compatibility with phpunit8

This commit is contained in:
Massimiliano Arione 2019-03-07 11:36:06 +01:00
parent e9c8e19f46
commit 5ef254fa65
No known key found for this signature in database
GPG Key ID: A2BD043E5D80E008
5 changed files with 175 additions and 5 deletions

View File

@ -20,12 +20,14 @@ use Symfony\Component\Form\Forms;
*/ */
abstract class FormIntegrationTestCase extends TestCase abstract class FormIntegrationTestCase extends TestCase
{ {
use TestCaseSetUpTearDownTrait;
/** /**
* @var FormFactoryInterface * @var FormFactoryInterface
*/ */
protected $factory; protected $factory;
protected function setUp() private function doSetUp()
{ {
$this->factory = Forms::createFormFactoryBuilder() $this->factory = Forms::createFormFactoryBuilder()
->addExtensions($this->getExtensions()) ->addExtensions($this->getExtensions())

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\Component\Form\Test;
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\Component\Form\Test;
/**
* @internal
*/
trait TestCaseSetUpTearDownTrait
{
private function doSetUp(): void
{
}
private function doTearDown(): void
{
}
protected function setUp(): void
{
$this->doSetUp();
}
protected function tearDown(): void
{
$this->doTearDown();
}
}
');
} else {
/**
* @internal
*/
trait TestCaseSetUpTearDownTrait
{
/**
* @return void
*/
private function doSetUp()
{
}
/**
* @return void
*/
private function doTearDown()
{
}
/**
* @return void
*/
protected function setUp()
{
$this->doSetUp();
}
/**
* @return void
*/
protected function tearDown()
{
$this->doTearDown();
}
}
}

View File

@ -17,6 +17,8 @@ use Symfony\Component\Form\Test\Traits\ValidatorExtensionTrait;
abstract class TypeTestCase extends FormIntegrationTestCase abstract class TypeTestCase extends FormIntegrationTestCase
{ {
use TestCaseSetUpTearDownTrait;
/** /**
* @var FormBuilder * @var FormBuilder
*/ */
@ -27,7 +29,7 @@ abstract class TypeTestCase extends FormIntegrationTestCase
*/ */
protected $dispatcher; protected $dispatcher;
protected function setUp() private function doSetUp()
{ {
parent::setUp(); parent::setUp();
@ -35,7 +37,7 @@ abstract class TypeTestCase extends FormIntegrationTestCase
$this->builder = new FormBuilder('', null, $this->dispatcher, $this->factory); $this->builder = new FormBuilder('', null, $this->dispatcher, $this->factory);
} }
protected function tearDown() private function doTearDown()
{ {
if (\in_array(ValidatorExtensionTrait::class, class_uses($this))) { if (\in_array(ValidatorExtensionTrait::class, class_uses($this))) {
$this->validator = null; $this->validator = null;

View File

@ -29,6 +29,8 @@ use Symfony\Component\Validator\Mapping\PropertyMetadata;
*/ */
abstract class ConstraintValidatorTestCase extends TestCase abstract class ConstraintValidatorTestCase extends TestCase
{ {
use TestCaseSetUpTearDownTrait;
/** /**
* @var ExecutionContextInterface * @var ExecutionContextInterface
*/ */
@ -48,7 +50,7 @@ abstract class ConstraintValidatorTestCase extends TestCase
protected $constraint; protected $constraint;
protected $defaultTimezone; protected $defaultTimezone;
protected function setUp() private function doSetUp()
{ {
$this->group = 'MyGroup'; $this->group = 'MyGroup';
$this->metadata = null; $this->metadata = null;
@ -70,7 +72,7 @@ abstract class ConstraintValidatorTestCase extends TestCase
$this->setDefaultTimezone('UTC'); $this->setDefaultTimezone('UTC');
} }
protected function tearDown() private function doTearDown()
{ {
$this->restoreDefaultTimezone(); $this->restoreDefaultTimezone();
} }

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\Component\Validator\Test;
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\Component\Validator\Test;
/**
* @internal
*/
trait TestCaseSetUpTearDownTrait
{
private function doSetUp(): void
{
}
private function doTearDown(): void
{
}
protected function setUp(): void
{
$this->doSetUp();
}
protected function tearDown(): void
{
$this->doTearDown();
}
}
');
} else {
/**
* @internal
*/
trait TestCaseSetUpTearDownTrait
{
/**
* @return void
*/
private function doSetUp()
{
}
/**
* @return void
*/
private function doTearDown()
{
}
/**
* @return void
*/
protected function setUp()
{
$this->doSetUp();
}
/**
* @return void
*/
protected function tearDown()
{
$this->doTearDown();
}
}
}