No Description

NumericComparatorTest.php 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. * @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 NumericComparatorTest extends \PHPUnit_Framework_TestCase
  21. {
  22. private $comparator;
  23. protected function setUp()
  24. {
  25. $this->comparator = new NumericComparator;
  26. }
  27. public function acceptsSucceedsProvider()
  28. {
  29. return array(
  30. array(5, 10),
  31. array(8, '0'),
  32. array('10', 0),
  33. array(0x74c3b00c, 42),
  34. array(0755, 0777)
  35. );
  36. }
  37. public function acceptsFailsProvider()
  38. {
  39. return array(
  40. array('5', '10'),
  41. array(8, 5.0),
  42. array(5.0, 8),
  43. array(10, null),
  44. array(false, 12)
  45. );
  46. }
  47. public function assertEqualsSucceedsProvider()
  48. {
  49. return array(
  50. array(1337, 1337),
  51. array('1337', 1337),
  52. array(0x539, 1337),
  53. array(02471, 1337),
  54. array(1337, 1338, 1),
  55. array('1337', 1340, 5),
  56. );
  57. }
  58. public function assertEqualsFailsProvider()
  59. {
  60. return array(
  61. array(1337, 1338),
  62. array('1338', 1337),
  63. array(0x539, 1338),
  64. array(1337, 1339, 1),
  65. array('1337', 1340, 2),
  66. );
  67. }
  68. /**
  69. * @covers ::accepts
  70. * @dataProvider acceptsSucceedsProvider
  71. */
  72. public function testAcceptsSucceeds($expected, $actual)
  73. {
  74. $this->assertTrue(
  75. $this->comparator->accepts($expected, $actual)
  76. );
  77. }
  78. /**
  79. * @covers ::accepts
  80. * @dataProvider acceptsFailsProvider
  81. */
  82. public function testAcceptsFails($expected, $actual)
  83. {
  84. $this->assertFalse(
  85. $this->comparator->accepts($expected, $actual)
  86. );
  87. }
  88. /**
  89. * @covers ::assertEquals
  90. * @dataProvider assertEqualsSucceedsProvider
  91. */
  92. public function testAssertEqualsSucceeds($expected, $actual, $delta = 0.0)
  93. {
  94. $exception = null;
  95. try {
  96. $this->comparator->assertEquals($expected, $actual, $delta);
  97. }
  98. catch (ComparisonFailure $exception) {
  99. }
  100. $this->assertNull($exception, 'Unexpected ComparisonFailure');
  101. }
  102. /**
  103. * @covers ::assertEquals
  104. * @dataProvider assertEqualsFailsProvider
  105. */
  106. public function testAssertEqualsFails($expected, $actual, $delta = 0.0)
  107. {
  108. $this->setExpectedException(
  109. 'SebastianBergmann\\Comparator\\ComparisonFailure', 'matches expected'
  110. );
  111. $this->comparator->assertEquals($expected, $actual, $delta);
  112. }
  113. }