Skip to content

Commit f5df97c

Browse files
committed
Fixes #1023
[BC BREAK] The numeric comparator is no longer invoked when provided with two strings.
1 parent 1c26eb5 commit f5df97c

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

PHPUnit/Framework/Comparator/Numeric.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ class PHPUnit_Framework_Comparator_Numeric extends PHPUnit_Framework_Comparator_
6767
public function accepts($expected, $actual)
6868
{
6969
// all numerical values, but not if one of them is a double
70-
return is_numeric($expected) && is_numeric($actual) && !(is_double($expected) || is_double($actual));
70+
// or both of them are strings
71+
return is_numeric($expected) && is_numeric($actual) &&
72+
!(is_double($expected) || is_double($actual)) &&
73+
!(is_string($expected) && is_string($actual));
7174
}
7275

7376
/**

Tests/Framework/AssertTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,8 @@ protected function notEqualValues()
651651
// strings
652652
array('a', 'b'),
653653
array('a', 'A'),
654+
// https://github.com/sebastianbergmann/phpunit/issues/1023
655+
array('9E6666666','9E7777777'),
654656
// integers
655657
array(1, 2),
656658
array(2, 1),

Tests/Framework/ComparatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function instanceProvider()
7373
array(TRUE, FALSE, 'PHPUnit_Framework_Comparator_Scalar'),
7474
array(FALSE, TRUE, 'PHPUnit_Framework_Comparator_Scalar'),
7575
array('', '', 'PHPUnit_Framework_Comparator_Scalar'),
76-
array('0', '0', 'PHPUnit_Framework_Comparator_Numeric'),
76+
array('0', '0', 'PHPUnit_Framework_Comparator_Scalar'),
7777
array('0', 0, 'PHPUnit_Framework_Comparator_Numeric'),
7878
array(0, '0', 'PHPUnit_Framework_Comparator_Numeric'),
7979
array(0, 0, 'PHPUnit_Framework_Comparator_Numeric'),

0 commit comments

Comments
 (0)