Skip to content

Commit

Permalink
Closes #4663
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed May 6, 2021
1 parent f3cd275 commit faa3a11
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 6 deletions.
4 changes: 4 additions & 0 deletions ChangeLog-8.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ All notable changes of the PHPUnit 8.5 release series are documented in this fil

* The test result cache (the storage for which is implemented in `PHPUnit\Runner\DefaultTestResultCache`) no longer uses PHP's `serialize()` and `unserialize()` function for persistence. It now uses a versioned JSON format instead that is independent of PHP implementation details (see [#3581](https://github.com/sebastianbergmann/phpunit/issues/3581) and [#4662](https://github.com/sebastianbergmann/phpunit/pull/4662) for examples why this is a problem). When PHPUnit tries to load the test result cache from a file that does not exist, or from a file that does not contain data in JSON format, or from a file that contains data in a JSON format version other than the one uses by the currently running PHPUnit version, then this is considered to be a "cache miss". An empty `DefaultTestResultCache` object is created in this case. This should also prevent PHPUnit from crashing when trying to load a test result cache file created by a different version of PHPUnit (see [#4580](https://github.com/sebastianbergmann/phpunit/issues/4580) for example).

### Fixed

* [#4663](https://github.com/sebastianbergmann/phpunit/issues/4663): `TestCase::expectError()` works on PHP 7.3, but not on PHP >= 7.4

## [8.5.15] - 2021-03-17

### Fixed
Expand Down
23 changes: 17 additions & 6 deletions src/Framework/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
use PHPUnit\Framework\Constraint\ExceptionCode;
use PHPUnit\Framework\Constraint\ExceptionMessage;
use PHPUnit\Framework\Constraint\ExceptionMessageRegularExpression;
use PHPUnit\Framework\Constraint\LogicalOr;
use PHPUnit\Framework\Error\Deprecated;
use PHPUnit\Framework\Error\Error;
use PHPUnit\Framework\Error\Notice;
Expand Down Expand Up @@ -1475,12 +1476,22 @@ protected function runTest()
}

if ($this->expectedException !== null) {
$this->assertThat(
$exception,
new ExceptionConstraint(
$this->expectedException
)
);
if ($this->expectedException === Error::class) {
$this->assertThat(
$exception,
LogicalOr::fromConstraints(
new ExceptionConstraint(Error::class),
new ExceptionConstraint(\Error::class)
)
);
} else {
$this->assertThat(
$exception,
new ExceptionConstraint(
$this->expectedException
)
);
}
}

if ($this->expectedExceptionMessage !== null) {
Expand Down
19 changes: 19 additions & 0 deletions tests/end-to-end/regression/GitHub/4663.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
https://github.com/sebastianbergmann/phpunit/issues/4663
--FILE--
<?php declare(strict_types=1);
$_SERVER['argv'][] = '--do-not-cache-result';
$_SERVER['argv'][] = '--no-configuration';
$_SERVER['argv'][] = __DIR__ . '/4663/Issue4663Test.php';

require __DIR__ . '/../../../bootstrap.php';

PHPUnit\TextUI\Command::main();
--EXPECTF--
PHPUnit %s by Sebastian Bergmann and contributors.

. 1 / 1 (100%)

Time: %s, Memory: %s

OK (1 test, 2 assertions)
20 changes: 20 additions & 0 deletions tests/end-to-end/regression/GitHub/4663/Issue4663Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use PHPUnit\Framework\TestCase;

final class Issue4663Test extends TestCase
{
public function testTestThatExpectsAnErrorPassesWhenTheErrorOccurs(): void
{
$this->expectError();

implode('', [new stdClass]);
}
}

0 comments on commit faa3a11

Please sign in to comment.