No Description

SplObjectStorageComparatorTest.php 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. * @package Comparator
  17. * @author Jeff Welch <whatthejeff@gmail.com>
  18. * @copyright Sebastian Bergmann <sebastian@phpunit.de>
  19. * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
  20. * @link http://www.github.com/sebastianbergmann/comparator
  21. */
  22. class SplObjectStorageComparatorTest extends \PHPUnit_Framework_TestCase
  23. {
  24. private $comparator;
  25. protected function setUp()
  26. {
  27. $this->comparator = new SplObjectStorageComparator;
  28. }
  29. public function acceptsFailsProvider()
  30. {
  31. return array(
  32. array(new SplObjectStorage, new stdClass),
  33. array(new stdClass, new SplObjectStorage),
  34. array(new stdClass, new stdClass)
  35. );
  36. }
  37. public function assertEqualsSucceedsProvider()
  38. {
  39. $object1 = new stdClass();
  40. $object2 = new stdClass();
  41. $storage1 = new SplObjectStorage();
  42. $storage2 = new SplObjectStorage();
  43. $storage3 = new SplObjectStorage();
  44. $storage3->attach($object1);
  45. $storage3->attach($object2);
  46. $storage4 = new SplObjectStorage();
  47. $storage4->attach($object2);
  48. $storage4->attach($object1);
  49. return array(
  50. array($storage1, $storage1),
  51. array($storage1, $storage2),
  52. array($storage3, $storage3),
  53. array($storage3, $storage4)
  54. );
  55. }
  56. public function assertEqualsFailsProvider()
  57. {
  58. $object1 = new stdClass;
  59. $object2 = new stdClass;
  60. $storage1 = new SplObjectStorage;
  61. $storage2 = new SplObjectStorage;
  62. $storage2->attach($object1);
  63. $storage3 = new SplObjectStorage;
  64. $storage3->attach($object2);
  65. $storage3->attach($object1);
  66. return array(
  67. array($storage1, $storage2),
  68. array($storage1, $storage3),
  69. array($storage2, $storage3),
  70. );
  71. }
  72. /**
  73. * @covers ::accepts
  74. */
  75. public function testAcceptsSucceeds()
  76. {
  77. $this->assertTrue(
  78. $this->comparator->accepts(
  79. new SplObjectStorage,
  80. new SplObjectStorage
  81. )
  82. );
  83. }
  84. /**
  85. * @covers ::accepts
  86. * @dataProvider acceptsFailsProvider
  87. */
  88. public function testAcceptsFails($expected, $actual)
  89. {
  90. $this->assertFalse(
  91. $this->comparator->accepts($expected, $actual)
  92. );
  93. }
  94. /**
  95. * @covers ::assertEquals
  96. * @dataProvider assertEqualsSucceedsProvider
  97. */
  98. public function testAssertEqualsSucceeds($expected, $actual)
  99. {
  100. $exception = null;
  101. try {
  102. $this->comparator->assertEquals($expected, $actual);
  103. }
  104. catch (ComparisonFailure $exception) {
  105. }
  106. $this->assertNull($exception, 'Unexpected ComparisonFailure');
  107. }
  108. /**
  109. * @covers ::assertEquals
  110. * @dataProvider assertEqualsFailsProvider
  111. */
  112. public function testAssertEqualsFails($expected, $actual)
  113. {
  114. $this->setExpectedException(
  115. 'SebastianBergmann\\Comparator\\ComparisonFailure',
  116. 'Failed asserting that two objects are equal.'
  117. );
  118. $this->comparator->assertEquals($expected, $actual);
  119. }
  120. }