-
Notifications
You must be signed in to change notification settings - Fork 65
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
Fix renamed file loader in phpunit #127
Conversation
It was renamed from `Fileloader` to `FileLoader`
Some case sensitive issues is not allowing to add class alias. Added phpunit ^7.0 tests om php version 7.2 Another run with `-x` on travis, as there was a problem with autoloading `\PHPUnit\Util\FileLoader` only if through phpunit.xml file
@@ -61,6 +63,10 @@ private static function handleBootstrap(array $config) | |||
{ | |||
$filename = isset($config['bootstrap']) ? $config['bootstrap'] : 'vendor/autoload.php'; | |||
|
|||
\PHPUnit\Util\Fileloader::checkAndLoad($filename); | |||
if (class_exists('\PHPUnit\Util\Fileloader')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please threat this if as it is at line 18? Just add the alias as well and use it as before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a problem with that.
Adding:
if (class_exists('\PHPUnit\Util\Fileloader')) {
class_alias('\PHPUnit\Util\Fileloader', '\PHPUnit\Util\FileLoader');
}
is resulting in odd behaviour on phpunit < 7.0 , class_exists
will trigger autoload on Fileloader
which at least on MacOs (not sure if OS case insensitive problem), is also thinking FileLoader
is there thus class_alias('\PHPUnit\Util\Fileloader', '\PHPUnit\Util\FileLoader');
would throw
Cannot declare class \PHPUnit\Util\FileLoader, because the name is already in use in reateTestsQueueFromPhpUnitXML.php on line 23
You can see the failing tests on the firs commit in the PR.
And if you run class_exists(\PHPUnit\Util\FileLoader)
it will return false.
So the only way to fix this problem was to actually check what is loaded before call.
Strangely enough class_exists will behave normally on cli piping. Didn't had time to dig deep into the issue and find what exactly is happening.
I'll be glad to help if you need more information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just saying you should put it on top of the class, like other alias, just for having them all in the same place.
BTW the problem you're facing is probably due to the fact that mac OSX (if you didn't specify a different fashion) run with case insensitive filesystem: this could lead you to this kind of troubles.
I suppose that, also, we should not include it as fastest problem but a filesystem one.
So, even travis file should not be modified, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I isolated the problem so you can take a look at it. I also tested on Windows and it seems it is not case sensitive problem. It would be PHP internal behaviour.
Take a look at this repo and run the test to see what the problem is.
We can remove the added ./fastest -x phpunit.xml.dist -v "vendor/phpunit/phpunit/phpunit {};"
but then you can never test the class aliasing and see if they are working. Probably isolating the aliased classes in separate tests for different phpunit versions, not sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still don't understand why ./fastest -x phpunit.xml.dist -v "vendor/phpunit/phpunit/phpunit {};"
won't test the alias.
I mean, if we still run phpunit 7
, we should fallback to alias with camel case whereas with phpunit 6
we should fallback to alias with non-camel case.
I didn't tried it, did you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, got the problem even for the command: it's due to composer
autoload that is case sensitive so we have two different issues: PHP is case insensitive so we can't define at the top the alias whereas composer is case sensitive so we need to run the command explicitly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still checking for a solution, but I'm starting to think that's the only one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly the problem finally cleared out also for me! Thanks for your patience.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another solution that comes to mind is to just trigger the autoload with two class_exists on both cases. Then the command will execute without problem no matter camel case or not as composer will load the file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lsimeonov I don't thinks it's gonna work. Only solution is to let all the code be bootstrapped by composer, like symfony does (for instance). This is the only way to be able to try to load both, but if you wanna try with both, go ahead and le me know.
PS.: I'm gonna merge this one at the end of this week end so feel free to try - as well as I will - other solutions 'till that time. For other point of this discussion, I suppose it's better to separate them into single "issue" and continue there; I'm gonna do this either
fi | ||
- composer update $PREFER_LOWEST | ||
|
||
script: | ||
- find tests/ -name "*Test.php" | php fastest -v | ||
- ./fastest -x phpunit.xml.dist -v "vendor/phpunit/phpunit/phpunit {};" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really needed? I mean, line 43 should run the same tests: isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added it because the test behave differently in terms of autoloading when running trough pipping and running it with phpunit.xml.
The old travisci way would pass for phpunit ^7.0 as it won't trigger into the autoload problem I described on the previous comment and where fastest is failing with phpunit ^7.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course the best way to do it is just include it in the tests which I can't do at the moment.
We need to cover all the nuances of missing classes and aliases.
Ok, this seems to be the only way to fix this, I didn't find a better solution. Moreover it would be great to start a discussion about this kind of BC that we want to keep: it's fantastic but, as we provide support for behat and phpunit, maybe we should have different major releases for majors of these libraries, with end of support for them, when them gonna stop support. Moreover we should start thinking about "splitting" the project in three parts:
This way we could have more freedom for changes. Still don't know if core is "contaminated" with PHPUnit concepts though Just random thoughts, let me know what do you guys think. |
…or phpunit 7.0 ProcessorCounter now has new class for getting the OS so we can mock it. Tests were failing on MacOS
Added more elegant way of handling case sensitive problem between PHP classes and composer autoloader. |
Ok, I'm gonna merge this. Thank you for great effort! |
@lsimeonov here the release https://github.com/liuggio/fastest/releases/tag/v1.6.1 thank you again |
It was renamed from
PHPUnit\Util\Fileloader
toPHPUnit\Util\FileLoader
in sebastianbergmann/phpunit@3a9494b#diff-7862e6eec2d5923e62d57728b79a0480