Skip to content
Permalink
Browse files

bug #30474 compatibility with phpunit8 (garak)

This PR was merged into the 3.4 branch.

Discussion
----------

compatibility with phpunit8

This basically adds the same phpunit8 compatibility layer added in #30084 (but for other test classes)
See also discussion in #30071

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #30071
| License       | MIT
| Doc PR        | none

Commits
-------

5ef254f compatibility with phpunit8
  • Loading branch information...
fabpot committed Mar 9, 2019
2 parents cf728a5 + 5ef254f commit d583f803190a3001f3dbc38ce888cdb1d3c16182
@@ -20,12 +20,14 @@
*/
abstract class FormIntegrationTestCase extends TestCase
{
use TestCaseSetUpTearDownTrait;
/**
* @var FormFactoryInterface
*/
protected $factory;
protected function setUp()
private function doSetUp()
{
$this->factory = Forms::createFormFactoryBuilder()
->addExtensions($this->getExtensions())
@@ -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();
}
}
}
@@ -17,6 +17,8 @@
abstract class TypeTestCase extends FormIntegrationTestCase
{
use TestCaseSetUpTearDownTrait;
/**
* @var FormBuilder
*/
@@ -27,15 +29,15 @@ abstract class TypeTestCase extends FormIntegrationTestCase
*/
protected $dispatcher;
protected function setUp()
private function doSetUp()
{
parent::setUp();
$this->dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
$this->builder = new FormBuilder('', null, $this->dispatcher, $this->factory);
}
protected function tearDown()
private function doTearDown()
{
if (\in_array(ValidatorExtensionTrait::class, class_uses($this))) {
$this->validator = null;
@@ -29,6 +29,8 @@
*/
abstract class ConstraintValidatorTestCase extends TestCase
{
use TestCaseSetUpTearDownTrait;
/**
* @var ExecutionContextInterface
*/
@@ -48,7 +50,7 @@ abstract class ConstraintValidatorTestCase extends TestCase
protected $constraint;
protected $defaultTimezone;
protected function setUp()
private function doSetUp()
{
$this->group = 'MyGroup';
$this->metadata = null;
@@ -70,7 +72,7 @@ protected function setUp()
$this->setDefaultTimezone('UTC');
}
protected function tearDown()
private function doTearDown()
{
$this->restoreDefaultTimezone();
}
@@ -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();
}
}
}

0 comments on commit d583f80

Please sign in to comment.
You can’t perform that action at this time.