ResourceComparatorTest.php 2.8 KB

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