Skip to content

Update to PHPUnit namespaces #21564

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

Closed
wants to merge 10 commits into from
Closed

Update to PHPUnit namespaces #21564

wants to merge 10 commits into from

Conversation

peterrehm
Copy link
Contributor

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?

@peterrehm
Copy link
Contributor Author

peterrehm commented Feb 8, 2017

The FC layer is basically restricted to a few classes as you can see here: sebastianbergmann/phpunit@a55235c

  • PHPUnit_Framework_Assert
  • PHPUnit_Framework_BaseTestListener
  • PHPUnit_Framework_TestCase
  • PHPUnit_Framework_TestListener

In order to fully switch to namespaces we must upgrade to 6.0.

Meanwhile to Bridge will not work with 6.0.

@peterrehm
Copy link
Contributor Author

The PHP 5.3 test fails due to the wrong phpunit version.

@stof
Copy link
Member

stof commented Feb 8, 2017

Well, you say you are replacing #21540, but our remarks on it are still valid. We have more public base test cases (and we have some listeners in the PHPUnit bridge)

@peterrehm
Copy link
Contributor Author

@stof Yes. Sorry, it looks like I did not elaborate enough information about your Bridge remark.

The issue is since only the above mentioned 4 classes are in the FC layer, the Bridge cannot be updated to 6.0 as it uses the following classes:

