Skip to content

[PhpUnitBridge] Add polyfill for expectException* methods #32869

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
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
93 changes: 93 additions & 0 deletions src/Symfony/Bridge/PhpUnit/Legacy/ForwardCompatTestTraitForV5.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@
namespace Symfony\Bridge\PhpUnit\Legacy;

use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

/**
* @internal
*/
trait ForwardCompatTestTraitForV5
{
private $forwardCompatExpectedExceptionMessage = '';
private $forwardCompatExpectedExceptionCode = null;

/**
* @return void
*/
Expand Down Expand Up @@ -210,4 +214,93 @@ public static function assertIsIterable($actual, $message = '')
{
static::assertInternalType('iterable', $actual, $message);
}

/**
* @param string $exception
*
* @return void
*/
public function expectException($exception)
{
if (method_exists(TestCase::class, 'expectException')) {
parent::expectException($exception);

return;
}

parent::setExpectedException($exception, $this->forwardCompatExpectedExceptionMessage, $this->forwardCompatExpectedExceptionCode);
}

/**
* @return void
*/
public function expectExceptionCode($code)
{
if (method_exists(TestCase::class, 'expectExceptionCode')) {
parent::expectExceptionCode($code);

return;
}

$this->forwardCompatExpectedExceptionCode = $code;
parent::setExpectedException(parent::getExpectedException(), $this->forwardCompatExpectedExceptionMessage, $this->forwardCompatExpectedExceptionCode);
}

/**
* @param string $message
*
* @return void
*/
public function expectExceptionMessage($message)
{
if (method_exists(TestCase::class, 'expectExceptionMessage')) {
parent::expectExceptionMessage($message);

return;
}

$this->forwardCompatExpectedExceptionMessage = $message;
parent::setExpectedException(parent::getExpectedException(), $this->forwardCompatExpectedExceptionMessage, $this->forwardCompatExpectedExceptionCode);
}

/**
* @param string $messageRegExp
*
* @return void
*/
public function expectExceptionMessageRegExp($messageRegExp)
{
if (method_exists(TestCase::class, 'expectExceptionMessageRegExp')) {
parent::expectExceptionMessageRegExp($messageRegExp);

return;
}

parent::setExpectedExceptionRegExp(parent::getExpectedException(), $messageRegExp, $this->forwardCompatExpectedExceptionCode);
}

/**
* @param string $exceptionMessage
*
* @return void
*/
public function setExpectedException($exceptionName, $exceptionMessage = '', $exceptionCode = null)
{
$this->forwardCompatExpectedExceptionMessage = $exceptionMessage;
$this->forwardCompatExpectedExceptionCode = $exceptionCode;

parent::setExpectedException($exceptionName, $exceptionMessage, $exceptionCode);
}

/**
* @param string $exceptionMessageRegExp
*
* @return void
*/
public function setExpectedExceptionRegExp($exceptionName, $exceptionMessageRegExp = '', $exceptionCode = null)
{
$this->forwardCompatExpectedExceptionCode = $exceptionCode;

parent::setExpectedExceptionRegExp($exceptionName, $exceptionMessageRegExp, $exceptionCode);
}
}
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy