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

Fix KernelTestCase compatibility for PhpUnit 8 (bis) #30124

Merged
merged 1 commit into from Feb 12, 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
@@ -0,0 +1,45 @@
<?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\Bundle\FrameworkBundle\Test;

use PHPUnit\Framework\TestCase;

// Auto-adapt to PHPUnit 8 that added a `void` return-type to the tearDown method

if (method_exists(\ReflectionMethod::class, 'hasReturnType') && (new \ReflectionMethod(TestCase::class, 'tearDown'))->hasReturnType()) {
eval('
/**
* @internal
*/
trait KernelShutdownOnTearDownTrait
{
protected function tearDown(): void
{
static::ensureKernelShutdown();
}
}
');
xabbuh marked this conversation as resolved.
Show resolved Hide resolved
} else {
/**
* @internal
*/
trait KernelShutdownOnTearDownTrait
{
/**
* @return void
*/
protected function tearDown()
{
static::ensureKernelShutdown();
}
}
}
6 changes: 3 additions & 3 deletions src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php
Expand Up @@ -23,6 +23,8 @@
*/
abstract class KernelTestCase extends TestCase
{
use KernelShutdownOnTearDownTrait;

protected static $class;

/**
Expand Down Expand Up @@ -208,9 +210,7 @@ protected static function createKernel(array $options = [])
}

/**
* @after
*
* Shuts the kernel down if it was used in the test.
* Shuts the kernel down if it was used in the test - called by the tearDown method by default.
*/
protected static function ensureKernelShutdown()
{
Expand Down