1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* phpDocumentor |
4
|
|
|
* |
5
|
|
|
* PHP Version 5.3 |
6
|
|
|
* |
7
|
|
|
* @author Mike van Riel <[email protected]> |
8
|
|
|
* @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com) |
9
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
10
|
|
|
* @link http://phpdoc.org |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace phpDocumentor\Transformer\Writer; |
14
|
|
|
|
15
|
|
|
use Mockery as m; |
16
|
|
|
use Mockery\Adapter\Phpunit\MockeryTestCase; |
17
|
|
|
use Mockery\MockInterface; |
18
|
|
|
use phpDocumentor\Transformer\Router\Queue; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Test class for phpDocumentor\Transformer\Writer\Collection |
22
|
|
|
*/ |
23
|
|
|
class CollectionTest extends MockeryTestCase |
24
|
|
|
{ |
25
|
|
|
/** @var MockInterface|Queue */ |
26
|
|
|
protected $routers; |
27
|
|
|
|
28
|
|
|
/** @var MockInterface|WriterAbstract */ |
29
|
|
|
protected $writer; |
30
|
|
|
|
31
|
|
|
/** @var Collection */ |
32
|
|
|
protected $fixture; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Initializes the fixture and dependencies for this testcase. |
36
|
|
|
*/ |
37
|
|
|
protected function setUp() |
38
|
|
|
{ |
39
|
|
|
$this->routers = m::mock(Queue::class); |
40
|
|
|
$this->writer = m::mock(WriterAbstract::class); |
41
|
|
|
$this->fixture = new Collection($this->routers); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @covers phpDocumentor\Transformer\Writer\Collection::__construct |
46
|
|
|
*/ |
47
|
|
|
public function testIfDependenciesAreCorrectlyRegisteredOnInitialization() |
48
|
|
|
{ |
49
|
|
|
$this->assertAttributeSame($this->routers, 'routers', $this->fixture); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @expectedException \InvalidArgumentException |
54
|
|
|
* @covers phpDocumentor\Transformer\Writer\Collection::offsetSet |
55
|
|
|
*/ |
56
|
|
|
public function testOffsetSetWithWriterNotDescendingFromWriterAbstract() |
57
|
|
|
{ |
58
|
|
|
$this->fixture->offsetSet('index', new \stdClass()); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @expectedException \InvalidArgumentException |
63
|
|
|
* @covers phpDocumentor\Transformer\Writer\Collection::offsetSet |
64
|
|
|
*/ |
65
|
|
|
public function testOffsetSetWithInvalidIndexName() |
66
|
|
|
{ |
67
|
|
|
$this->fixture->offsetSet('i', $this->writer); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @expectedException \InvalidArgumentException |
72
|
|
|
* @covers phpDocumentor\Transformer\Writer\Collection::offsetGet |
73
|
|
|
*/ |
74
|
|
|
public function testOffsetGetWithNonExistingIndex() |
75
|
|
|
{ |
76
|
|
|
$this->fixture->offsetGet('nonExistingIndex'); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @covers phpDocumentor\Transformer\Writer\Collection::offsetGet |
81
|
|
|
*/ |
82
|
|
|
public function testOffsetGetWithExistingIndex() |
83
|
|
|
{ |
84
|
|
|
$this->registerWriter(); |
85
|
|
|
|
86
|
|
|
$this->assertSame($this->writer, $this->fixture->offsetGet('index')); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @covers phpDocumentor\Transformer\Writer\Collection::checkRequirements |
91
|
|
|
*/ |
92
|
|
|
public function testCheckRequirements() |
93
|
|
|
{ |
94
|
|
|
$this->registerWriter(); |
95
|
|
|
|
96
|
|
|
$this->writer->shouldReceive('checkRequirements')->once(); |
97
|
|
|
$this->fixture->checkRequirements(); |
98
|
|
|
|
99
|
|
|
$this->assertTrue(true); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Registers a writer for tests that need a collection item |
104
|
|
|
*/ |
105
|
|
|
private function registerWriter() |
106
|
|
|
{ |
107
|
|
|
$this->fixture->offsetSet('index', $this->writer); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: