Ei kuvausta

ResourceComparatorTest.php 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. * @covers \SebastianBergmann\Comparator\ResourceComparator<extended>
  14. *
  15. * @uses \SebastianBergmann\Comparator\Comparator
  16. * @uses \SebastianBergmann\Comparator\Factory
  17. * @uses \SebastianBergmann\Comparator\ComparisonFailure
  18. */
  19. final class ResourceComparatorTest extends TestCase
  20. {
  21. /**
  22. * @var ResourceComparator
  23. */
  24. private $comparator;
  25. protected function setUp(): void
  26. {
  27. $this->comparator = new ResourceComparator;
  28. }
  29. public function acceptsSucceedsProvider()
  30. {
  31. $tmpfile1 = \tmpfile();
  32. $tmpfile2 = \tmpfile();
  33. return [
  34. [$tmpfile1, $tmpfile1],
  35. [$tmpfile2, $tmpfile2],
  36. [$tmpfile1, $tmpfile2]
  37. ];
  38. }
  39. public function acceptsFailsProvider()
  40. {
  41. $tmpfile1 = \tmpfile();
  42. return [
  43. [$tmpfile1, null],
  44. [null, $tmpfile1],
  45. [null, null]
  46. ];
  47. }
  48. public function assertEqualsSucceedsProvider()
  49. {
  50. $tmpfile1 = \tmpfile();
  51. $tmpfile2 = \tmpfile();
  52. return [
  53. [$tmpfile1, $tmpfile1],
  54. [$tmpfile2, $tmpfile2]
  55. ];
  56. }
  57. public function assertEqualsFailsProvider()
  58. {
  59. $tmpfile1 = \tmpfile();
  60. $tmpfile2 = \tmpfile();
  61. return [
  62. [$tmpfile1, $tmpfile2],
  63. [$tmpfile2, $tmpfile1]
  64. ];
  65. }
  66. /**
  67. * @dataProvider acceptsSucceedsProvider
  68. */
  69. public function testAcceptsSucceeds($expected, $actual): void
  70. {
  71. $this->assertTrue(
  72. $this->comparator->accepts($expected, $actual)
  73. );
  74. }
  75. /**
  76. * @dataProvider acceptsFailsProvider
  77. */
  78. public function testAcceptsFails($expected, $actual): void
  79. {
  80. $this->assertFalse(
  81. $this->comparator->accepts($expected, $actual)
  82. );
  83. }
  84. /**
  85. * @dataProvider assertEqualsSucceedsProvider
  86. */
  87. public function testAssertEqualsSucceeds($expected, $actual): void
  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. * @dataProvider assertEqualsFailsProvider
  98. */
  99. public function testAssertEqualsFails($expected, $actual): void
  100. {
  101. $this->expectException(ComparisonFailure::class);
  102. $this->comparator->assertEquals($expected, $actual);
  103. }
  104. }