NumericComparatorTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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\NumericComparator
  13. *
  14. */
  15. class NumericComparatorTest extends \PHPUnit_Framework_TestCase
  16. {
  17. private $comparator;
  18. protected function setUp()
  19. {
  20. $this->comparator = new NumericComparator;
  21. }
  22. public function acceptsSucceedsProvider()
  23. {
  24. return array(
  25. array(5, 10),
  26. array(8, '0'),
  27. array('10', 0),
  28. array(0x74c3b00c, 42),
  29. array(0755, 0777)
  30. );
  31. }
  32. public function acceptsFailsProvider()
  33. {
  34. return array(
  35. array('5', '10'),
  36. array(8, 5.0),
  37. array(5.0, 8),
  38. array(10, null),
  39. array(false, 12)
  40. );
  41. }
  42. public function assertEqualsSucceedsProvider()
  43. {
  44. return array(
  45. array(1337, 1337),
  46. array('1337', 1337),
  47. array(0x539, 1337),
  48. array(02471, 1337),
  49. array(1337, 1338, 1),
  50. array('1337', 1340, 5),
  51. );
  52. }
  53. public function assertEqualsFailsProvider()
  54. {
  55. return array(
  56. array(1337, 1338),
  57. array('1338', 1337),
  58. array(0x539, 1338),
  59. array(1337, 1339, 1),
  60. array('1337', 1340, 2),
  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, $delta = 0.0)
  88. {
  89. $exception = null;
  90. try {
  91. $this->comparator->assertEquals($expected, $actual, $delta);
  92. }
  93. catch (ComparisonFailure $exception) {
  94. }
  95. $this->assertNull($exception, 'Unexpected ComparisonFailure');
  96. }
  97. /**
  98. * @covers ::assertEquals
  99. * @dataProvider assertEqualsFailsProvider
  100. */
  101. public function testAssertEqualsFails($expected, $actual, $delta = 0.0)
  102. {
  103. $this->setExpectedException(
  104. 'SebastianBergmann\\Comparator\\ComparisonFailure', 'matches expected'
  105. );
  106. $this->comparator->assertEquals($expected, $actual, $delta);
  107. }
  108. }