Skip to content

Commit

Permalink
Closes #3949
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Nov 21, 2019
1 parent c2dc144 commit f4660f5
Show file tree
Hide file tree
Showing 3 changed files with 337 additions and 0 deletions.
1 change: 1 addition & 0 deletions ChangeLog-8.5.md
Expand Up @@ -7,6 +7,7 @@ All notable changes of the PHPUnit 8.5 release series are documented in this fil
### Added

* Implemented [#3911](https://github.com/sebastianbergmann/phpunit/issues/3911): Support combined use of `addMethods()` and `onlyMethods()`
* Implemented [#3949](https://github.com/sebastianbergmann/phpunit/issues/3949): Introduce specialized assertions `assertFileEqualsCanonicalizing()`, `assertFileEqualsIgnoringCase()`, `assertStringEqualsFileCanonicalizing()`, `assertStringEqualsFileIgnoringCase()`, `assertFileNotEqualsCanonicalizing()`, `assertFileNotEqualsIgnoringCase()`, `assertStringNotEqualsFileCanonicalizing()`, and `assertStringNotEqualsFileIgnoringCase()` as alternative to using `assertFileEquals()` etc. with optional parameters

[8.5.0]: https://github.com/sebastianbergmann/phpunit/compare/8.4...master

224 changes: 224 additions & 0 deletions src/Framework/Assert.php
Expand Up @@ -1035,6 +1035,16 @@ public static function assertAttributeLessThanOrEqual($expected, string $actualA
*/
public static function assertFileEquals(string $expected, string $actual, string $message = '', bool $canonicalize = false, bool $ignoreCase = false): void
{
// @codeCoverageIgnoreStart
if ($canonicalize) {
self::createWarning('The optional $canonicalize parameter of assertFileEquals() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertFileEqualsCanonicalizing() instead.');
}

if ($ignoreCase) {
self::createWarning('The optional $ignoreCase parameter of assertFileEquals() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertFileEqualsIgnoringCase() instead.');
}
// @codeCoverageIgnoreEnd

static::assertFileExists($expected, $message);
static::assertFileExists($actual, $message);

Expand All @@ -1049,6 +1059,51 @@ public static function assertFileEquals(string $expected, string $actual, string
static::assertThat(\file_get_contents($actual), $constraint, $message);
}

/**
* Asserts that the contents of one file is equal to the contents of another
* file (canonicalizing).
*
* @throws ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public static function assertFileEqualsCanonicalizing(string $expected, string $actual, string $message = ''): void
{
static::assertFileExists($expected, $message);
static::assertFileExists($actual, $message);

$constraint = new IsEqual(
\file_get_contents($expected),
0.0,
10,
true
);

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

/**
* Asserts that the contents of one file is equal to the contents of another
* file (ignoring case).
*
* @throws ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public static function assertFileEqualsIgnoringCase(string $expected, string $actual, string $message = ''): void
{
static::assertFileExists($expected, $message);
static::assertFileExists($actual, $message);

$constraint = new IsEqual(
\file_get_contents($expected),
0.0,
10,
false,
true
);

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

/**
* Asserts that the contents of one file is not equal to the contents of
* another file.
Expand All @@ -1058,6 +1113,16 @@ public static function assertFileEquals(string $expected, string $actual, string
*/
public static function assertFileNotEquals(string $expected, string $actual, string $message = '', bool $canonicalize = false, bool $ignoreCase = false): void
{
// @codeCoverageIgnoreStart
if ($canonicalize) {
self::createWarning('The optional $canonicalize parameter of assertFileNotEquals() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertFileNotEqualsCanonicalizing() instead.');
}

if ($ignoreCase) {
self::createWarning('The optional $ignoreCase parameter of assertFileNotEquals() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertFileNotEqualsIgnoringCase() instead.');
}
// @codeCoverageIgnoreEnd

static::assertFileExists($expected, $message);
static::assertFileExists($actual, $message);

Expand All @@ -1074,6 +1139,55 @@ public static function assertFileNotEquals(string $expected, string $actual, str
static::assertThat(\file_get_contents($actual), $constraint, $message);
}

/**
* Asserts that the contents of one file is not equal to the contents of another
* file (canonicalizing).
*
* @throws ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public static function assertFileNotEqualsCanonicalizing(string $expected, string $actual, string $message = ''): void
{
static::assertFileExists($expected, $message);
static::assertFileExists($actual, $message);

$constraint = new LogicalNot(
new IsEqual(
\file_get_contents($expected),
0.0,
10,
true
)
);

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

/**
* Asserts that the contents of one file is not equal to the contents of another
* file (ignoring case).
*
* @throws ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public static function assertFileNotEqualsIgnoringCase(string $expected, string $actual, string $message = ''): void
{
static::assertFileExists($expected, $message);
static::assertFileExists($actual, $message);

$constraint = new LogicalNot(
new IsEqual(
\file_get_contents($expected),
0.0,
10,
false,
true
)
);

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

/**
* Asserts that the contents of a string is equal
* to the contents of a file.
Expand All @@ -1083,6 +1197,16 @@ public static function assertFileNotEquals(string $expected, string $actual, str
*/
public static function assertStringEqualsFile(string $expectedFile, string $actualString, string $message = '', bool $canonicalize = false, bool $ignoreCase = false): void
{
// @codeCoverageIgnoreStart
if ($canonicalize) {
self::createWarning('The optional $canonicalize parameter of assertStringEqualsFile() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertStringEqualsFileCanonicalizing() instead.');
}

if ($ignoreCase) {
self::createWarning('The optional $ignoreCase parameter of assertStringEqualsFile() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertStringEqualsFileIgnoringCase() instead.');
}
// @codeCoverageIgnoreEnd

static::assertFileExists($expectedFile, $message);

$constraint = new IsEqual(
Expand All @@ -1096,6 +1220,49 @@ public static function assertStringEqualsFile(string $expectedFile, string $actu
static::assertThat($actualString, $constraint, $message);
}

/**
* Asserts that the contents of a string is equal
* to the contents of a file (canonicalizing).
*
* @throws ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public static function assertStringEqualsFileCanonicalizing(string $expectedFile, string $actualString, string $message = ''): void
{
static::assertFileExists($expectedFile, $message);

$constraint = new IsEqual(
\file_get_contents($expectedFile),
0.0,
10,
true
);

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

/**
* Asserts that the contents of a string is equal
* to the contents of a file (ignoring case).
*
* @throws ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public static function assertStringEqualsFileIgnoringCase(string $expectedFile, string $actualString, string $message = ''): void
{
static::assertFileExists($expectedFile, $message);

$constraint = new IsEqual(
\file_get_contents($expectedFile),
0.0,
10,
false,
true
);

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

/**
* Asserts that the contents of a string is not equal
* to the contents of a file.
Expand All @@ -1105,6 +1272,16 @@ public static function assertStringEqualsFile(string $expectedFile, string $actu
*/
public static function assertStringNotEqualsFile(string $expectedFile, string $actualString, string $message = '', bool $canonicalize = false, bool $ignoreCase = false): void
{
// @codeCoverageIgnoreStart
if ($canonicalize) {
self::createWarning('The optional $canonicalize parameter of assertStringNotEqualsFile() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertStringNotEqualsFileCanonicalizing() instead.');
}

if ($ignoreCase) {
self::createWarning('The optional $ignoreCase parameter of assertStringNotEqualsFile() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertStringNotEqualsFileIgnoringCase() instead.');
}
// @codeCoverageIgnoreEnd

static::assertFileExists($expectedFile, $message);

$constraint = new LogicalNot(
Expand All @@ -1120,6 +1297,53 @@ public static function assertStringNotEqualsFile(string $expectedFile, string $a
static::assertThat($actualString, $constraint, $message);
}

/**
* Asserts that the contents of a string is not equal
* to the contents of a file (canonicalizing).
*
* @throws ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public static function assertStringNotEqualsFileCanonicalizing(string $expectedFile, string $actualString, string $message = ''): void
{
static::assertFileExists($expectedFile, $message);

$constraint = new LogicalNot(
new IsEqual(
\file_get_contents($expectedFile),
0.0,
10,
true
)
);

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

/**
* Asserts that the contents of a string is not equal
* to the contents of a file (ignoring case).
*
* @throws ExpectationFailedException
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
*/
public static function assertStringNotEqualsFileIgnoringCase(string $expectedFile, string $actualString, string $message = ''): void
{
static::assertFileExists($expectedFile, $message);

$constraint = new LogicalNot(
new IsEqual(
\file_get_contents($expectedFile),
0.0,
10,
false,
true
)
);

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

/**
* Asserts that a file/dir is readable.
*
Expand Down

0 comments on commit f4660f5

Please sign in to comment.