1 | <?php |
||
16 | class HooksTest extends \PHPUnit_Framework_TestCase { |
||
17 | |||
18 | public function testCanConstruct() { |
||
27 | |||
28 | public function testRegister() { |
||
45 | |||
46 | public function callOnApprovedRevsRevisionApproved( $instance ) { |
||
77 | |||
78 | public function callOnApprovedRevsFileRevisionApproved( $instance ) { |
||
109 | |||
110 | public function callOnSMWRevisionGuardIsApprovedRevision( $instance ) { |
||
111 | |||
112 | $handler = 'SMW::RevisionGuard::IsApprovedRevision'; |
||
113 | |||
114 | $title = $this->getMockBuilder( '\Title' ) |
||
115 | ->disableOriginalConstructor() |
||
116 | ->getMock(); |
||
117 | |||
118 | $this->assertTrue( |
||
119 | $instance->isRegistered( $handler ) |
||
120 | ); |
||
121 | |||
122 | $rev = 0; |
||
123 | |||
124 | $this->assertThatHookIsExcutable( |
||
125 | $instance->getHandlers( $handler ), |
||
126 | [ $title, $rev ] |
||
127 | ); |
||
128 | } |
||
129 | |||
130 | public function callOnSMWRevisionGuardChangeRevision( $instance ) { |
||
131 | |||
132 | $handler = 'SMW::RevisionGuard::ChangeRevision'; |
||
133 | |||
134 | $title = $this->getMockBuilder( '\Title' ) |
||
135 | ->disableOriginalConstructor() |
||
136 | ->getMock(); |
||
137 | |||
138 | $this->assertTrue( |
||
139 | $instance->isRegistered( $handler ) |
||
140 | ); |
||
141 | |||
142 | $revision = null; |
||
143 | |||
144 | $this->assertThatHookIsExcutable( |
||
145 | $instance->getHandlers( $handler ), |
||
146 | [ $title, &$revision ] |
||
147 | ); |
||
148 | } |
||
149 | |||
150 | public function callOnSMWRevisionGuardChangeRevisionID( $instance ) { |
||
151 | |||
152 | $handler = 'SMW::RevisionGuard::ChangeRevisionID'; |
||
153 | |||
154 | $title = $this->getMockBuilder( '\Title' ) |
||
155 | ->disableOriginalConstructor() |
||
156 | ->getMock(); |
||
157 | |||
158 | $this->assertTrue( |
||
159 | $instance->isRegistered( $handler ) |
||
160 | ); |
||
161 | |||
162 | $latestRevID = 0; |
||
163 | |||
164 | $this->assertThatHookIsExcutable( |
||
165 | $instance->getHandlers( $handler ), |
||
166 | [ $title, &$latestRevID ] |
||
167 | ); |
||
168 | } |
||
169 | |||
170 | public function callOnSMWInitProperties( $instance ) { |
||
171 | |||
172 | $handler = 'SMW::Property::initProperties'; |
||
173 | |||
174 | $propertyRegistry = $this->getMockBuilder( '\SMW\PropertyRegistry' ) |
||
175 | ->disableOriginalConstructor() |
||
176 | ->getMock(); |
||
177 | |||
178 | $this->assertTrue( |
||
179 | $instance->isRegistered( $handler ) |
||
180 | ); |
||
181 | |||
182 | $this->assertThatHookIsExcutable( |
||
183 | $instance->getHandlers( $handler ), |
||
184 | [ $propertyRegistry ] |
||
185 | ); |
||
186 | } |
||
187 | |||
188 | public function callOnSMWStoreUpdateDataBefore( $instance ) { |
||
189 | |||
190 | $handler = 'SMWStore::updateDataBefore'; |
||
191 | |||
192 | $store = $this->getMockBuilder( '\SMW\Store' ) |
||
193 | ->disableOriginalConstructor() |
||
194 | ->getMockForAbstractClass(); |
||
195 | |||
196 | $semanticData = $this->getMockBuilder( '\SMW\SemanticData' ) |
||
197 | ->disableOriginalConstructor() |
||
198 | ->getMock(); |
||
199 | |||
200 | $this->assertTrue( |
||
201 | $instance->isRegistered( $handler ) |
||
202 | ); |
||
203 | |||
204 | $this->assertThatHookIsExcutable( |
||
205 | $instance->getHandlers( $handler ), |
||
206 | [ $store, $semanticData ] |
||
207 | ); |
||
208 | } |
||
209 | |||
210 | public function callOnSMWConfigBeforeCompletion( $instance ) { |
||
211 | |||
212 | $handler = 'SMW::Config::BeforeCompletion'; |
||
213 | |||
214 | $this->assertTrue( |
||
215 | $instance->isRegistered( $handler ) |
||
216 | ); |
||
217 | |||
218 | $config = [ |
||
219 | 'smwgImportFileDirs' => [] |
||
220 | ]; |
||
221 | |||
222 | $this->assertThatHookIsExcutable( |
||
223 | $instance->getHandlers( $handler ), |
||
224 | [ &$config ] |
||
225 | ); |
||
226 | |||
227 | $this->assertArrayHasKey( |
||
228 | 'sar', |
||
229 | $config['smwgImportFileDirs'] |
||
230 | ); |
||
231 | } |
||
232 | |||
233 | public function callOnSMWRevisionGuardChangeFile( $instance ) { |
||
234 | |||
235 | $handler = 'SMW::RevisionGuard::ChangeFile'; |
||
236 | |||
237 | $this->assertTrue( |
||
238 | $instance->isRegistered( $handler ) |
||
239 | ); |
||
240 | |||
241 | $title = $this->getMockBuilder( '\Title' ) |
||
242 | ->disableOriginalConstructor() |
||
243 | ->getMock(); |
||
244 | |||
245 | $file = null; |
||
246 | |||
247 | $this->assertThatHookIsExcutable( |
||
248 | $instance->getHandlers( $handler ), |
||
249 | [ $title, &$file ] |
||
250 | ); |
||
251 | } |
||
252 | |||
253 | private function assertThatHookIsExcutable( $hooks, $arguments ) { |
||
267 | |||
268 | } |
||
269 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.