ResourceComparatorTest.php 2.8 KB

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