Prefix all code bundled in PHAR distribution with random/unique namespace #2015

Open
sebastianbergmann opened this Issue Dec 23, 2015 · 7 comments

Projects

None yet

5 participants

@sebastianbergmann

Issues such as #2014 happen when the code under test shares dependencies with PHPUnit but requires different versions than the ones bundled in the PHAR.

@sebastianbergmann sebastianbergmann self-assigned this Dec 23, 2015
@Soullivaneuh

I was working on it but php-scoper is not on packagist yet. See webmozart/php-scoper#12.

I'm not sure of the theseer/autoload work here, can you please elaborate? :-)

@Soullivaneuh

AFAIK, this will partially resolve #2014.

The .phar will be fixed, but not global composer install, right?

@lastzero
Contributor

Excellent idea! We just had trouble testing our Symfony 2.8 project. PHPUnit's phar (tested with 5.1.4) comes with the Yaml component of Symfony 3.0. Since Yaml::parse() does not support file names anymore, important dependencies such as Doctrine ORM are broken with this version (YAML config files can not be read anymore and you see misleading error messages). I can imagine, many developers are facing similar problems without understanding the reason. They might stop writing unit tests right in this moment. You should really fix this.

@sebastianbergmann

@lastzero In a scenario such as the one you describe you have to install PHPUnit via Composer for the time being.

@lastzero
Contributor

@sebastianbergmann Sure, but my developers didn't figure this out on their own. It's just plain dangerous to bundle a common standard component such as the Symfony YAML parser in a version with all backwards compatibility removed. Actually, I think there was a previous release of phpunit(.phar), that checked if a vendor directory exists and only used the bundled libraries if not.

Hint for other developers: If you're facing issues like this, you can use http://php.net/manual/en/reflectionclass.getfilename.php to get the filename of a class to see if it's coming from vendor or from a phar file.

@ssnikiforov
ssnikiforov commented Oct 20, 2016 edited

We have stucked with the same problem. "symfony/dependency-injection" v3.2 (master) has a dependency "use Symfony\Component\Yaml\Yaml;" in "/Loader/YamlFileLoader.php". And, also, phpunit has an implementation (hard-coded) of "Yaml" class in phpunit's phploc.php file.

Solution is to set up in your composer.json requirement of exactly "3.0" version of symphony/dependency-injection. You can type smth like this:
"symfony/dependency-injection": "3.0".

Thanks @iplus for found solution to the problem.

@COil
COil commented Oct 27, 2016 edited

@ssnikiforov I tried adding symfony/dependency-injection": "3.0" but it doesn't seem to work. (with Symfony 3.2 beta1) (and php 5.5)

[17:41:43] $ composer update symfony/symfony --with-dependencies
Loading composer repositories with package information
Updating dependencies (including require-dev)                                                             
Your requirements could not be resolved to an installable set of packages.
 Problem 1
    - don't install symfony/dependency-injection v3.0.0|don't install symfony/symfony 3.2.x-dev
    - don't install symfony/dependency-injection v3.0.0|remove symfony/symfony 3.2.x-dev
    - don't install symfony/dependency-injection v3.0.0|don't install symfony/symfony 3.2.x-dev
    - Installation request for symfony/dependency-injection 3.0 -> satisfiable by symfony/dependency-injection[v3.0.0].
    - Installation request for symfony/symfony 3.2.x-dev -> satisfiable by symfony/symfony[3.2.x-dev].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment