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
KernelTestCase no longer works with PhpUnit 6.0+ #21534
Comments
The new namespace wasn't added until phpunit 5.4, not 4.8, as you asserted (check the changelog link you referenced). |
You're right, I got the version numbers mixed up. |
I'm not sure if this should be a new issue, but the issue also occurs with Symfony 2.8. |
I closed the PR since it won't be possible to merge it. class PHPUnit_Framework_TestCase extends \PHPUnit\Framework\TestCase
{
} |
The polyfill seems the way to go for now, but methinks it should go in the PHPUnit bridge, not in the general polyfill packages as it's only an issue for Symfony's own KernelTestCase and WebTestCase base classes. Given the issues that it's causing (full crash on every single testcase) my recommendation would be to add a |
Come to think of it, that polyfill would horribly break many projects. A regular polyfill adds missing functionality without breaking anything, but in this case many projects might consciously stay on 5.x for some time and thus would explicitly break on the suggested solution, or get stuck with an old Symfony version. I think the only really transparent solution is changing
Just tried it out and this makes my local tests pass both on 5.7 and 6.0. Then again, perhaps it would be easier on Symfony and other frameworks if @sebastianbergmann either added this alias to 6.0 until 6.1 comes out, and marks 6.1 as conflicting with |
@curry684 All you need to do is "polyfill" (by creating an alias) the Something like the following could be added to the <?php
if (!class_exists('\PHPUnit_Framework_TestCase') && class_exists('\PHPUnit\Framework\TestCase')) {
class_alias('\PHPUnit\Framework\TestCase', '\PHPUnit_Framework_TestCase');
} @nicolas-grekas Is this something that is appropriate for the |
@robfrawley if you do it in the polyfill it is aliased for every test case in a project using the polyfill, not just those using Global polyfilling is in this case a carpet bomb approach while we're only trying to patch Admittedly the |
Solid point. Not positive what the best route is to proceed... |
Re: #21534 (comment) I made the conscious decision to not provide aliases as they only delay the problem. It is your right, of course, to make the conscious decision to add aliases in your project. |
Looking at your I have just released PHPUnit 4.8.35 to which I have backported the forward compatibility layer for PHPUnit 6 from PHPUnit 5 so that |
I opened a new PR since the new namespaces now exists in PHPUnit 4.8. |
That PR isn't enough as you then still need the proper All in all I would recommend not making PRs until a clear path on this is chosen by the powers that be - it's not a trivial minor issue so at least @nicolas-grekas should have a say in this as he likely has the best insight in impact. |
@curry684 creating a class alias with the PHPUnit class name has already been rejected, for the reason given by you above (it would also break feature detection for code checking the availability of the class btw). As the forward compatibility layer is now available in 4.8 and 5.4+, we can switch to it IMO |
Well, making sure that the PhpUnitBridge doesn't use the cache, but reinstalls PHPUnit instead will probably make the tests green. |
I was already trying to tackle this problem for the bridge here: #21221 |
ok, so what is the solution to this? I'm using symfony 3.1 for a project, PHPUnit 6.0.6 and the tests won't even start, i.e. my CI fails every build, which won't let me deploy... |
@pculka For the moment, you can stick with PHPUnit 5.x. |
On my current project I've put the following in my PHPUnit bootstrap file after the autoloader until it's resolved on the Symfony and/or PHPUnit levels, with
I'm only using this because I want the bundle to support only PHPUnit 6 eventually. In regular projects I'm sticking with 5.x for the time being as @xabbuh suggests. |
There are other polyfills required, like those ...
|
Not for Symfony as the conflict only arises from KernelTestCase extending PHPUnit_Framework_TestCase. |
Those are needed for the PHPUnit bridge, in fact |
Ok, |
Even if PHPUnit 7 were out and our base test case classes were not compatible with PHPUnit 7 yet, users would still be able to use it if they did not make use of our base classes. |
Technically it is not sure yet and since PHPUnit is optionally tooling it should updated once the changes in 7.0 are clear. There are good chances that there might not be any issues. You will in any case immediately notice if there are issues with your testsuite. |
This PR was squashed before being merged into the 2.7 branch (closes #21564). Discussion ---------- Update to PHPUnit namespaces | Q | A | ------------- | --- | Branch? | 2.7+ | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #21534 | License | MIT | Doc PR | - Replaces #21540 @nicolas-grekas Is the update of the cache-id like this sufficient? Do we maybe have to specifiy 4.8.35 in simple-phpunit? Commits ------- ddd2dff Update to PHPUnit namespaces
This also occurs with Silex 2 |
I'm facing: |
I tried with PHPUnit 5.7/Symfony 2.8 and PhpUnit 6.x/Symfony 3.x. I got the Class Not Found Error. I only have this error on Functional Tests extending Symfony\Bundle\FrameworkBundle\Test\WebTestCase |
Can you please show the output of |
The composer.json for symfony2.8. PhpUnit 6.x conflicts with phpunit-brifge 2.8
Composer show
|
You need dev-master of the bridge. |
I don't know why I should require dev-master version of the bridge (I am not using it), but I did it. Isn't working, same Class not found Error. I tried with PhpUnit 5.x and 6.x on both versions of symfony (2.8 and 3.2) |
If you want PHPUnit 6.0 you need the dev-master version of the bridge as only the master version supports PHPUnit 6.0. |
How do you run the tests? What is the exact error you get? |
I am don't care if is 5.x or 6.x version of PHPUnit, I just need a version working. I already tried everything I found about it. Including load the bootstrap.php.cache in phpunit.xml, run the test directly, etc. nothing works.
The same error I got with the default controller with default AppBundle. Class 'Symfony\Bundle\FrameworkBundle\Test\WebTestCase' not found in /var/www/scheduler/src/Fluency/Bundle/SchedulerBundle/Tests/Controller/DefaultControllerTest.php on line 7 |
This does not answer my question how you run your tests. Please explain how you did that before the tests started to fail and how your config was at that time. Did you then get the same error? Please note that the initial issue was about the |
I re-start everything from scratch, now is working. I think the problem was with the PhpUnit versions. Anyway for some reason my global installations of PHPUnit is not working (The Composer and OS Native). @xabbuh I did nothing, my Unit Tests works fine all the time, using my global phpunit installations, just the functional test failed. And WebTestCase is a child class of PHPUnit_Framework_TestCase. Thank you |
I started to use only the composer version. I was using composer + system version, and when they were different I was facing issues. So I'm now just using composer versions.
My phpunit run command:
|
There is also another workaround using composer directly. there is a plugin for class aliasing. This way there no need to change anything else |
Will be there a fix for this? I consider the aliasing as a monkey patch, not a real fix. |
There shouldn't be any issue if you are using a recent version of the PhpUnitBridge or PHPUnit itself. |
Using it with PHPUnit itself results in error. I don't know if this bridge works with Silex. |
But this is the Symfony issue tracker, not Silex'. |
@BlackSonic Which PHPUnit version and which error? |
Preconditions:
composer require --dev phpunit/phpunit=~6.0
.Steps to reproduce:
vendor/bin/phpunit -c .
Actual result:
Expected result:
Notes:
PHPUnit_Framework_TestCase
which is used as a parent class ofvendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php
was completely dropped in favor of PSR compatible namespacing in PhpUnit 6 (see this commit).4.85.4 (see changelog).KernelTestCase
with the new namespaced class?The text was updated successfully, but these errors were encountered: