Skip to content

Commit

Permalink
Add compat for "expectExceptionMessage"
Browse files Browse the repository at this point in the history
  • Loading branch information
rougin committed Nov 14, 2024
1 parent 37d317b commit 9e7a899
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion tests/ResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function test_undefined_field()
{
$expected = 'Field "age" not found';

$this->expectExceptionMessage($expected);
$this->doExpectExceptionMessage($expected);

$result = new Result;

Expand Down
4 changes: 2 additions & 2 deletions tests/Source/BasicSourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function test_invalid_with_error()
*/
public function test_invalid_without_result()
{
$this->expectExceptionMessage('Validation failed');
$this->doExpectExceptionMessage('Validation failed');

$payload = array('email' => 'me@roug.in');

Expand Down Expand Up @@ -92,7 +92,7 @@ public function test_valid_with_result()
*/
public function test_valid_without_error()
{
$this->expectExceptionMessage('Validation passed');
$this->doExpectExceptionMessage('Validation passed');

$payload = array();

Expand Down
31 changes: 28 additions & 3 deletions tests/Testcase.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,42 @@
*/
class Testcase extends Legacy
{
/** @phpstan-ignore-next-line */
public function setExpectedException($exception)
/**
* @param string $exception
*
* @return void
*/
public function doSetExpectedException($exception)
{
if (method_exists($this, 'expectException'))
{
/** @phpstan-ignore-next-line */
$this->expectException($exception);

return;
}

/** @phpstan-ignore-next-line */
parent::setExpectedException($exception);
$this->setExpectedException($exception);
}

/**
* @param string $message
*
* @return void
*/
public function doExpectExceptionMessage($message)
{
if (! method_exists($this, 'expectExceptionMessage'))
{
$exception = 'Exception';

/** @phpstan-ignore-next-line */
$this->setExpectedException($exception, $message);

return;
}

$this->expectExceptionMessage($message);
}
}

0 comments on commit 9e7a899

Please sign in to comment.