Skip to content

Commit

Permalink
Closes #3341
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Nov 19, 2018
1 parent a76792c commit bb1d5aa
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 66 deletions.
1 change: 1 addition & 0 deletions ChangeLog-8.0.md
Expand Up @@ -7,6 +7,7 @@ All notable changes of the PHPUnit 8.0 release series are documented in this fil
### Changed

* Implemented [#3288](https://github.com/sebastianbergmann/phpunit/issues/3288): The `void_return` fixer of php-cs-fixer is now in effect
* Implemented [#3341](https://github.com/sebastianbergmann/phpunit/issues/3341): Deprecate optional parameters of `assertEquals()` and `assertNotEquals()`

### Removed

Expand Down
81 changes: 54 additions & 27 deletions src/Framework/Assert.php
Expand Up @@ -487,6 +487,22 @@ public static function assertAttributeNotCount(int $expectedCount, string $hayst
*/
public static function assertEquals($expected, $actual, string $message = '', float $delta = 0.0, int $maxDepth = 10, bool $canonicalize = false, bool $ignoreCase = false): void
{
if ($delta !== 0.0) {
self::createWarning('The optional $delta parameter of assertEquals() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertEqualsWithDelta() instead.');
}

if ($maxDepth !== 10) {
self::createWarning('The optional $maxDepth parameter of assertEquals() is deprecated and will be removed in PHPUnit 9.');
}

if ($canonicalize !== false) {
self::createWarning('The optional $canonicalize parameter of assertEquals() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertEqualsCanonicalizing() instead.');
}

if ($ignoreCase !== false) {
self::createWarning('The optional $ignoreCase parameter of assertEquals() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertEqualsIgnoringCase() instead.');
}

$constraint = new IsEqual(
$expected,
$delta,
Expand Down Expand Up @@ -588,6 +604,22 @@ public static function assertAttributeEquals($expected, string $actualAttributeN
*/
public static function assertNotEquals($expected, $actual, string $message = '', $delta = 0.0, $maxDepth = 10, $canonicalize = false, $ignoreCase = false): void
{
if ($delta !== 0.0) {
self::createWarning('The optional $delta parameter of assertNotEquals() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertNotEqualsWithDelta() instead.');
}

if ($maxDepth !== 10) {
self::createWarning('The optional $maxDepth parameter of assertNotEquals() is deprecated and will be removed in PHPUnit 9.');
}

if ($canonicalize !== false) {
self::createWarning('The optional $canonicalize parameter of assertNotEquals() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertNotEqualsCanonicalizing() instead.');
}

if ($ignoreCase !== false) {
self::createWarning('The optional $ignoreCase parameter of assertNotEquals() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertNotEqualsIgnoringCase() instead.');
}

$constraint = new LogicalNot(
new IsEqual(
$expected,
Expand Down Expand Up @@ -880,15 +912,13 @@ public static function assertFileEquals(string $expected, string $actual, string
static::assertFileExists($expected, $message);
static::assertFileExists($actual, $message);

static::assertEquals(
$constraint = new IsEqual(
\file_get_contents($expected),
\file_get_contents($actual),
$message,
0,
10,
$canonicalize,
$ignoreCase
);

static::assertThat(\file_get_contents($actual), $constraint, $message);
}

/**
Expand All @@ -903,15 +933,15 @@ public static function assertFileNotEquals(string $expected, string $actual, str
static::assertFileExists($expected, $message);
static::assertFileExists($actual, $message);

static::assertNotEquals(
\file_get_contents($expected),
\file_get_contents($actual),
$message,
0,
10,
$canonicalize,
$ignoreCase
$constraint = new LogicalNot(
new IsEqual(
\file_get_contents($expected),
$canonicalize,
$ignoreCase
)
);

static::assertThat(\file_get_contents($actual), $constraint, $message);
}

/**
Expand All @@ -925,16 +955,13 @@ public static function assertStringEqualsFile(string $expectedFile, string $actu
{
static::assertFileExists($expectedFile, $message);

/** @noinspection PhpUnitTestsInspection */
static::assertEquals(
$constraint = new IsEqual(
\file_get_contents($expectedFile),
$actualString,
$message,
0,
10,
$canonicalize,
$ignoreCase
);

static::assertThat($actualString, $constraint, $message);
}

/**
Expand All @@ -948,15 +975,15 @@ public static function assertStringNotEqualsFile(string $expectedFile, string $a
{
static::assertFileExists($expectedFile, $message);

static::assertNotEquals(
\file_get_contents($expectedFile),
$actualString,
$message,
0,
10,
$canonicalize,
$ignoreCase
$constraint = new LogicalNot(
new IsEqual(
\file_get_contents($expectedFile),
$canonicalize,
$ignoreCase
)
);

static::assertThat($actualString, $constraint, $message);
}

/**
Expand Down
47 changes: 8 additions & 39 deletions tests/unit/Framework/AssertTest.php
Expand Up @@ -525,9 +525,9 @@ public function notSameProvider(): array
* @throws ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testAssertEqualsSucceeds($a, $b, $delta = 0.0, $canonicalize = false, $ignoreCase = false): void
public function testAssertEqualsSucceeds($a, $b): void
{
$this->assertEquals($a, $b, '', $delta, 10, $canonicalize, $ignoreCase);
$this->assertEquals($a, $b);
}

/**
Expand All @@ -536,11 +536,11 @@ public function testAssertEqualsSucceeds($a, $b, $delta = 0.0, $canonicalize = f
* @throws ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testAssertEqualsFails($a, $b, $delta = 0.0, $canonicalize = false, $ignoreCase = false): void
public function testAssertEqualsFails($a, $b): void
{
$this->expectException(AssertionFailedError::class);

$this->assertEquals($a, $b, '', $delta, 10, $canonicalize, $ignoreCase);
$this->assertEquals($a, $b);
}

/**
Expand All @@ -549,9 +549,9 @@ public function testAssertEqualsFails($a, $b, $delta = 0.0, $canonicalize = fals
* @throws ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testAssertNotEqualsSucceeds($a, $b, $delta = 0.0, $canonicalize = false, $ignoreCase = false): void
public function testAssertNotEqualsSucceeds($a, $b): void
{
$this->assertNotEquals($a, $b, '', $delta, 10, $canonicalize, $ignoreCase);
$this->assertNotEquals($a, $b);
}

/**
Expand All @@ -560,11 +560,11 @@ public function testAssertNotEqualsSucceeds($a, $b, $delta = 0.0, $canonicalize
* @throws ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public function testAssertNotEqualsFails($a, $b, $delta = 0.0, $canonicalize = false, $ignoreCase = false): void
public function testAssertNotEqualsFails($a, $b): void
{
$this->expectException(AssertionFailedError::class);

$this->assertNotEquals($a, $b, '', $delta, 10, $canonicalize, $ignoreCase);
$this->assertNotEquals($a, $b);
}

/**
Expand Down Expand Up @@ -3017,20 +3017,9 @@ protected function equalValues(): array
$storage2->attach($object1);

return [
// strings
['a', 'A', 0, false, true], // ignore case
// arrays
[['a' => 1, 'b' => 2], ['b' => 2, 'a' => 1]],
[[1], ['1']],
[[3, 2, 1], [2, 3, 1], 0, true], // canonicalized comparison
// floats
[2.3, 2.5, 0.5],
[[2.3], [2.5], 0.5],
[[[2.3]], [[2.5]], 0.5],
[new \Struct(2.3), new \Struct(2.5), 0.5],
[[new \Struct(2.3)], [new \Struct(2.5)], 0.5],
// numeric with delta
[1, 2, 1],
// objects
[$object1, $object2],
[$book1, $book2],
Expand All @@ -3057,16 +3046,6 @@ protected function equalValues(): array
new \DateTime('2013-03-29 04:13:35', new \DateTimeZone('America/New_York')),
new \DateTime('2013-03-29 04:13:35', new \DateTimeZone('America/New_York')),
],
[
new \DateTime('2013-03-29 04:13:35', new \DateTimeZone('America/New_York')),
new \DateTime('2013-03-29 04:13:25', new \DateTimeZone('America/New_York')),
10,
],
[
new \DateTime('2013-03-29 04:13:35', new \DateTimeZone('America/New_York')),
new \DateTime('2013-03-29 04:14:40', new \DateTimeZone('America/New_York')),
65,
],
[
new \DateTime('2013-03-29', new \DateTimeZone('America/New_York')),
new \DateTime('2013-03-29', new \DateTimeZone('America/New_York')),
Expand All @@ -3075,20 +3054,10 @@ protected function equalValues(): array
new \DateTime('2013-03-29 04:13:35', new \DateTimeZone('America/New_York')),
new \DateTime('2013-03-29 03:13:35', new \DateTimeZone('America/Chicago')),
],
[
new \DateTime('2013-03-29 04:13:35', new \DateTimeZone('America/New_York')),
new \DateTime('2013-03-29 03:13:49', new \DateTimeZone('America/Chicago')),
15,
],
[
new \DateTime('2013-03-30', new \DateTimeZone('America/New_York')),
new \DateTime('2013-03-29 23:00:00', new \DateTimeZone('America/Chicago')),
],
[
new \DateTime('2013-03-30', new \DateTimeZone('America/New_York')),
new \DateTime('2013-03-29 23:01:30', new \DateTimeZone('America/Chicago')),
100,
],
[
new \DateTime('@1364616000'),
new \DateTime('2013-03-29 23:00:00', new \DateTimeZone('America/Chicago')),
Expand Down

0 comments on commit bb1d5aa

Please sign in to comment.