Skip to content

[PhpUnitBridge] Restore SetUpTearDownTraitForV5 #39487

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
Dec 14, 2020
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions UPGRADE-5.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ HttpKernel

* Marked the class `Symfony\Component\HttpKernel\EventListener\DebugHandlersListener` as internal

PhpunitBridge
-------------

* Deprecated the `SetUpTearDownTrait` trait, use original methods with "void" return typehint.

Security
--------

Expand Down
1 change: 1 addition & 0 deletions UPGRADE-6.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ PhpUnitBridge
-------------

* Removed support for `@expectedDeprecation` annotations, use the `ExpectDeprecationTrait::expectDeprecation()` method instead.
* Removed the `SetUpTearDownTrait` trait, use original methods with "void" return typehint.

PropertyAccess
--------------
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Bridge/PhpUnit/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ CHANGELOG

* bumped the minimum PHP version to 7.1.3
* bumped the minimum PHPUnit version to 7.5
* deprecated the `SetUpTearDownTrait` trait, use original methods with "void" return typehint.

5.1.0
-----
Expand Down
70 changes: 70 additions & 0 deletions src/Symfony/Bridge/PhpUnit/Legacy/SetUpTearDownTraitForV7.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?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\Legacy;

/**
* @internal
*/
trait SetUpTearDownTraitForV7
{
/**
* @return void
*/
public static function setUpBeforeClass()
{
self::doSetUpBeforeClass();
}

/**
* @return void
*/
public static function tearDownAfterClass()
{
self::doTearDownAfterClass();
}

/**
* @return void
*/
protected function setUp()
{
self::doSetUp();
}

/**
* @return void
*/
protected function tearDown()
{
self::doTearDown();
}

private static function doSetUpBeforeClass()
{
parent::setUpBeforeClass();
}

private static function doTearDownAfterClass()
{
parent::tearDownAfterClass();
}

private function doSetUp()
{
parent::setUp();
}

private function doTearDown()
{
parent::tearDown();
}
}
6 changes: 4 additions & 2 deletions src/Symfony/Bridge/PhpUnit/SetUpTearDownTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@

use PHPUnit\Framework\TestCase;

trigger_deprecation('symfony/phpunit-bridge', '5.3', 'The "%s" trait is deprecated, use original methods with "void" return typehint.', SetUpTearDownTrait::class);

// A trait to provide forward compatibility with newest PHPUnit versions
$r = new \ReflectionClass(TestCase::class);
if (\PHP_VERSION_ID < 70000 || !$r->getMethod('setUp')->hasReturnType()) {
if (!$r->getMethod('setUp')->hasReturnType()) {
trait SetUpTearDownTrait
{
use Legacy\SetUpTearDownTraitForV5;
use Legacy\SetUpTearDownTraitForV7;
}
} else {
trait SetUpTearDownTrait
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bridge/PhpUnit/Tests/CoverageListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function test()

exec('type phpdbg 2> /dev/null', $output, $returnCode);

if (\PHP_VERSION_ID >= 70000 && 0 === $returnCode) {
if (0 === $returnCode) {
$php = 'phpdbg -qrr';
} else {
exec('php --ri xdebug -d zend_extension=xdebug.so 2> /dev/null', $output, $returnCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\DeprecationErrorHandler;
use Symfony\Bridge\PhpUnit\DeprecationErrorHandler\Deprecation;
use Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerForV5;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
use Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerForV7;

class DeprecationTest extends TestCase
{
use SetUpTearDownTrait;

private static $vendorDir;
private static $prefixDirsPsr4;

Expand Down Expand Up @@ -164,7 +161,7 @@ public function providerGetTypeDetectsSelf()
'triggering_file' => 'dummy_vendor_path',
'files_stack' => [],
]),
SymfonyTestsListenerForV5::class,
SymfonyTestsListenerForV7::class,
'',
],
];
Expand Down Expand Up @@ -208,7 +205,7 @@ public function providerGetTypeUsesRightTrace()
$vendorDir.'/myfakevendor/myfakepackage1/MyFakeFile2.php',
],
]),
[['function' => 'myfunc1'], ['class' => SymfonyTestsListenerForV5::class, 'method' => 'mymethod']],
[['function' => 'myfunc1'], ['class' => SymfonyTestsListenerForV7::class, 'method' => 'mymethod']],
],
'serialized_stack_files_from_various_packages' => [
Deprecation::TYPE_INDIRECT,
Expand All @@ -221,7 +218,7 @@ public function providerGetTypeUsesRightTrace()
$vendorDir.'/myfakevendor/myfakepackage2/MyFakeFile.php',
],
]),
[['function' => 'myfunc1'], ['class' => SymfonyTestsListenerForV5::class, 'method' => 'mymethod']],
[['function' => 'myfunc1'], ['class' => SymfonyTestsListenerForV7::class, 'method' => 'mymethod']],
],
];
}
Expand Down Expand Up @@ -261,7 +258,7 @@ private static function removeDir($dir)
rmdir($dir);
}

private static function doSetupBeforeClass()
public static function setupBeforeClass(): void
{
foreach (get_declared_classes() as $class) {
if ('C' === $class[0] && 0 === strpos($class, 'ComposerAutoloaderInit')) {
Expand All @@ -281,7 +278,7 @@ private static function doSetupBeforeClass()
}
}

private static function doTearDownAfterClass()
public static function tearDownAfterClass(): void
{
foreach (self::$prefixDirsPsr4 as [$prop, $loader, $prefixDirsPsr4]) {
$prop->setValue($loader, $prefixDirsPsr4);
Expand Down