Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PhpUnitBridge] added polyfill for assertStringContainsString*() #32878

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 32 additions & 15 deletions src/Symfony/Bridge/PhpUnit/Legacy/ForwardCompatTestTraitForV5.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Bridge\PhpUnit\Legacy;

use PHPUnit\Framework\Constraint\StringContains;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -51,33 +52,21 @@ protected function tearDown()
self::doTearDown();
}

/**
* @return void
*/
private static function doSetUpBeforeClass()
{
parent::setUpBeforeClass();
}

/**
* @return void
*/
private static function doTearDownAfterClass()
{
parent::tearDownAfterClass();
}

/**
* @return void
*/
private function doSetUp()
{
parent::setUp();
}

/**
* @return void
*/
private function doTearDown()
{
parent::tearDown();
Expand Down Expand Up @@ -233,6 +222,32 @@ public static function assertIsIterable($actual, $message = '')
static::assertInternalType('iterable', $actual, $message);
}

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

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

/**
* @param string $message
*
Expand Down Expand Up @@ -303,6 +318,8 @@ public function expectException($exception)
}

/**
* @param int|string $code
*
* @return void
*/
public function expectExceptionCode($code)
Expand All @@ -315,7 +332,7 @@ public function expectExceptionCode($code)

$property = new \ReflectionProperty(class_exists('PHPUnit_Framework_TestCase') ? 'PHPUnit_Framework_TestCase' : TestCase::class, 'expectedExceptionCode');
$property->setAccessible(true);
$property->setValue($this, $exception);
$property->setValue($this, $code);
}

/**
Expand All @@ -333,7 +350,7 @@ public function expectExceptionMessage($message)

$property = new \ReflectionProperty(class_exists('PHPUnit_Framework_TestCase') ? 'PHPUnit_Framework_TestCase' : TestCase::class, 'expectedExceptionMessage');
$property->setAccessible(true);
$property->setValue($this, $exception);
$property->setValue($this, $message);
}

/**
Expand All @@ -351,6 +368,6 @@ public function expectExceptionMessageRegExp($messageRegExp)

$property = new \ReflectionProperty(class_exists('PHPUnit_Framework_TestCase') ? 'PHPUnit_Framework_TestCase' : TestCase::class, 'expectedExceptionMessageRegExp');
$property->setAccessible(true);
$property->setValue($this, $exception);
$property->setValue($this, $messageRegExp);
}
}