Skip to content
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

compatibility with phpunit8 #30474

Merged
merged 1 commit into from Mar 9, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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())
Expand Down
82 changes: 82 additions & 0 deletions src/Symfony/Component/Form/Test/TestCaseSetUpTearDownTrait.php
@@ -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
xabbuh marked this conversation as resolved.
Show resolved Hide resolved
*/
private function doSetUp()
{
}

/**
* @return void
*/
private function doTearDown()
{
}

/**
* @return void
*/
protected function setUp()
{
$this->doSetUp();
}

/**
* @return void
*/
protected function tearDown()
{
$this->doTearDown();
}
}
}
6 changes: 4 additions & 2 deletions src/Symfony/Component/Form/Test/TypeTestCase.php
Expand Up @@ -17,6 +17,8 @@

abstract class TypeTestCase extends FormIntegrationTestCase
{
use TestCaseSetUpTearDownTrait;

/**
* @var FormBuilder
*/
Expand All @@ -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;
Expand Down
Expand Up @@ -29,6 +29,8 @@
*/
abstract class ConstraintValidatorTestCase extends TestCase
{
use TestCaseSetUpTearDownTrait;

/**
* @var ExecutionContextInterface
*/
Expand All @@ -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;
Expand All @@ -70,7 +72,7 @@ protected function setUp()
$this->setDefaultTimezone('UTC');
}

protected function tearDown()
private function doTearDown()
{
$this->restoreDefaultTimezone();
}
Expand Down
@@ -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();
}
}
}