-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] KernelTestCase: allow to provide the kernel class with a var #22668
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
[FrameworkBundle] KernelTestCase: allow to provide the kernel class with a var #22668
Conversation
@@ -106,6 +106,14 @@ private static function getPhpUnitCliConfigArgument() | |||
*/ | |||
protected static function getKernelClass() | |||
{ | |||
if (isset($_SERVER['KERNEL_CLASS'])) { | |||
if (!class_exists($class = $_SERVER['KERNEL_CLASS'])) { | |||
throw new \RuntimeException(sprintf('Class "%s" not found or cannot be autoloaded. Please check the KERNEL_CLASS value in your phpunit.xml matches the fully-qualified class name of your Kernel or override the WebTestCase::createKernel() method.', $class)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the use of "Please" in error messages. I'm proposing changing this:
Class "%s" not found or cannot be autoloaded. Please check the KERNEL_CLASS
value in your phpunit.xml matches the fully-qualified class name of your Kernel
or override the WebTestCase::createKernel() method.
to this:
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 WebTestCase::createKernel() method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated. Thank you :)
I also updated the WebTestCase::createKernel()
part to use static::class
instead of WebTestCase
, so the message will indicate the final class. Anyway it was wrong, as we're in KernelTestCase
, so I might propose a fix on lower branches too for the other exception a few lines below.
Thank you @ogizanagi. |
… kernel class with a var (ogizanagi) This PR was merged into the 3.3-dev branch. Discussion ---------- [FrameworkBundle] KernelTestCase: allow to provide the kernel class with a var | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | no | New feature? | yes, but must-have for the new project structure when using flex | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #22661 | License | MIT | Doc PR | todo in https://symfony.com/doc/current/testing.html#your-first-functional-test So, when using flex, the new `phpunit.xml.dist` will be: ```diff <?xml version="1.0" encoding="UTF-8"?> <!-- https://phpunit.de/manual/current/en/appendixes.configuration.html --> <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.1/phpunit.xsd" backupGlobals="false" colors="true" bootstrap="vendor/autoload.php" > <php> <ini name="error_reporting" value="-1" /> - <server name="KERNEL_DIR" value="etc/" /> + <server name="KERNEL_CLASS" value="App\Kernel" /> </php> <testsuites> <testsuite name="Project Test Suite"> <directory>tests/</directory> </testsuite> </testsuites> </phpunit> ``` As it may cause issues when refactoring, I added a `class_exists` check with an appropriate exception to indicate the class is either not found or not autoloadable. Commits ------- 4f68912 [FrameworkBundle] KernelTestCase: allow to provide the kernel class with a var
…izanagi) This PR was merged into the master branch. Discussion ---------- [PhpUnit] Use the new KERNEL_CLASS var for KernelTestCase Once symfony/symfony#22668 is merged. Commits ------- c32f3e5 [PhpUnit] Use the new KERNEL_CLASS var for KernelTestCase
What about deprecating |
I agree about deprecating it in 3.4. I don't see any good reason to keep it appart from the ability to use a non-autoloadable kernel (still doable if needed by overriding the method, as done by the SecurityBundle |
I've opened #22675 about the deprecation in 3.4. |
…KERNEL_CLASS (ogizanagi) This PR was merged into the 3.4 branch. Discussion ---------- [FrameworkBundle] KernelTestCase: deprecate not using KERNEL_CLASS | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | #22668 (comment) | License | MIT | Doc PR | N/A Commits ------- d102fc0 [FrameworkBundle] KernelTestCase: deprecate not using KERNEL_CLASS
…KERNEL_CLASS (ogizanagi) This PR was merged into the 3.4 branch. Discussion ---------- [FrameworkBundle] KernelTestCase: deprecate not using KERNEL_CLASS | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | symfony/symfony#22668 (comment) | License | MIT | Doc PR | N/A Commits ------- d102fc08e4 [FrameworkBundle] KernelTestCase: deprecate not using KERNEL_CLASS
PHPUnit 8.x version required PHP ^7.2, so I'm setting 7.x version to support PHP 7.1. There is new way to specify Kernel class, related PR: symfony/symfony#22668
* Set PHP 7.1.3 required version I've tried to specify ^7.0 version at first, but main package which is symfony/framework-bundle@v4.4.8 requires PHP ^7.1.3. * Bump Symfony FrameworkBundle to ^4.4.8 Current Symfony Framework stable version is v5.0.8, but I guess it requires significant codebase upgrade, so I've sticked with 4.4.8 which shouldn't cause any breaking changes. Old requirement was ^3.3|^4.1 which compatible with 4.4.8. * Bump PHPUnit version to ^7.0 PHPUnit 8.x version required PHP ^7.2, so I'm setting 7.x version to support PHP 7.1. There is new way to specify Kernel class, related PR: symfony/symfony#22668 * Bump PHP CS Fixer version to ^2.16.3 Configuration and all renamed rules fixed. Config file renamed to .php_cs.dist as recommended in migration guide. Migration guide from 1.x to 2.x: https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/UPGRADE.md#config-file * Remove PHP_CodeSniffer package Second linter doesn't make sense. I think Symfony user would prefer PHP CS Fixer over PHP_CodeSniffer because first one maintained by Symfony members. * Remove satooshi/php-coveralls package from Composer This package is abandoned and Coveralls recommends to install it directly in Travis-CI task script. * Update Travic-CI config I've changed test versions to PHP 7.1.3 and 7.2. PHPUnit generates coverage report in report/logs/clover.xml file. Then PHP CS Fixer runs with --dry-run option to not override anything just to show coding style errors. * Add basic Coveralls config This is basic recommended config for a PHP based project. * Add symfony/yaml package This package was part of satooshi/php-coveralls, now it should be defined as dev dependency. * Do not commit composer.lock I think committed composer.lock can cause CI errors while tests on fresh installs are better. * Remove confusing Ruby comment
…izanagi) This PR was merged into the master branch. Discussion ---------- [PhpUnit] Use the new KERNEL_CLASS var for KernelTestCase Once symfony/symfony#22668 is merged. Commits ------- c32f3e5 [PhpUnit] Use the new KERNEL_CLASS var for KernelTestCase
So, when using flex, the new
phpunit.xml.dist
will be:As it may cause issues when refactoring, I added a
class_exists
check with an appropriate exception to indicate the class is either not found or not autoloadable.