Sylius: Test environment broken with php 7.2.20
Sylius version affected: >=1.4.2
Description
We encountered this error when we tried to clear the cache:
[Symfony\Component\Debug\Exception\FatalErrorException]
Error: During class fetch: Uncaught ReflectionException: Class HWI\Bundle\OAuthBundle\Connect\AccountConnectorInterface not found
in /var/www/html/sylius/vendor/sylius/sylius/src/Sylius/Bundle/CoreBundle/OAuth/UserProvider.php:36
Stack trace:
#0 /var/www/html/sylius/vendor/symfony/debug/DebugClassLoader.php(160): require('/var/www/html/s...')
#1 [internal function]: Symfony\Component\Debug\DebugClassLoader->loadClass('Sylius\\Bundle\\C...')
#2 [internal function]: spl_autoload_call('Sylius\\Bundle\\C...')
#3 /var/www/html/sylius/vendor/symfony/config/Resource/ClassExistenceResource.php(78): class_exists('Sylius\\Bundle\\C...')
#4 /var/www/html/sylius/vendor/symfony/dependency-injection/ContainerBuilder.php(353): Symfony\Component\Config\Resource\ClassExistenceResource->isFresh(0)
#5 /var/www/html/sylius/vendor/symfony/dependency-injection/Compiler/AutowirePass.php(336): Symfony\Component\DependencyInjection\ContainerBuilder->getReflectionClass('Sylius\\Bundle\\C...', false)
#6 /var/www/html/sylius/vendor/symfony/dep
I found out that it’s due to Symfony trying to load the Sylius\Bundle\CoreBundle\OAuth\UserProvider, when in the test environment, which implements the HWI\Bundle\OAuthBundle\Connect\AccountConnectorInterface.
This interface comes with the hwi/oauth-bundle which doesn’t get installed by Sylius-standard.
The only reason it worked before was a bug in Php that made it possible to define a class that implements a non existent interface.
This bug got fixed in Php 7.2.20. https://www.php.net/ChangeLog-7.php#7.2.20 https://bugs.php.net/bug.php?id=76980
Steps to reproduce
Install Php 7.2.20 and try to clear the cache in the test environment.
Possible Solution
Two solutions come to mind:
- Require
hwi\oauth-bundlein Sylius-standard - Only load the service definition if the
hwi\oauth-bundleis installed like here: https://github.com/Sylius/Sylius/blob/defb389775303ec9fffa1dab7bdbd594b3de841e/src/Sylius/Bundle/CoreBundle/DependencyInjection/SyliusCoreExtension.php#L85-L92
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 2
- Comments: 19 (15 by maintainers)
Commits related to this issue
- Fix #10530 — committed to mmenozzi/Sylius by mmenozzi 5 years ago
- Move hwi/oauth-bundle to require from require-dev See #10530 — committed to mmenozzi/Sylius by mmenozzi 5 years ago
- bug #10540 Skip oauth_user_factory_is_not_overridden test if HWIOAuthBundle is not installed (vvasiloi) This PR was merged into the 1.4 branch. Discussion ---------- | Q | A | ------... — committed to Sylius/Sylius by pamil 5 years ago
Thank you very much for providing solutions
No @vvasiloi that code doesn’t matter because in
testenvironment thesylius.test.oauth.user_provideril loaded plain without any conditions here:https://github.com/Sylius/Sylius/blob/df295e46777266d4d3b94d1726b7cfc01f5c36fb/src/Sylius/Bundle/CoreBundle/Resources/config/test_services.xml#L58-L68
@mmenozzi I think it is a dev-dependency for tests only, because it’s an optional dependency and is listed in “suggests”.