[Bridge/PhpUnit] rename SetUpTearDownTrait to ForwardCompatTrait

This commit is contained in:
Nicolas Grekas 2019-07-31 23:28:46 +02:00
parent e11e4a54fe
commit 2671359bac
4 changed files with 168 additions and 80 deletions

View File

@ -0,0 +1,28 @@
<?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;
use PHPUnit\Framework\TestCase;
// A trait to provide forward compatibility with newest PHPUnit versions
if (method_exists(\ReflectionMethod::class, 'hasReturnType') && (new \ReflectionMethod(TestCase::class, 'tearDown'))->hasReturnType()) {
trait ForwardCompatTrait
{
use Legacy\ForwardCompatTraitForV8;
}
} else {
trait ForwardCompatTrait
{
use Legacy\ForwardCompatTraitForV5;
}
}

View File

@ -0,0 +1,82 @@
<?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 ForwardCompatTraitForV5
{
/**
* @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();
}
/**
* @return void
*/
private static function doSetUpBeforeClass()
{
parent::setUpBeforeClass();
}
/**
* @return void
*/
private static function doTearDownAfterClass()
{
parent::tearDownAfterClass();
}
/**
* @return void
*/
private function doSetUp()
{
parent::setUp();
}
/**
* @return void
*/
private function doTearDown()
{
parent::tearDown();
}
}

View File

@ -0,0 +1,58 @@
<?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 ForwardCompatTraitForV8
{
public static function setUpBeforeClass(): void
{
self::doSetUpBeforeClass();
}
public static function tearDownAfterClass(): void
{
self::doTearDownAfterClass();
}
protected function setUp(): void
{
self::doSetUp();
}
protected function tearDown(): void
{
self::doTearDown();
}
private static function doSetUpBeforeClass(): void
{
parent::setUpBeforeClass();
}
private static function doTearDownAfterClass(): void
{
parent::tearDownAfterClass();
}
private function doSetUp(): void
{
parent::setUp();
}
private function doTearDown(): void
{
parent::tearDown();
}
}

View File

@ -1,80 +0,0 @@
<?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;
use PHPUnit\Framework\TestCase;
// Auto-adapt to PHPUnit 8 that added a `void` return-type to the setUp/tearDown methods
if (method_exists(\ReflectionMethod::class, 'hasReturnType') && (new \ReflectionMethod(TestCase::class, 'tearDown'))->hasReturnType()) {
eval('
namespace Symfony\Bridge\PhpUnit;
trait SetUpTearDownTrait
{
private function doSetUp(): void
{
parent::setUp();
}
private function doTearDown(): void
{
parent::tearDown();
}
protected function setUp(): void
{
$this->doSetUp();
}
protected function tearDown(): void
{
$this->doTearDown();
}
}
');
} else {
trait SetUpTearDownTrait
{
/**
* @return void
*/
private function doSetUp()
{
parent::setUp();
}
/**
* @return void
*/
private function doTearDown()
{
parent::tearDown();
}
/**
* @return void
*/
protected function setUp()
{
$this->doSetUp();
}
/**
* @return void
*/
protected function tearDown()
{
$this->doTearDown();
}
}
}