Complex classes like ReferenceListTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ReferenceListTest, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
25 | class ReferenceListTest extends PHPUnit_Framework_TestCase { |
||
26 | |||
27 | public function instanceProvider() { |
||
37 | |||
38 | public function testCanConstructWithReferenceListObject() { |
||
46 | |||
47 | public function testConstructorIgnoresIdenticalObjects() { |
||
48 | $reference = new Reference( array( new PropertyNoValueSnak( 1 ) ) ); |
||
49 | $list = new ReferenceList( array( $reference, $reference ) ); |
||
50 | $this->assertCount( 1, $list ); |
||
51 | } |
||
52 | |||
53 | public function testConstructorDoesNotIgnoreCopies() { |
||
54 | $reference = new Reference( array( new PropertyNoValueSnak( 1 ) ) ); |
||
55 | $list = new ReferenceList( array( $reference, clone $reference ) ); |
||
56 | $this->assertCount( 2, $list ); |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * @dataProvider invalidConstructorArgumentsProvider |
||
61 | * @expectedException InvalidArgumentException |
||
62 | */ |
||
63 | public function testGivenInvalidConstructorArguments_constructorThrowsException( $input ) { |
||
66 | |||
67 | public function invalidConstructorArgumentsProvider() { |
||
85 | |||
86 | public function testGetIterator_isTraversable() { |
||
97 | |||
98 | /** |
||
99 | * @dataProvider instanceProvider |
||
100 | */ |
||
101 | public function testHasReferenceBeforeRemoveButNotAfter( ReferenceList $array ) { |
||
116 | |||
117 | public function testGivenCloneOfReferenceInList_hasReferenceReturnsTrue() { |
||
130 | |||
131 | /** |
||
132 | * @dataProvider instanceProvider |
||
133 | */ |
||
134 | public function testRemoveReference( ReferenceList $array ) { |
||
149 | |||
150 | public function testRemoveReferenceRemovesIdenticalObjects() { |
||
158 | |||
159 | public function testRemoveReferenceDoesNotRemoveCopies() { |
||
169 | |||
170 | public function testAddReferenceOnEmptyList() { |
||
181 | |||
182 | private function assertSameReferenceOrder( ReferenceList $expectedList, ReferenceList $references ) { |
||
188 | |||
189 | public function testAddReferenceOnNonEmptyList() { |
||
202 | |||
203 | public function testAddReferenceIgnoresIdenticalObjects() { |
||
210 | |||
211 | public function testAddReferenceDoesNotIgnoreCopies() { |
||
212 | $list = new ReferenceList(); |
||
213 | $reference = new Reference( array( new PropertyNoValueSnak( 1 ) ) ); |
||
214 | $list->addReference( $reference ); |
||
215 | $list->addReference( clone $reference ); |
||
216 | $this->assertCount( 2, $list ); |
||
217 | } |
||
218 | |||
219 | public function testAddReferenceAtIndexIgnoresIdenticalObjects() { |
||
226 | |||
227 | public function testAddReferenceAtIndexZero() { |
||
238 | |||
239 | public function testAddReferenceAtNegativeIndex() { |
||
246 | |||
247 | public function testGivenEmptyReference_addReferenceDoesNotAdd() { |
||
258 | |||
259 | public function testGivenEmptyReferenceAndIndex_addReferenceDoesNotAdd() { |
||
270 | |||
271 | /** |
||
272 | * @dataProvider instanceProvider |
||
273 | */ |
||
274 | public function testIndexOf( ReferenceList $array ) { |
||
282 | |||
283 | public function testIndexOf_checksForIdentity() { |
||
293 | |||
294 | /** |
||
295 | * @dataProvider instanceProvider |
||
296 | */ |
||
297 | public function testEquals( ReferenceList $array ) { |
||
301 | |||
302 | /** |
||
303 | * @dataProvider instanceProvider |
||
304 | */ |
||
305 | public function testGetValueHashReturnsString( ReferenceList $array ) { |
||
308 | |||
309 | /** |
||
310 | * @dataProvider instanceProvider |
||
311 | */ |
||
312 | public function testGetValueHashIsTheSameForClone( ReferenceList $array ) { |
||
316 | |||
317 | /** |
||
318 | * @dataProvider instanceProvider |
||
319 | */ |
||
320 | public function testHasReferenceHash( ReferenceList $references ) { |
||
330 | |||
331 | /** |
||
332 | * @dataProvider instanceProvider |
||
333 | */ |
||
334 | public function testGetReference( ReferenceList $references ) { |
||
344 | |||
345 | /** |
||
346 | * @dataProvider instanceProvider |
||
347 | */ |
||
348 | public function testRemoveReferenceHash( ReferenceList $references ) { |
||
366 | |||
367 | public function testRemoveReferenceHashRemovesIdenticalObjects() { |
||
375 | |||
376 | public function testRemoveReferenceHashDoesNotRemoveCopies() { |
||
386 | |||
387 | public function testRemoveReferenceHashUpdatesIndexes() { |
||
396 | |||
397 | public function testGivenOneSnak_addNewReferenceAddsSnak() { |
||
398 | $references = new ReferenceList(); |
||
399 | $snak = new PropertyNoValueSnak( 1 ); |
||
400 | |||
401 | $references->addNewReference( $snak ); |
||
402 | $this->assertTrue( $references->hasReference( new Reference( array( $snak ) ) ) ); |
||
403 | } |
||
404 | |||
405 | public function testGivenMultipleSnaks_addNewReferenceAddsThem() { |
||
406 | $references = new ReferenceList(); |
||
407 | $snak1 = new PropertyNoValueSnak( 1 ); |
||
408 | $snak2 = new PropertyNoValueSnak( 3 ); |
||
409 | $snak3 = new PropertyNoValueSnak( 2 ); |
||
410 | |||
411 | $references->addNewReference( $snak1, $snak2, $snak3 ); |
||
412 | |||
413 | $expectedSnaks = array( $snak1, $snak2, $snak3 ); |
||
414 | $this->assertTrue( $references->hasReference( new Reference( $expectedSnaks ) ) ); |
||
415 | } |
||
416 | |||
417 | public function testGivenAnArrayOfSnaks_addNewReferenceAddsThem() { |
||
418 | $references = new ReferenceList(); |
||
419 | $snaks = array( |
||
420 | new PropertyNoValueSnak( 1 ), |
||
421 | new PropertyNoValueSnak( 3 ), |
||
422 | new PropertyNoValueSnak( 2 ) |
||
423 | ); |
||
424 | |||
425 | $references->addNewReference( $snaks ); |
||
426 | $this->assertTrue( $references->hasReference( new Reference( $snaks ) ) ); |
||
427 | } |
||
428 | |||
429 | public function testAddNewReferenceDoesNotIgnoreIdenticalObjects() { |
||
430 | $list = new ReferenceList(); |
||
431 | $snak = new PropertyNoValueSnak( 1 ); |
||
432 | $list->addNewReference( $snak ); |
||
433 | $list->addNewReference( $snak ); |
||
434 | $this->assertCount( 2, $list ); |
||
435 | } |
||
436 | |||
437 | public function testAddNewReferenceDoesNotIgnoreCopies() { |
||
438 | $list = new ReferenceList(); |
||
439 | $snak = new PropertyNoValueSnak( 1 ); |
||
440 | $list->addNewReference( $snak ); |
||
441 | $list->addNewReference( clone $snak ); |
||
442 | $this->assertCount( 2, $list ); |
||
443 | } |
||
444 | |||
445 | public function testGivenNoneSnak_addNewReferenceThrowsException() { |
||
451 | |||
452 | public function testEmptySerializationStability() { |
||
453 | $list = new ReferenceList(); |
||
454 | $this->assertSame( 'a:0:{}', $list->serialize() ); |
||
455 | } |
||
456 | |||
457 | public function testSerializationStability() { |
||
458 | $list = new ReferenceList(); |
||
459 | $list->addNewReference( new PropertyNoValueSnak( 1 ) ); |
||
460 | $this->assertSame( |
||
461 | "a:1:{i:0;O:28:\"Wikibase\\DataModel\\Reference\":1:{s:35:\"\x00Wikibase\\DataModel\\" |
||
462 | . "Reference\x00snaks\";C:32:\"Wikibase\\DataModel\\Snak\\SnakList\":102:{a:2:{s:4:\"" |
||
463 | . 'data";a:1:{i:0;C:43:"Wikibase\\DataModel\\Snak\\PropertyNoValueSnak":4:{i:1;}}s:5' |
||
464 | . ':"index";i:0;}}}}', |
||
465 | $list->serialize() |
||
466 | ); |
||
467 | } |
||
468 | |||
469 | public function testSerializeUnserializeRoundtrip() { |
||
470 | $original = new ReferenceList(); |
||
471 | $original->addNewReference( new PropertyNoValueSnak( 1 ) ); |
||
472 | |||
473 | /** @var ReferenceList $clone */ |
||
474 | $clone = unserialize( serialize( $original ) ); |
||
475 | |||
476 | $this->assertTrue( $original->equals( $clone ) ); |
||
477 | $this->assertSame( $original->getValueHash(), $clone->getValueHash() ); |
||
478 | $this->assertSame( $original->serialize(), $clone->serialize() ); |
||
479 | } |
||
480 | |||
481 | public function testUnserializeCreatesNonIdenticalClones() { |
||
482 | $original = new ReferenceList(); |
||
483 | $reference = new Reference( array( new PropertyNoValueSnak( 1 ) ) ); |
||
484 | $original->addReference( $reference ); |
||
485 | |||
486 | /** @var ReferenceList $clone */ |
||
487 | $clone = unserialize( serialize( $original ) ); |
||
488 | $clone->addReference( $reference ); |
||
489 | |||
490 | $this->assertCount( 2, $clone ); |
||
491 | } |
||
492 | |||
493 | public function testGivenEmptyList_isEmpty() { |
||
497 | |||
498 | public function testGivenNonEmptyList_isNotEmpty() { |
||
504 | |||
505 | } |
||
506 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.