3
* This file is part of the Comparator package.
5
* (c) Sebastian Bergmann <sebastian@phpunit.de>
7
* For the full copyright and license information, please view the LICENSE
8
* file that was distributed with this source code.
11
namespace SebastianBergmann\Comparator;
14
* @coversDefaultClass SebastianBergmann\Comparator\ScalarComparator
17
* @author Jeff Welch <whatthejeff@gmail.com>
18
* @copyright Sebastian Bergmann <sebastian@phpunit.de>
19
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
20
* @link http://www.github.com/sebastianbergmann/comparator
22
class ScalarComparatorTest extends \PHPUnit_Framework_TestCase
26
protected function setUp()
28
$this->comparator = new ScalarComparator;
31
public function acceptsSucceedsProvider()
34
array("string", "string"),
35
array(new ClassWithToString, "string"),
36
array("string", new ClassWithToString),
37
array("string", null),
38
array(false, "string"),
51
public function acceptsFailsProvider()
54
array(array(), array()),
55
array("string", array()),
56
array(new ClassWithToString, new ClassWithToString),
57
array(false, new ClassWithToString),
58
array(tmpfile(), tmpfile())
62
public function assertEqualsSucceedsProvider()
65
array("string", "string"),
66
array(new ClassWithToString, new ClassWithToString),
67
array("string representation", new ClassWithToString),
68
array(new ClassWithToString, "string representation"),
69
array("string", "STRING", true),
70
array("STRING", "string", true),
71
array("String Representation", new ClassWithToString, true),
72
array(new ClassWithToString, "String Representation", true),
86
public function assertEqualsFailsProvider()
88
$stringException = 'Failed asserting that two strings are equal.';
89
$otherException = 'matches expected';
92
array("string", "other string", $stringException),
93
array("string", "STRING", $stringException),
94
array("STRING", "string", $stringException),
95
array("string", "other string", $stringException),
96
// https://github.com/sebastianbergmann/phpunit/issues/1023
97
array('9E6666666','9E7777777', $stringException),
98
array(new ClassWithToString, "does not match", $otherException),
99
array("does not match", new ClassWithToString, $otherException),
100
array(0, 'Foobar', $otherException),
101
array('Foobar', 0, $otherException),
102
array("10", 25, $otherException),
103
array("1", false, $otherException),
104
array("", true, $otherException),
105
array(false, true, $otherException),
106
array(true, false, $otherException),
107
array(null, true, $otherException),
108
array(0, true, $otherException)
114
* @dataProvider acceptsSucceedsProvider
116
public function testAcceptsSucceeds($expected, $actual)
119
$this->comparator->accepts($expected, $actual)
125
* @dataProvider acceptsFailsProvider
127
public function testAcceptsFails($expected, $actual)
130
$this->comparator->accepts($expected, $actual)
135
* @covers ::assertEquals
136
* @dataProvider assertEqualsSucceedsProvider
138
public function testAssertEqualsSucceeds($expected, $actual, $ignoreCase = false)
143
$this->comparator->assertEquals($expected, $actual, 0.0, false, $ignoreCase);
146
catch (ComparisonFailure $exception) {
149
$this->assertNull($exception, 'Unexpected ComparisonFailure');
153
* @covers ::assertEquals
154
* @dataProvider assertEqualsFailsProvider
156
public function testAssertEqualsFails($expected, $actual, $message)
158
$this->setExpectedException(
159
'SebastianBergmann\\Comparator\\ComparisonFailure', $message
161
$this->comparator->assertEquals($expected, $actual);