Reputation: 6620
In my Behat context, I've been included PHPUnit's assertions as described in the manual:
require_once 'PHPUnit/Autoload.php';
require_once 'PHPUnit/Framework/Assert/Functions.php';
However, I'm now using Symfony's PHPUnit bridge and so I've removed my explicitly-installed PHPUnit and am using the one brought in by the bridge. I needed to do this to avoid the "multiple versions" error described here.
But now, I can't use PHPUnit in behat!
PHP Warning: Uncaught exception 'Symfony\Component\Debug\Exception\ContextErrorException' with message 'Warning: require_once(PHPUnit/Autoload.php): failed to open stream: No such file or directory'
How can I reference the PHPUnit instance brought in by the PHPUnit bridge?
Upvotes: 2
Views: 1052
Reputation: 31
For Symfony 4, this was enough to get it working for me:
require_once(__DIR__ . '/../../vendor/bin/.phpunit/phpunit-5.7/vendor/autoload.php');
However it's not a great solution ongoing, as PHPUnit Bridge will install PHPUnit 6.3 instead of 5.7 if you're using PHP 7.2.
I tried changing composer.json as follows:
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
},
"classmap": [
"vendor/bin/.phpunit"
]
},
which does work, but breaks a fresh install because the folder doesn't exist until you run simple-phpunit
.
I suspect this could be worked around using composer scripts to run simple-phpunit
, but my brief experiments with post-install-cmd
and pre-autoload-dump
got me nowhere.
Upvotes: 3
Reputation: 6620
It turned out that I needed to require the relevant files in vendor by their path instead. For me, that was:
require_once(__DIR__.'/../../vendor/symfony/phpunit-bridge/bin/.phpunit/phpunit-5.7/vendor/autoload.php');
require_once(__DIR__.'/../../vendor/symfony/phpunit-bridge/bin/.phpunit/phpunit-5.7/src/Framework/Assert/Functions.php');
Upvotes: 1