SplObjectStorageComparatorTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. /*
  3. * This file is part of the Comparator package.
  4. *
  5. * (c) Sebastian Bergmann <sebastian@phpunit.de>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace SebastianBergmann\Comparator;
  11. use SplObjectStorage;
  12. use stdClass;
  13. /**
  14. * @coversDefaultClass SebastianBergmann\Comparator\SplObjectStorageComparator
  15. *
  16. */
  17. class SplObjectStorageComparatorTest extends \PHPUnit_Framework_TestCase
  18. {
  19. private $comparator;
  20. protected function setUp()
  21. {
  22. $this->comparator = new SplObjectStorageComparator;
  23. }
  24. public function acceptsFailsProvider()
  25. {
  26. return array(
  27. array(new SplObjectStorage, new stdClass),
  28. array(new stdClass, new SplObjectStorage),
  29. array(new stdClass, new stdClass)
  30. );
  31. }
  32. public function assertEqualsSucceedsProvider()
  33. {
  34. $object1 = new stdClass();
  35. $object2 = new stdClass();
  36. $storage1 = new SplObjectStorage();
  37. $storage2 = new SplObjectStorage();
  38. $storage3 = new SplObjectStorage();
  39. $storage3->attach($object1);
  40. $storage3->attach($object2);
  41. $storage4 = new SplObjectStorage();
  42. $storage4->attach($object2);
  43. $storage4->attach($object1);
  44. return array(
  45. array($storage1, $storage1),
  46. array($storage1, $storage2),
  47. array($storage3, $storage3),
  48. array($storage3, $storage4)
  49. );
  50. }
  51. public function assertEqualsFailsProvider()
  52. {
  53. $object1 = new stdClass;
  54. $object2 = new stdClass;
  55. $storage1 = new SplObjectStorage;
  56. $storage2 = new SplObjectStorage;
  57. $storage2->attach($object1);
  58. $storage3 = new SplObjectStorage;
  59. $storage3->attach($object2);
  60. $storage3->attach($object1);
  61. return array(
  62. array($storage1, $storage2),
  63. array($storage1, $storage3),
  64. array($storage2, $storage3),
  65. );
  66. }
  67. /**
  68. * @covers ::accepts
  69. */
  70. public function testAcceptsSucceeds()
  71. {
  72. $this->assertTrue(
  73. $this->comparator->accepts(
  74. new SplObjectStorage,
  75. new SplObjectStorage
  76. )
  77. );
  78. }
  79. /**
  80. * @covers ::accepts
  81. * @dataProvider acceptsFailsProvider
  82. */
  83. public function testAcceptsFails($expected, $actual)
  84. {
  85. $this->assertFalse(
  86. $this->comparator->accepts($expected, $actual)
  87. );
  88. }
  89. /**
  90. * @covers ::assertEquals
  91. * @dataProvider assertEqualsSucceedsProvider
  92. */
  93. public function testAssertEqualsSucceeds($expected, $actual)
  94. {
  95. $exception = null;
  96. try {
  97. $this->comparator->assertEquals($expected, $actual);
  98. }
  99. catch (ComparisonFailure $exception) {
  100. }
  101. $this->assertNull($exception, 'Unexpected ComparisonFailure');
  102. }
  103. /**
  104. * @covers ::assertEquals
  105. * @dataProvider assertEqualsFailsProvider
  106. */
  107. public function testAssertEqualsFails($expected, $actual)
  108. {
  109. $this->setExpectedException(
  110. 'SebastianBergmann\\Comparator\\ComparisonFailure',
  111. 'Failed asserting that two objects are equal.'
  112. );
  113. $this->comparator->assertEquals($expected, $actual);
  114. }
  115. }