These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * phpDocumentor |
||
4 | * |
||
5 | * PHP Version 5.3 |
||
6 | * |
||
7 | * @author Mike van Riel <[email protected]> |
||
8 | * @copyright 2010-2012 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; |
||
14 | |||
15 | use Mockery as m; |
||
16 | use phpDocumentor\Transformer\Template\Parameter; |
||
17 | |||
18 | /** |
||
19 | * Test class for phpDocumentor\Transformer\Transformation |
||
20 | */ |
||
21 | class TransformationTest extends \PHPUnit_Framework_TestCase |
||
22 | { |
||
23 | /** @var Transformation $fixture */ |
||
24 | protected $fixture; |
||
25 | |||
26 | /** @var string */ |
||
27 | protected $query = 'queryString'; |
||
28 | |||
29 | /** @var string */ |
||
30 | protected $writer = 'writerString'; |
||
31 | |||
32 | /** @var string */ |
||
33 | protected $source = 'sourceString'; |
||
34 | |||
35 | /** @var string */ |
||
36 | protected $artifact = 'artifactString'; |
||
37 | |||
38 | /** |
||
39 | * Initializes the fixture and dependencies for this testcase. |
||
40 | */ |
||
41 | public function setUp() |
||
42 | { |
||
43 | $this->fixture = new Transformation($this->query, $this->writer, $this->source, $this->artifact); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @covers phpDocumentor\Transformer\Transformation::__construct |
||
48 | * @covers phpDocumentor\Transformer\Transformation::setQuery |
||
49 | * @covers phpDocumentor\Transformer\Transformation::setWriter |
||
50 | * @covers phpDocumentor\Transformer\Transformation::setSource |
||
51 | * @covers phpDocumentor\Transformer\Transformation::setArtifact |
||
52 | */ |
||
53 | public function testIfDependenciesAreCorrectlyRegisteredOnInitialization() |
||
54 | { |
||
55 | $this->assertAttributeSame($this->query, 'query', $this->fixture); |
||
56 | $this->assertAttributeSame($this->writer, 'writer', $this->fixture); |
||
57 | $this->assertAttributeSame($this->source, 'source', $this->fixture); |
||
58 | $this->assertAttributeSame($this->artifact, 'artifact', $this->fixture); |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * @covers phpDocumentor\Transformer\Transformation::getQuery |
||
63 | */ |
||
64 | public function testGetQuery() |
||
65 | { |
||
66 | $this->assertSame($this->query, $this->fixture->getQuery()); |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * @covers phpDocumentor\Transformer\Transformation::getWriter |
||
71 | */ |
||
72 | public function testGetWriter() |
||
73 | { |
||
74 | $this->assertSame($this->writer, $this->fixture->getWriter()); |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * @covers phpDocumentor\Transformer\Transformation::getSource |
||
79 | */ |
||
80 | public function testGetSource() |
||
81 | { |
||
82 | $this->assertSame($this->source, $this->fixture->getSource()); |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * @covers phpDocumentor\Transformer\Transformation::getArtifact |
||
87 | */ |
||
88 | public function testGetArtifact() |
||
89 | { |
||
90 | $this->assertSame($this->artifact, $this->fixture->getArtifact()); |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * @covers phpDocumentor\Transformer\Transformation::getParameters |
||
95 | * @covers phpDocumentor\Transformer\Transformation::setParameters |
||
96 | */ |
||
97 | public function testSetAndGetParameters() |
||
98 | { |
||
99 | $this->assertSame(array(), $this->fixture->getParameters()); |
||
100 | |||
101 | $parameters = $this->givenAParameter(); |
||
102 | |||
103 | $this->assertSame($parameters, $this->fixture->getParameters()); |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * @covers phpDocumentor\Transformer\Transformation::getParameter |
||
108 | */ |
||
109 | public function testGetParameterWithExistingName() |
||
110 | { |
||
111 | $parameters = $this->givenAParameter(); |
||
112 | $this->assertSame($parameters["firstKey"], $this->fixture->getParameter('name')); |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * @covers phpDocumentor\Transformer\Transformation::getParameter |
||
117 | */ |
||
118 | public function testGetParameterWithNonExistingName() |
||
119 | { |
||
120 | $this->assertSame(null, $this->fixture->getParameter('somethingElse')); |
||
121 | } |
||
122 | |||
123 | /** |
||
124 | * @covers phpDocumentor\Transformer\Transformation::getParametersWithKey |
||
125 | */ |
||
126 | public function testGetParametersWithKeyWithExistingName() |
||
127 | { |
||
128 | $parameters = $this->givenAParameter(); |
||
129 | $this->assertSame(array($parameters["firstKey"]), $this->fixture->getParametersWithKey('name')); |
||
130 | } |
||
131 | |||
132 | /** |
||
133 | * @covers phpDocumentor\Transformer\Transformation::getParametersWithKey |
||
134 | */ |
||
135 | public function testGetParametersWithKeyWithNonExistingName() |
||
136 | { |
||
137 | $this->assertSame(array(), $this->fixture->getParametersWithKey('somethingElse')); |
||
138 | } |
||
139 | |||
140 | /** |
||
141 | * @covers phpDocumentor\Transformer\Transformation::getTransformer |
||
142 | * @covers phpDocumentor\Transformer\Transformation::setTransformer |
||
143 | */ |
||
144 | public function testSetAndGetTransformer() |
||
145 | { |
||
146 | $transformer = m::mock('phpDocumentor\Transformer\Transformer'); |
||
147 | |||
148 | $this->assertSame(null, $this->fixture->getTransformer()); |
||
149 | |||
150 | $this->fixture->setTransformer($transformer); |
||
151 | |||
152 | $this->assertSame($transformer, $this->fixture->getTransformer()); |
||
153 | } |
||
154 | |||
155 | /** |
||
156 | * Sets a parameter in the fixture for tests that need to get parameters and |
||
157 | * returns the parameter array used to set this parameter for comparison |
||
158 | */ |
||
159 | private function givenAParameter() |
||
160 | { |
||
161 | $parameterMock = m::mock('phpDocumentor\Transformer\Template\Parameter'); |
||
162 | $parameterMock->shouldReceive('getKey')->andReturn('name'); |
||
163 | $parameters = array("firstKey" => $parameterMock); |
||
164 | $this->fixture->setParameters($parameters); |
||
0 ignored issues
–
show
|
|||
165 | |||
166 | return $parameters; |
||
167 | } |
||
168 | } |
||
169 |
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: