No Description

ResourceComparatorTest.php 3.0KB

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