/symfony/src/Symfony/Bridge/PhpUnit$ pt PHPUnit_
bootstrap.php
16:if (!defined('PHPUNIT_COMPOSER_INSTALL') && !class_exists('PHPUnit_TextUI_Command', false)) {

DeprecationErrorHandler.php
54:                return \PHPUnit_Util_ErrorHandler::handleError($type, $msg, $file, $line, $context);
62:            while (1 < $i && (!isset($trace[--$i]['class']) || ('ReflectionMethod' === $trace[$i]['class'] || 0 === strpos($trace[$i]['class'], 'PHPUnit_')))) {
76:                    || in_array('legacy', \PHPUnit_Util_Test::getGroups($class, $method), true)
99:            if (array('PHPUnit_Util_ErrorHandler', 'handleError') === $oldErrorHandler) {

Tests/DeprecationErrorHandler/default.phpt
21:class PHPUnit_Util_Test

TextUI/Command.php
17:class Command extends \PHPUnit_TextUI_Command

Are those the listeners/handlers you meant? I do not see a way other then adding classes to the bridge which should then work like the FC layer here sebastianbergmann/phpunit@a55235c.

@peterrehm
Copy link
Contributor Author

I would think all the other remarks are included in the PR.

@stof
Copy link
Member

stof commented Feb 8, 2017

@peterrehm it cannot be switched to namespaces entirely to add compat, I know. But several places can be changed.

And we also have base test cases elsewhere than the KernelTestCase (I know that the Form and Validator components have some)

@peterrehm
Copy link
Contributor Author

How about migrating at least ALL those 4 classes to the namespaced version that the FC layer provides?

@@ -13,6 +13,7 @@

require_once __DIR__.'/Fixtures/includes/foo.php';

use PhpUnit\Framework\TestCase;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong namespace. It is PHPUnit (same in many files, and it breaks on the CI server)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed with the Migration of the Components

@peterrehm
Copy link
Contributor Author

And PHPUnit_Framework_Assert is also migrated.

@peterrehm
Copy link
Contributor Author

I dont get why the PHP 7 tests are failing, on my local machine I do not have any issues.
Any other remarks?

@peterrehm
Copy link
Contributor Author

/ping @symfony-deciders Any remarks? Can we get this merged?

@Jean85
Copy link
Contributor

Jean85 commented Feb 10, 2017

If this gets merged, due to the new conflicts with the older PHPUnit versions, I can completely rewrite my PR for the PHPUnit bridge too (#21221)

composer.json Outdated
@@ -24,6 +24,9 @@
"twig/twig": "~1.28|~2.0",
"psr/log": "~1.0"
},
"conflict": {
"phpunit/phpunit": "< 4.8.35 || >=5.0 <=5.4.2"
Copy link
Member

@jderusse jderusse Feb 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Symfony 2.7 supports php 5.3
This rule prevent people to install a version of phpunit compatible with php < 5.6 alongside Symfony

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not as it allows 4.8.35?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, I missed the strict comparison

Copy link
Member

@nicolas-grekas nicolas-grekas Feb 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should written as <4.8.35|<5.4.3,>=5.0 for consistency with what we do elsewhere IMHO

@jderusse
Copy link
Member

If this PR break unit tests for a supported version, you should find a way to fix it

@peterrehm
Copy link
Contributor Author

@jderusse As mentioned I do not get why they are failing, it might be related to the rebuild of the bridge, the subtree split, etc. Feel free to take over if you know better.

@@ -1,7 +1,7 @@
#!/usr/bin/env php
<?php

// Cache-Id: https://github.com/symfony/phpunit-bridge/commit/4f2aa873d2872a3b9782b25879fd628a0c418bc9
// Cache-Id: https://github.com/symfony/phpunit-bridge/commit/d3157d942a4590121dfd23f9cadf519ca6ad4ac7
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is not necessary. The issue with the failing tests is that the PhpUnitBridge itself checks whether or not it needs an update. However, this doesn't work here as the simple-phpunit file is part of the bridge installed as a vendor library.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It still is necessary I think to trigger a phpunit cache invalidation on appveyor.

@nicolas-grekas
Copy link
Member

I cleared the phpunit cache and restarted tests. There are still a few failures to take care of.

@peterrehm
Copy link
Contributor Author

Hm, when quickly scanning the logs I do not understand the reason for the failures. I see some missing autoloadphp's and some command failures.

Do you have a clue what the reason might be?

@nicolas-grekas
Copy link
Member

Dunno yet about the autoload failure.
You should be able to reproduce (then debug) this one easily locally, isn't it?
https://travis-ci.org/symfony/symfony/jobs/199575966#L3178

@peterrehm
Copy link
Contributor Author

Actually not at all:

With PHPUnit 5.7.
./phpunit src/Symfony/Bundle/TwigBundle/Tests/Functional/CacheWarmingTest.php
#!/usr/bin/env php
PHPUnit 5.7.12 by Sebastian Bergmann and contributors.

Testing Symfony\Bundle\TwigBundle\Tests\CacheWarmingTest
..                                                                  2 / 2 (100%)

Time: 430 ms, Memory: 14.00MB

With PHPUnit 4.8

./phpunit src/Symfony/Bundle/TwigBundle/Tests/Functional/CacheWarmingTest.php
#!/usr/bin/env php
PHPUnit 4.8.35 by Sebastian Bergmann and contributors.

Testing Symfony\Bundle\TwigBundle\Tests\CacheWarmingTest
..

Time: 456 ms, Memory: 14.00MB

I tried some adjustment, it just makes no sense. Localy the tests pass on PHP7 as well.

@peterrehm
Copy link
Contributor Author

With the latest commits I fixed 5.3 which IMHO makes no sense but who cares.

No there are the issues with 7.x ledt which seem more related with the test setup rather than the actual changes? Is this maybe due to the subtree split?

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - would be great to have a rule on fabbot that ensures that we won't introduce non-namespaced phpunit things anymore thought.

composer.json Outdated
@@ -24,6 +24,9 @@
"twig/twig": "~1.28|~2.0",
"psr/log": "~1.0"
},
"conflict": {
"phpunit/phpunit": "< 4.8.35 || >=5.0 <=5.4.2"
Copy link
Member

@nicolas-grekas nicolas-grekas Feb 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should written as <4.8.35|<5.4.3,>=5.0 for consistency with what we do elsewhere IMHO

@nicolas-grekas
Copy link
Member

travis failures are unrelated (known composer bug when too many local packages are created)

@peterrehm
Copy link
Contributor Author

@nicolas-grekas Updated the constraint. For now some PHPUnit_ classes are still needed due to the limited scope of the FC layer.

If we manage to provide a full FC layer we could enforce that. Next would be to update the bridge to full PHP6 compatibility.

@nicolas-grekas
Copy link
Member

Just did that: grep PHPUnit_ * -r, which leads to two things that remain:
all doc block annotations should be updated to namespaces, even if the BC layer doesn't provide them.
all instanceof/catch checks should be doubled with both namespaced and underscore versions.

@Jean85
Copy link
Contributor

Jean85 commented Feb 13, 2017

@peterrehm
Copy link
Contributor Author

See my attempt here: sebastianbergmann/phpunit#2502 Lets see how it goes.

@peterrehm
Copy link
Contributor Author

@nicolas-grekas Rebased. Once this is merged I would like to check first the 3.x branches then we should care about the bridge. Once we have this done we could look into how to prevent those issues. Does fabbot rely on php-cs-fixer?

@Jean85
Copy link
Contributor

Jean85 commented Feb 17, 2017

@peterrehm I this get merged, I would like to help with the bridhe.
I'll close and attempt a rewrite to my prev PR (#21221) but I think it'll be a hard think to do... The main issue that I was unable to overcome was the usage of the TestCase in argument typehints, and the use of the FC layer should be helpful!

@peterrehm
Copy link
Contributor Author

@Jean85 Lets discuss once this is done. I think we have to look into providing a FC layer as PHPUnit does.

@nicolas-grekas nicolas-grekas added this to the 2.7 milestone Feb 18, 2017
@nicolas-grekas
Copy link
Member

👍

@xabbuh
Copy link
Member

xabbuh commented Feb 18, 2017

👍 The changes look good. I just don't understand why the build is failing.

@peterrehm
Copy link
Contributor Author

@xabbuh #21564 (comment)

@Tobion
Copy link
Contributor

Tobion commented Feb 18, 2017

👍

@Tobion Tobion self-requested a review February 18, 2017 11:27
@fabpot
Copy link
Member

fabpot commented Feb 18, 2017

Thank you @peterrehm.

fabpot added a commit that referenced this pull request Feb 18, 2017
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
@fabpot fabpot closed this Feb 18, 2017
@nicolas-grekas
Copy link
Member

@peterrehm can you please check branch 2.8 now? I just merged 2.7 into 2.8. Thanks for your help.

@peterrehm peterrehm deleted the phpunit-6 branch February 18, 2017 17:32
nicolas-grekas added a commit that referenced this pull request Feb 20, 2017
This PR was squashed before being merged into the 2.8 branch (closes #21663).

Discussion
----------

Updated PHPUnit namespaces

| Q             | A
| ------------- | ---
| Branch?       | 2.8
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Follow Up of #21564

Commits
-------

205ced4 Updated PHPUnit namespaces
nicolas-grekas added a commit that referenced this pull request Feb 20, 2017
This PR was merged into the 2.7 branch.

Discussion
----------

Add missing conflict rules for phpunit

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

We forgot them in #21564

Commits
-------

3e83e02 Add missing conflict rules for phpunit
nicolas-grekas added a commit that referenced this pull request Mar 9, 2017
This PR was merged into the 3.2 branch.

Discussion
----------

Use PHPUnit 5.4 instead of 5.3

| Q             | A
| ------------- | ---
| Branch?       | 3.2
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

PHPUnit 5.3 doesn't have the forward compatibility layer for PHPUnit 6 so that `PHPUnit\Framework\TestCase` can be used instead of `PHPUnit_Framework_TestCase`.

This generates an error when upgrading to Symfony 3.2.5 without forcing the `SYMFONY_PHPUNIT_VERSION` const:

```
Class 'PHPUnit\Framework\TestCase' not found in vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php on line 25
```

This was introduced by c9684ad (from #21564) in 3.2.5

(Discussion started on Slack: https://symfony-devs.slack.com/archives/support/p1489058629011510)

Commits
-------

fca16ba Use PHPUnit 5.4 instead of 5.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.