Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6d28c43

Browse files
committed
[FrameworkBundle] Remove KernelTestCase deprecated code
1 parent f309c09 commit 6d28c43

File tree

2 files changed

+7
-109
lines changed

2 files changed

+7
-109
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ CHANGELOG
1717
* Removed `ConstraintValidatorFactory`
1818
* Removed class parameters related to routing
1919
* Removed absolute template paths support in the template name parser
20+
* Removed support of the `KERNEL_DIR` environment variable with `KernelTestCase::getKernelClass()`.
21+
* Removed the `KernelTestCase::getPhpUnitXmlDir()` and `KernelTestCase::getPhpUnitCliConfigArgument()` methods.
2022

2123
3.4.0
2224
-----

src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php

Lines changed: 5 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\DependencyInjection\ResettableContainerInterface;
16-
use Symfony\Component\Finder\Finder;
1716
use Symfony\Component\HttpKernel\KernelInterface;
1817

1918
/**
@@ -31,124 +30,21 @@ abstract class KernelTestCase extends TestCase
3130
protected static $kernel;
3231

3332
/**
34-
* Finds the directory where the phpunit.xml(.dist) is stored.
35-
*
36-
* If you run tests with the PHPUnit CLI tool, everything will work as expected.
37-
* If not, override this method in your test classes.
38-
*
39-
* @return string The directory where phpunit.xml(.dist) is stored
40-
*
41-
* @throws \RuntimeException
42-
*
43-
* @deprecated since 3.4 and will be removed in 4.0.
44-
*/
45-
protected static function getPhpUnitXmlDir()
46-
{
47-
@trigger_error(sprintf('The %s() method is deprecated since 3.4 and will be removed in 4.0.', __METHOD__), E_USER_DEPRECATED);
48-
49-
if (!isset($_SERVER['argv']) || false === strpos($_SERVER['argv'][0], 'phpunit')) {
50-
throw new \RuntimeException('You must override the KernelTestCase::createKernel() method.');
51-
}
52-
53-
$dir = static::getPhpUnitCliConfigArgument();
54-
if (null === $dir &&
55-
(is_file(getcwd().DIRECTORY_SEPARATOR.'phpunit.xml') ||
56-
is_file(getcwd().DIRECTORY_SEPARATOR.'phpunit.xml.dist'))) {
57-
$dir = getcwd();
58-
}
59-
60-
// Can't continue
61-
if (null === $dir) {
62-
throw new \RuntimeException('Unable to guess the Kernel directory.');
63-
}
64-
65-
if (!is_dir($dir)) {
66-
$dir = dirname($dir);
67-
}
68-
69-
return $dir;
70-
}
71-
72-
/**
73-
* Finds the value of the CLI configuration option.
74-
*
75-
* PHPUnit will use the last configuration argument on the command line, so this only returns
76-
* the last configuration argument.
77-
*
78-
* @return string The value of the PHPUnit CLI configuration option
79-
*
80-
* @deprecated since 3.4 and will be removed in 4.0.
81-
*/
82-
private static function getPhpUnitCliConfigArgument()
83-
{
84-
@trigger_error(sprintf('The %s() method is deprecated since 3.4 and will be removed in 4.0.', __METHOD__), E_USER_DEPRECATED);
85-
86-
$dir = null;
87-
$reversedArgs = array_reverse($_SERVER['argv']);
88-
foreach ($reversedArgs as $argIndex => $testArg) {
89-
if (preg_match('/^-[^ \-]*c$/', $testArg) || $testArg === '--configuration') {
90-
$dir = realpath($reversedArgs[$argIndex - 1]);
91-
break;
92-
} elseif (0 === strpos($testArg, '--configuration=')) {
93-
$argPath = substr($testArg, strlen('--configuration='));
94-
$dir = realpath($argPath);
95-
break;
96-
} elseif (0 === strpos($testArg, '-c')) {
97-
$argPath = substr($testArg, strlen('-c'));
98-
$dir = realpath($argPath);
99-
break;
100-
}
101-
}
102-
103-
return $dir;
104-
}
105-
106-
/**
107-
* Attempts to guess the kernel location.
108-
*
109-
* When the Kernel is located, the file is required.
110-
*
11133
* @return string The Kernel class name
11234
*
11335
* @throws \RuntimeException
36+
* @throws \LogicException
11437
*/
11538
protected static function getKernelClass()
11639
{
117-
if (isset($_SERVER['KERNEL_CLASS'])) {
118-
if (!class_exists($class = $_SERVER['KERNEL_CLASS'])) {
119-
throw new \RuntimeException(sprintf('Class "%s" doesn\'t exist or cannot be autoloaded. Check that the KERNEL_CLASS value in phpunit.xml matches the fully-qualified class name of your Kernel or override the %s::createKernel() method.', $class, static::class));
120-
}
121-
122-
return $class;
123-
} else {
124-
@trigger_error(sprintf('Using the KERNEL_DIR environment variable or the automatic guessing based on the phpunit.xml / phpunit.xml.dist file location is deprecated since 3.4. Set the KERNEL_CLASS environment variable to the fully-qualified class name of your Kernel instead. Not setting the KERNEL_CLASS environment variable will throw an exception on 4.0 unless you override the %1$::createKernel() or %1$::getKernelClass() method.', static::class), E_USER_DEPRECATED);
125-
}
126-
127-
if (isset($_SERVER['KERNEL_DIR'])) {
128-
$dir = $_SERVER['KERNEL_DIR'];
129-
130-
if (!is_dir($dir)) {
131-
$phpUnitDir = static::getPhpUnitXmlDir();
132-
if (is_dir("$phpUnitDir/$dir")) {
133-
$dir = "$phpUnitDir/$dir";
134-
}
135-
}
136-
} else {
137-
$dir = static::getPhpUnitXmlDir();
40+
if (!isset($_SERVER['KERNEL_CLASS'])) {
41+
throw new \LogicException(sprintf('You must set the KERNEL_CLASS environment variable to the fully-qualified class name of your Kernel in phpunit.xml / phpunit.xml.dist or override the %1$::createKernel() or %1$::getKernelClass() method.', static::class));
13842
}
13943

140-
$finder = new Finder();
141-
$finder->name('*Kernel.php')->depth(0)->in($dir);
142-
$results = iterator_to_array($finder);
143-
if (!count($results)) {
144-
throw new \RuntimeException('Either set KERNEL_DIR in your phpunit.xml according to https://symfony.com/doc/current/book/testing.html#your-first-functional-test or override the WebTestCase::createKernel() method.');
44+
if (!class_exists($class = $_SERVER['KERNEL_CLASS'])) {
45+
throw new \RuntimeException(sprintf('Class "%s" doesn\'t exist or cannot be autoloaded. Check that the KERNEL_CLASS value in phpunit.xml matches the fully-qualified class name of your Kernel or override the %s::createKernel() method.', $class, static::class));
14546
}
14647

147-
$file = current($results);
148-
$class = $file->getBasename('.php');
149-
150-
require_once $file;
151-
15248
return $class;
15349
}
15450

0 commit comments

Comments
 (0)