Skip to content

Commit

Permalink
minor #32907 [PhpUnitBridge] add more assert*() polyfills (nicolas-gr…
Browse files Browse the repository at this point in the history
…ekas)

This PR was merged into the 4.4 branch.

Discussion
----------

[PhpUnitBridge] add more assert*() polyfills

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #32844
| License       | MIT
| Doc PR        | -

Commits
-------

54ddfd2 [PhpUnitBridge] add more assert*() polyfills
  • Loading branch information
nicolas-grekas committed Aug 3, 2019
2 parents d01ec68 + 54ddfd2 commit 5d5e04b
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions src/Symfony/Bridge/PhpUnit/Legacy/ForwardCompatTestTraitForV5.php
Expand Up @@ -11,7 +11,10 @@

namespace Symfony\Bridge\PhpUnit\Legacy;

use PHPUnit\Framework\Constraint\IsEqual;
use PHPUnit\Framework\Constraint\LogicalNot;
use PHPUnit\Framework\Constraint\StringContains;
use PHPUnit\Framework\Constraint\TraversableContains;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -112,6 +115,42 @@ protected function createPartialMock($originalClassName, array $methods)
return $mock->getMock();
}

/**
* @param float $delta
* @param string $message
*
* @return void
*/
public static function assertEqualsWithDelta($expected, $actual, $delta, $message = '')
{
$constraint = new IsEqual($expected, $delta);
static::assertThat($actual, $constraint, $message);
}

/**
* @param iterable $haystack
* @param string $message
*
* @return void
*/
public static function assertContainsEquals($needle, $haystack, $message = '')
{
$constraint = new TraversableContains($needle, false, false);
static::assertThat($haystack, $constraint, $message);
}

/**
* @param iterable $haystack
* @param string $message
*
* @return void
*/
public static function assertNotContainsEquals($needle, $haystack, $message = '')
{
$constraint = new LogicalNot(new TraversableContains($needle, false, false));
static::assertThat($haystack, $constraint, $message);
}

/**
* @param string $message
*
Expand Down Expand Up @@ -248,6 +287,32 @@ public static function assertStringContainsStringIgnoringCase($needle, $haystack
static::assertThat($haystack, $constraint, $message);
}

/**
* @param string $needle
* @param string $haystack
* @param string $message
*
* @return void
*/
public static function assertStringNotContainsString($needle, $haystack, $message = '')
{
$constraint = new LogicalNot(new StringContains($needle, false));
static::assertThat($haystack, $constraint, $message);
}

/**
* @param string $needle
* @param string $haystack
* @param string $message
*
* @return void
*/
public static function assertStringNotContainsStringIgnoringCase($needle, $haystack, $message = '')
{
$constraint = new LogicalNot(new StringContains($needle, true));
static::assertThat($haystack, $constraint, $message);
}

/**
* @param string $message
*
Expand Down

0 comments on commit 5d5e04b

Please sign in to comment.