Skip to content

[Bridge\PhpUnit] Disable broken auto-require mechanism of phpunit #25032

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
Nov 19, 2017

Conversation

nicolas-grekas
Copy link
Member

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

It took me all the flight back from Cluj to figure out this is the only way to solve this nasty issue created by phpunit generating inlined require_once in the global scope for isolated tests.
This mechanism predates the autoloading mechanism, and it's behavior is just hardcoded.
Needs to be merged in 3.4, where the split container triggers this situation very quickly.

Will allow removing the function_exists('__phpunit_run_isolated_test') workarounds already in place in the code base (2.7 up to master.)

@nicolas-grekas nicolas-grekas changed the base branch from 3.4 to 3.3 November 19, 2017 17:07
@nicolas-grekas
Copy link
Member Author

moved to 3.3 to prevent conflicts between local and vendor phpunit bridges

@nicolas-grekas nicolas-grekas modified the milestones: 3.4, 3.3 Nov 19, 2017
@nicolas-grekas nicolas-grekas merged commit 0577d20 into symfony:3.3 Nov 19, 2017
nicolas-grekas added a commit that referenced this pull request Nov 19, 2017
…phpunit (nicolas-grekas)

This PR was merged into the 3.3 branch.

Discussion
----------

[Bridge\PhpUnit] Disable broken auto-require mechanism of phpunit

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

It took me all the flight back from Cluj to figure out this is the only way to solve this nasty issue created by phpunit generating inlined `require_once` in the global scope for isolated tests.
This mechanism predates the autoloading mechanism, and it's behavior is just hardcoded.
Needs to be merged in 3.4, where the split container triggers this situation very quickly.

Will allow removing the `function_exists('__phpunit_run_isolated_test')` workarounds already in place in the code base (2.7 up to master.)

Commits
-------

0577d20 [Bridge\PhpUnit] Disable broken auto-require mechanism of phpunit
nicolas-grekas added a commit that referenced this pull request Nov 19, 2017
…ks (nicolas-grekas)

This PR was merged into the 2.7 branch.

Discussion
----------

Remove function_exists(__phpunit_run_isolated_test) checks

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

As now permitted by #25032

Commits
-------

a512217 Remove function_exists(__phpunit_run_isolated_test) checks
@greg0ire
Copy link
Contributor

greg0ire commented Nov 19, 2017

I'm getting

phpunit
PHPUnit 5.7.23 by Sebastian Bergmann and contributors.

Cannot declare class PHPUnit_Util_Blacklist, because the name is already in use

vendor/bin/simple-phpunit
which: no composer.phar in (/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/games:/home/greg/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/greg/src/shunit2:/home/greg/.fzf/bin)
PHPUnit 5.7.25 by Sebastian Bergmann and contributors.

Cannot declare class PHPUnit_Util_Blacklist, because the name is already in use

since upgrading to the latest 3.4.

Not entirely sure it's related yet.

UPDATE: I have the same issue with 3.x, I'll try bisecting.

@greg0ire
Copy link
Contributor

greg0ire commented Nov 19, 2017

0577d20 is the first bad commit

commit 0577d20ade7d6191c68174c8a3fe68d84072e442
Author: Nicolas Grekas <nicolas.grekas@gmail.com>
Date:   Sun Nov 19 14:29:22 2017 +0200

    [Bridge\PhpUnit] Disable broken auto-require mechanism of phpunit

:040000 040000 4c11b70dd68fe5f6fa1cadd4058c8ab9eaca6d6d b329a21a1e6bc48a4abf48379745af28e6d443d9 M	src

@nicolas-grekas nicolas-grekas deleted the phpunit-blacklist-all branch November 19, 2017 19:15
@nicolas-grekas
Copy link
Member Author

did you remove the .phpunit cache folder?

@greg0ire
Copy link
Contributor

greg0ire commented Nov 19, 2017

I just tried removing ./vendor/symfony/phpunit-bridge/bin/.phpunit, it doesn't help, be it with the phar or with simple-phpunit

@greg0ire
Copy link
Contributor

Here is a simple reproducer:

git clone git@github.com:sonata-project/SonataMediaBundle.git
cd SonataMediaBundle
composer require symfony/symfony '3.3.x-dev as 3.3.0'
vendor/bin/simple-phpunit

@nicolas-grekas
Copy link
Member Author

@greg0ire can you try again? could/should be fixed.

@greg0ire
Copy link
Contributor

No luck it seems, with both the phar and simple-phpunit (with .phpunit removed)

composer update -v
Loading composer repositories with package information
Updating dependencies (including require-dev)
Dependency resolution completed in 0.711 seconds
Analyzed 13943 packages to resolve dependencies
Analyzed 521378 rules to resolve dependencies
Dependency resolution completed in 0.000 seconds
Package operations: 0 installs, 1 update, 0 removals
Updates: symfony/symfony:3.3.x-dev 0187e9b
  - Updating symfony/symfony 3.3.x-dev (f2fc7bf => 0187e9b):  Checking out 0187e9b3400e55b978901483ad71f40dc48c70ed
    Pulling in changes:
      0187e9b340 - Nicolas Grekas: [Bridge/PhpUnit] Fix compat with phpunit 4.8 & bridge <=3.3.13
Package amazonwebservices/aws-sdk-for-php is abandoned, you should avoid using it. Use aws/aws-sdk-php instead.
Package guzzle/guzzle is abandoned, you should avoid using it. Use guzzlehttp/guzzle instead.
Writing lock file
Generating autoload files
╭─greg@liche in /tmp/SonataMediaBundle on 3.x ✘ (origin/3.x)
╰$ phpunit                                            
PHPUnit 5.7.23 by Sebastian Bergmann and contributors.

Cannot declare class PHPUnit_Util_Blacklist, because the name is already in use

@nicolas-grekas
Copy link
Member Author

ok, then I need a reproducer that actually works :)
the previous didn't have the issue actually
exact PHP + phpunit versions might help?

@greg0ire
Copy link
Contributor

greg0ire commented Nov 19, 2017

Here you go:

php --version
PHP 7.1.11 (cli) (built: Oct 25 2017 07:27:25) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
    with Xdebug v2.5.5, Copyright (c) 2002-2017, by Derick Rethans

phpunit --version
PHPUnit 5.7.23 by Sebastian Bergmann and contributors.

vendor/bin/simple-phpunit --version
which: no composer.phar in (/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/games:/home/greg/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/greg/src/shunit2:/home/greg/.fzf/bin)
PHPUnit 5.7.25 by Sebastian Bergmann and contributors.

Not sure why this can't be reproduced easily 😅

@nicolas-grekas
Copy link
Member Author

@greg0ire OK, actually that's a bug in Sonata's tests/bootstrap.php:
the bridge is not provided by the symfony/symfony: even if the code is there, it is voluntarily excluded from "replace" and "autoload" sections in symfony's main composer.json. The lines in your bootstrap.php files that looks for the bridge in symfony/symfony need to be removed.

@greg0ire
Copy link
Contributor

Thanks a lot for the diagnosis, sorry we had that weird stuff, we're going to simplify. Cc @soullivaneuh @core23 @OskarStark @jordisala1991 @jlamur

This was referenced Nov 21, 2017
@fabpot fabpot mentioned this pull request Dec 4, 2017
@teohhanhui
Copy link
Contributor

So there is no other way than to use simple-phpunit? Or was this fixed at some point in phpunit itself?

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.

4 participants