Problem/Motivation
An attempt to run php vendor/phpunit/phpunit/phpunit -c web/core web/core/modules/views/tests/src/Unit/Plugin/argument_default/RawTest.php resulted to me with:
Fatal error: Trait 'Prophecy\PhpUnit\ProphecyTrait' not found in D:\wamp\www\d9unit\web\core\tests\Drupal\TestTo
ols\PhpUnitCompatibility\PhpUnit9\TestCompatibilityTrait.php on line 12
Steps to reproduce
This happened to me with latest D9.1.x-dev (e0f0ebc)
Proposed resolution
According to change record Updated to PHPUnit 9
Use composer drupal-phpunit-upgrade See #4
The original proposal, which also worked
The error is fixed for me after I run: composer require phpspec/prophecy-phpunit
So, this dependency might be missing somewhere probably.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comments
Comment #2
cilefen commentedComment #3
hugronaphor commentedI got it after upgrading to Composer 2
adding
phpspec/prophecy-phpunitfixed the issueComment #4
longwaveThe problem is that Drupal 9 is compatible with both PHPUnit 8 and PHPUnit 9, but we only need
phpspec/prophecy-phpuniton PHPUnit 9 and it won't install if you have PHPUnit 8 so we can't add it as a dependency.The command
composer drupal-phpunit-upgradeexists already to upgrade PHPUnit and add the dependency for you.This is also documented in the change record at https://www.drupal.org/node/3176567
I'm not sure there is a way of making this more foolproof while we are compatible with both versions?
Comment #5
mvonfrie commentedWhat about adding it as suggestion to the composer.json?
At least this gives the user a hint when running
composer installorcomposer updatethat he might have to addphpspec/prophecy-phpunitas dependency.Comment #6
quietone commentedI just ran into this. I did
composer drupal-phpunit-upgradeas provided in #4 and that worked just fine. I added that solution to the IS, keeping the original.Comment #7
moshe weitzman commentedWe are running into this as well on DrupalSpoons. The proposal to run
composer drupal-phpunit-upgradedoes not work for any site built on core-composer-scaffold since that script is defined in drupal/drupal but not in drupal/core. We can't easily hard code the contents of the script because it varies by Drupal version.Comment #8
laceysanderson commentedAlso running into this when testing 9.1.x-dev on docker. This tracks with @moshe-weitzman thoughts regarding drupal/core. I install as follows:
When I try to run
composer drupal-phpunit-upgradeas provided in #4 the script is not available. However usingcomposer require phpspec/prophecy-phpunitdoes fix it :-)Comment #9
fgmFixed broken CR link
Comment #10
longwaveI've helped two people on Slack today with this error message alone.
I wonder if we can add some detection code that detects this state and tells the user what to do?
Comment #11
longwaveComment #12
mondrake#10 and #11 sound like a good idea to me.
Comment #13
gábor hojtsyRan into this exact problem today while setting up a new dev site for Upgrade Status locally. This pointed me in the right direction.
Comment #14
eli-tSlight query with the wording of the patch in #11:
PHPUnit 9 requires Prophecy PhpUnit.Isn't it that Drupal requires Prophecy PhpUnit when testing with PHPUnit 9?
PHPUnit 9 doesn't require Prophecy PhpUnit by itself, or it would be in PHPUnit's requirements.
Comment #15
eli-tPatch attached with shameless bikeshedding from #14
Comment #16
eli-tAdding interdiff
Comment #17
longwaveGood point.
Comment #18
br0kenWouldn't that make sense to do something like `shell_exec('composer require --dev phpspec/prophecy-phpunit')`?
Comment #19
longwaveBetter to tell the user what to do rather than try and fix it, as we might not be able to run Composer.
We have similar instructions in run-tests.sh if PHPUnit is not installed at all or the wrong version.
Comment #20
eli-tI think if we actually started automatically running composer commands when people run unit tests, that would be very confusing.
We also don't know if composer is on the path so this might not even work.
Comment #21
br0kenMakes sense 👍
Comment #22
alexpottThis looks like a fine approach to me. I think we should limit this to we do in drupal-phpunit-upgrade - ie.
composer require --dev phpspec/prophecy-phpunit:^2We also should add an @todo to remove when the minimum PHPUnit is 9 because then we can add this as a real dependency.
Further, let's say "when using PHPUnit 9 or greater" - or something like that.
Comment #23
longwaveAddressed #22.
Comment #24
eli-tHave reviewed the patch in #23, it includes the suggested changes from #22.
Todo comment added - there is no current issue for removing PHPUnit 8 so we don't need to reference one here.
Hence setting back to RTBC.
Comment #25
alexpottCommitted and pushed cbccba94b6 to 9.2.x and 94d0c1f1f2 to 9.1.x. Thanks!
Comment #28
mglamanSo I tried searching the issue queue for this and it didn't show. So I'll comment what I got back in my phpstan-drupal testing:
Comment #30
cangurin limpiezashi, i use
PHPUnit 9.5.5
Drupal core 9.2.0
when i try use
vendor/bin/phpunit -c phpunit.xml
or
SIMPLETEST_BASE_URL=http://localhost/c17062021/ ./vendor/bin/phpunit -c core/ --testsuite functional --filter SkeletonTest
i always get
PHP Fatal error: Trait 'Symfony\Bridge\PhpUnit\Legacy\PolyfillAssertTrait' not found in /var/www/html/c17062021/sites/simpletest/Assert.php on line 91
any idea?, thanks.
Comment #31
cilefen commentedThat could be https://www.drupal.org/node/3217694
Comment #32
arshadkhan35 commentedAdding
composer require --dev symfony/phpunit-bridgeworked for me.Comment #33
hiramanpatil@arshadkhan35,
I have tried it but still getting the same error.
Please check my reply here - https://www.drupal.org/project/drupal/issues/3346242#comment-15387854
Were you able to run any contributed module tests?
Thanks,