ResourceComparatorTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. /**
  12. * @coversDefaultClass SebastianBergmann\Comparator\ResourceComparator
  13. *
  14. */
  15. class ResourceComparatorTest extends \PHPUnit_Framework_TestCase
  16. {
  17. private $comparator;
  18. protected function setUp()
  19. {
  20. $this->comparator = new ResourceComparator;
  21. }
  22. public function acceptsSucceedsProvider()
  23. {
  24. $tmpfile1 = tmpfile();
  25. $tmpfile2 = tmpfile();
  26. return array(
  27. array($tmpfile1, $tmpfile1),
  28. array($tmpfile2, $tmpfile2),
  29. array($tmpfile1, $tmpfile2)
  30. );
  31. }
  32. public function acceptsFailsProvider()
  33. {
  34. $tmpfile1 = tmpfile();
  35. return array(
  36. array($tmpfile1, null),
  37. array(null, $tmpfile1),
  38. array(null, null)
  39. );
  40. }
  41. public function assertEqualsSucceedsProvider()
  42. {
  43. $tmpfile1 = tmpfile();
  44. $tmpfile2 = tmpfile();
  45. return array(
  46. array($tmpfile1, $tmpfile1),
  47. array($tmpfile2, $tmpfile2)
  48. );
  49. }
  50. public function assertEqualsFailsProvider()
  51. {
  52. $tmpfile1 = tmpfile();
  53. $tmpfile2 = tmpfile();
  54. return array(
  55. array($tmpfile1, $tmpfile2),
  56. array($tmpfile2, $tmpfile1)
  57. );
  58. }
  59. /**
  60. * @covers ::accepts
  61. * @dataProvider acceptsSucceedsProvider
  62. */
  63. public function testAcceptsSucceeds($expected, $actual)
  64. {
  65. $this->assertTrue(
  66. $this->comparator->accepts($expected, $actual)
  67. );
  68. }
  69. /**
  70. * @covers ::accepts
  71. * @dataProvider acceptsFailsProvider
  72. */
  73. public function testAcceptsFails($expected, $actual)
  74. {
  75. $this->assertFalse(
  76. $this->comparator->accepts($expected, $actual)
  77. );
  78. }
  79. /**
  80. * @covers ::assertEquals
  81. * @dataProvider assertEqualsSucceedsProvider
  82. */
  83. public function testAssertEqualsSucceeds($expected, $actual)
  84. {
  85. $exception = null;
  86. try {
  87. $this->comparator->assertEquals($expected, $actual);
  88. }
  89. catch (ComparisonFailure $exception) {
  90. }
  91. $this->assertNull($exception, 'Unexpected ComparisonFailure');
  92. }
  93. /**
  94. * @covers ::assertEquals
  95. * @dataProvider assertEqualsFailsProvider
  96. */
  97. public function testAssertEqualsFails($expected, $actual)
  98. {
  99. $this->setExpectedException('SebastianBergmann\\Comparator\\ComparisonFailure');
  100. $this->comparator->assertEquals($expected, $actual);
  101. }
  102. }