8000 [PhpUnitBridge] Support new expect methods in test case polyfill by alcaeus · Pull Request #38680 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[PhpUnitBridge] Support new expect methods in test case polyfill #38680

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

Merged
merged 1 commit into from
Oct 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 95 additions & 3 deletions src/Symfony/Bridge/PhpUnit/Legacy/PolyfillTestCaseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

namespace Symfony\Bridge\PhpUnit\Legacy;

use PHPUnit\Framework\Error\Error;
use PHPUnit\Framework\Error\Notice;
use PHPUnit\Framework\Error\Warning;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -66,9 +69,7 @@ protected function createPartialMock($originalClassName, array $methods)
*/
public function expectException($exception)
{
$property = new \ReflectionProperty(TestCase::class, 'expectedException');
$property->setAccessible(true);
$property->setValue($this, $exception);
$this->doExpectException($exception);
}

/**
Expand Down Expand Up @@ -116,4 +117,95 @@ public function expectExceptionMessageRegExp($messageRegExp)
$property->setAccessible(true);
$property->setValue($this, $messageRegExp);
}

/**
* @return void
*/
public function expectNotice()
{
$this->doExpectException(Notice::class);
}

/**
* @param string $message
*
* @return void
*/
public function expectNoticeMessage($message)
{
$this->expectExceptionMessage($message);
}

/**
* @param string $regularExpression
*
* @return void
*/
public function expectNoticeMessageMatches($regularExpression)
{
$this->expectExceptionMessageMatches($regularExpression);
}

/**
* @return void
*/
public function expectWarning()
{
$this->doExpectException(Warning::class);
}

/**
* @param string $message
*
* @return void
*/
public function expectWarningMessage($message)
{
$this->expectExceptionMessage($message);
}

/**
* @param string $regularExpression
*
* @return void
*/
public function expectWarningMessageMatches($regularExpression)
{
$this->expectExceptionMessageMatches($regularExpression);
}

/**
* @return void
*/
public function expectError()
{
$this->doExpectException(Error::class);
}

/**
* @param string $message
*
* @return void
*/
public function expectErrorMessage($message)
{
$this->expectExceptionMessage($message);
}

/**
* @param string $regularExpression
*
* @return void
*/
public function expectErrorMessageMatches($regularExpression)
{
$this->expectExceptionMessageMatches($regularExpression);
}

private function doExpectException($exception)
{
$property = new \ReflectionProperty(TestCase::class, 'expectedException');
$property->setAccessible(true);
$property->setValue($this, $exception);
}
}
0