Skip to content

[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

Merged
merged 1 commit into from
May 8, 2017
Merged

[FrameworkBundle] KernelTestCase: allow to provide the kernel class with a var #22668

merged 1 commit into from
May 8, 2017

Conversation

ogizanagi
Copy link
Contributor

@ogizanagi ogizanagi commented May 8, 2017

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:

<?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.

@@ -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));
Copy link
Member

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.

Copy link
Contributor Author

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.

@fabpot
Copy link
Member

fabpot commented May 8, 2017

Thank you @ogizanagi.

@fabpot fabpot merged commit 4f68912 into symfony:master May 8, 2017
fabpot added a commit that referenced this pull request May 8, 2017
… 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
fabpot added a commit to symfony/recipes that referenced this pull request May 8, 2017
…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
@fabpot
Copy link
Member

fabpot commented May 8, 2017

What about deprecating KERNEL_DIR in 3.4?

@ogizanagi ogizanagi deleted the feature/3.3/fwb/kernel_test_case_kernel_class branch May 8, 2017 14:58
@ogizanagi
Copy link
Contributor Author

ogizanagi commented May 8, 2017

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 WebTestCase for instance).
Actually, it'll deprecate the entire getKernelClass() previous implementation, so not setting KERNEL_CLASS will throw the deprecation in 3.4, and throw an exception on 4.0.

@ogizanagi
Copy link
Contributor Author

I've opened #22675 about the deprecation in 3.4.

@fabpot fabpot mentioned this pull request May 17, 2017
fabpot added a commit that referenced this pull request Jun 9, 2017
…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
symfony-splitter pushed a commit to symfony/framework-bundle that referenced this pull request Jun 9, 2017
…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
ybelenko added a commit to ybelenko/openapi-generator that referenced this pull request May 8, 2020
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
wing328 pushed a commit to OpenAPITools/openapi-generator that referenced this pull request May 29, 2020
* 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
markovlatkovic pushed a commit to markovlatkovic/recipes that referenced this pull request May 24, 2024
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants