Merge branch '5.1'
* 5.1: Expect deprecations in isolation
This commit is contained in:
commit
812a4d5a27
@ -23,6 +23,21 @@ trait ExpectDeprecationTraitBeforeV8_4
|
|||||||
*/
|
*/
|
||||||
protected function expectDeprecation($message)
|
protected function expectDeprecation($message)
|
||||||
{
|
{
|
||||||
|
// Expected deprecations set by isolated tests need to be written to a file
|
||||||
|
// so that the test running process can take account of them.
|
||||||
|
if ($file = getenv('SYMFONY_EXPECTED_DEPRECATIONS_SERIALIZE')) {
|
||||||
|
$this->getTestResultObject()->beStrictAboutTestsThatDoNotTestAnything(false);
|
||||||
|
$expectedDeprecations = file_get_contents($file);
|
||||||
|
if ($expectedDeprecations) {
|
||||||
|
$expectedDeprecations = array_merge(unserialize($expectedDeprecations), [$message]);
|
||||||
|
} else {
|
||||||
|
$expectedDeprecations = [$message];
|
||||||
|
}
|
||||||
|
file_put_contents($file, serialize($expectedDeprecations));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!SymfonyTestsListenerTrait::$previousErrorHandler) {
|
if (!SymfonyTestsListenerTrait::$previousErrorHandler) {
|
||||||
SymfonyTestsListenerTrait::$previousErrorHandler = set_error_handler([SymfonyTestsListenerTrait::class, 'handleError']);
|
SymfonyTestsListenerTrait::$previousErrorHandler = set_error_handler([SymfonyTestsListenerTrait::class, 'handleError']);
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,21 @@ trait ExpectDeprecationTraitForV8_4
|
|||||||
throw new \InvalidArgumentException(sprintf('The "%s()" method requires the string $message argument.', __FUNCTION__));
|
throw new \InvalidArgumentException(sprintf('The "%s()" method requires the string $message argument.', __FUNCTION__));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Expected deprecations set by isolated tests need to be written to a file
|
||||||
|
// so that the test running process can take account of them.
|
||||||
|
if ($file = getenv('SYMFONY_EXPECTED_DEPRECATIONS_SERIALIZE')) {
|
||||||
|
$this->getTestResultObject()->beStrictAboutTestsThatDoNotTestAnything(false);
|
||||||
|
$expectedDeprecations = file_get_contents($file);
|
||||||
|
if ($expectedDeprecations) {
|
||||||
|
$expectedDeprecations = array_merge(unserialize($expectedDeprecations), [$message]);
|
||||||
|
} else {
|
||||||
|
$expectedDeprecations = [$message];
|
||||||
|
}
|
||||||
|
file_put_contents($file, serialize($expectedDeprecations));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!SymfonyTestsListenerTrait::$previousErrorHandler) {
|
if (!SymfonyTestsListenerTrait::$previousErrorHandler) {
|
||||||
SymfonyTestsListenerTrait::$previousErrorHandler = set_error_handler([SymfonyTestsListenerTrait::class, 'handleError']);
|
SymfonyTestsListenerTrait::$previousErrorHandler = set_error_handler([SymfonyTestsListenerTrait::class, 'handleError']);
|
||||||
}
|
}
|
||||||
|
@ -208,6 +208,7 @@ class SymfonyTestsListenerTrait
|
|||||||
if ($this->willBeIsolated($test)) {
|
if ($this->willBeIsolated($test)) {
|
||||||
$this->runsInSeparateProcess = tempnam(sys_get_temp_dir(), 'deprec');
|
$this->runsInSeparateProcess = tempnam(sys_get_temp_dir(), 'deprec');
|
||||||
putenv('SYMFONY_DEPRECATIONS_SERIALIZE='.$this->runsInSeparateProcess);
|
putenv('SYMFONY_DEPRECATIONS_SERIALIZE='.$this->runsInSeparateProcess);
|
||||||
|
putenv('SYMFONY_EXPECTED_DEPRECATIONS_SERIALIZE='.tempnam(sys_get_temp_dir(), 'expectdeprec'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$groups = Test::getGroups(\get_class($test), $test->getName(false));
|
$groups = Test::getGroups(\get_class($test), $test->getName(false));
|
||||||
@ -249,6 +250,17 @@ class SymfonyTestsListenerTrait
|
|||||||
|
|
||||||
public function endTest($test, $time)
|
public function endTest($test, $time)
|
||||||
{
|
{
|
||||||
|
if ($file = getenv('SYMFONY_EXPECTED_DEPRECATIONS_SERIALIZE')) {
|
||||||
|
putenv('SYMFONY_EXPECTED_DEPRECATIONS_SERIALIZE');
|
||||||
|
$expectedDeprecations = file_get_contents($file);
|
||||||
|
if ($expectedDeprecations) {
|
||||||
|
self::$expectedDeprecations = array_merge(self::$expectedDeprecations, unserialize($expectedDeprecations));
|
||||||
|
if (!self::$previousErrorHandler) {
|
||||||
|
self::$previousErrorHandler = set_error_handler([self::class, 'handleError']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (class_exists(DebugClassLoader::class, false)) {
|
if (class_exists(DebugClassLoader::class, false)) {
|
||||||
DebugClassLoader::checkClasses();
|
DebugClassLoader::checkClasses();
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,18 @@ final class ExpectDeprecationTraitTest extends TestCase
|
|||||||
@trigger_error('foo', E_USER_DEPRECATED);
|
@trigger_error('foo', E_USER_DEPRECATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do not remove this test in the next major version.
|
||||||
|
*
|
||||||
|
* @group legacy
|
||||||
|
* @runInSeparateProcess
|
||||||
|
*/
|
||||||
|
public function testOneInIsolation()
|
||||||
|
{
|
||||||
|
$this->expectDeprecation('foo');
|
||||||
|
@trigger_error('foo', E_USER_DEPRECATED);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Do not remove this test in the next major version.
|
* Do not remove this test in the next major version.
|
||||||
*
|
*
|
||||||
|
@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Bridge\PhpUnit\Tests\FailTests;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ExpectDeprecationTraitTestFail.
|
||||||
|
*
|
||||||
|
* This class is deliberately suffixed with *TestFail.php so that it is ignored
|
||||||
|
* by PHPUnit. This test is designed to fail. See ../expectdeprecationfail.phpt.
|
||||||
|
*/
|
||||||
|
final class ExpectDeprecationTraitTestFail extends TestCase
|
||||||
|
{
|
||||||
|
use ExpectDeprecationTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do not remove this test in the next major version.
|
||||||
|
*
|
||||||
|
* @group legacy
|
||||||
|
*/
|
||||||
|
public function testOne()
|
||||||
|
{
|
||||||
|
$this->expectDeprecation('foo');
|
||||||
|
@trigger_error('bar', E_USER_DEPRECATED);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do not remove this test in the next major version.
|
||||||
|
*
|
||||||
|
* @group legacy
|
||||||
|
* @runInSeparateProcess
|
||||||
|
*/
|
||||||
|
public function testOneInIsolation()
|
||||||
|
{
|
||||||
|
$this->expectDeprecation('foo');
|
||||||
|
@trigger_error('bar', E_USER_DEPRECATED);
|
||||||
|
}
|
||||||
|
}
|
37
src/Symfony/Bridge/PhpUnit/Tests/expectdeprecationfail.phpt
Normal file
37
src/Symfony/Bridge/PhpUnit/Tests/expectdeprecationfail.phpt
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
--TEST--
|
||||||
|
Test ExpectDeprecationTrait failing tests
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
$test = realpath(__DIR__ . '/FailTests/ExpectDeprecationTraitTestFail.php');
|
||||||
|
passthru(getenv('SYMFONY_SIMPLE_PHPUNIT_BIN_DIR') . '/simple-phpunit --colors=never ' . $test);
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
PHPUnit %s by Sebastian Bergmann and contributors.
|
||||||
|
|
||||||
|
Testing Symfony\Bridge\PhpUnit\Tests\FailTests\ExpectDeprecationTraitTestFail
|
||||||
|
FF 2 / 2 (100%)
|
||||||
|
|
||||||
|
Time: %s, Memory: %s
|
||||||
|
|
||||||
|
There were 2 failures:
|
||||||
|
|
||||||
|
1) Symfony\Bridge\PhpUnit\Tests\FailTests\ExpectDeprecationTraitTestFail::testOne
|
||||||
|
Failed asserting that string matches format description.
|
||||||
|
--- Expected
|
||||||
|
+++ Actual
|
||||||
|
@@ @@
|
||||||
|
@expectedDeprecation:
|
||||||
|
-%A foo
|
||||||
|
+ bar
|
||||||
|
|
||||||
|
2) Symfony\Bridge\PhpUnit\Tests\FailTests\ExpectDeprecationTraitTestFail::testOneInIsolation
|
||||||
|
Failed asserting that string matches format description.
|
||||||
|
--- Expected
|
||||||
|
+++ Actual
|
||||||
|
@@ @@
|
||||||
|
@expectedDeprecation:
|
||||||
|
-%A foo
|
||||||
|
+ bar
|
||||||
|
|
||||||
|
FAILURES!
|
||||||
|
Tests: 2, Assertions: 2, Failures: 2.
|
@ -134,6 +134,7 @@ $defaultEnvs = [
|
|||||||
'COMPOSER' => 'composer.json',
|
'COMPOSER' => 'composer.json',
|
||||||
'COMPOSER_VENDOR_DIR' => 'vendor',
|
'COMPOSER_VENDOR_DIR' => 'vendor',
|
||||||
'COMPOSER_BIN_DIR' => 'bin',
|
'COMPOSER_BIN_DIR' => 'bin',
|
||||||
|
'SYMFONY_SIMPLE_PHPUNIT_BIN_DIR' => __DIR__,
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($defaultEnvs as $envName => $envValue) {
|
foreach ($defaultEnvs as $envName => $envValue) {
|
||||||
|
Reference in New Issue
Block a user