Problem/Motivation

@requires externalCommand is not a supported syntax in PHPUnit 10, and its parser no longer processes it.

The valid types of @requires are describe here, https://docs.phpunit.de/en/10.0/annotations.html#requires.

We can no longer rely on PHPUnit internal Test::parseTestMethodAnnotations() method (which is no longer existing BTW), nor on its new Metadata API, to fetch this information.

Steps to reproduce

Run a build test with PHPUnit 10.

Proposed resolution

My suggestion would be to replace @requires externalCommand annotation with a static method to be implemented in the concrete tests.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3362083

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mondrake created an issue. See original summary.

mondrake’s picture

longwave’s picture

Some thoughts from Slack summarised here:

We introduced this three years ago as a generic solution but in fact we only use it four times, each to check that Composer is available.

I suggest moving the check into ComposerBuildTestBase and making ComposerValidateTest extend that, or perhaps adding the check to ComposerIntegrationTrait.

The more generic solution that follows PHPUnit would be to introduce a #[RequiresExternalCommand] attribute similar to https://docs.phpunit.de/en/10.0/attributes.html#skipping-tests but given we haven't needed this for anything else I suspect this is overkill and ExternalCommandRequirementsTrait can be removed.

mondrake’s picture

Assigned: Unassigned » mondrake

Thanks! I'm working on a solution based on a simple requirements check method.

wim leers’s picture

mondrake’s picture

Status: Active » Needs review
mondrake’s picture

Assigned: mondrake » Unassigned
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative
StatusFileSize
new106.18 KB

search

Do these instances need to be replaced too?

mondrake’s picture

The ExternalCommandRequirementTest ones no, because they serve the purpose of checking the deprecation. But the ComponentsTaggedReleaseTest probably yes - although it looks like the check was never done for that test...

mondrake’s picture

Status: Needs work » Needs review

Rebased and fixed ComponentsTaggedReleaseTest.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

LGTM.

longwave’s picture

Status: Reviewed & tested by the community » Needs review

As we only ever require Composer I think we can just make this even simpler?

trait RequiresComposerTrait {

  /**
   * @beforeClass
   */
  public static function requiresComposer() {
    $finder = new ExecutableFinder();
    if (!$finder->find('composer')) {
      static::markTestSkipped('This test requires Composer.');
    }
  }

}

You just add this trait to any class and it automatically skips if Composer is not available?

mondrake’s picture

Assigned: Unassigned » mondrake

I have some doubts we can skip a test through a @beforeClass annotated method, but I got the gist of this. Need some trials.

longwave’s picture

I did a very rough trial locally and it seemed to work, so I am hopeful.

mondrake’s picture

Status: Needs review » Needs work

OK thanks, I will work on this.

mondrake’s picture

Assigned: mondrake » Unassigned
Status: Needs work » Needs review

Can't add a deprecation trigger for ExternalCommandRequirementsTrait as it would fire during test discovery when the bridge is not yet capturing deprecations(*). So added a trigger to all the trait's methods instead.

(*) That's why things like these should live in the TestTools namespace, as the new trait - so that they do not mix up with the tests themselves.

longwave’s picture

Status: Needs review » Reviewed & tested by the community

Looks great! I updated the change record with documentation for the new trait.

  • catch committed 95136ba4 on 10.1.x
    Issue #3362083 by mondrake, smustgrave, longwave, Wim Leers: '@requires...

  • catch committed 6b2110cf on 11.x
    Issue #3362083 by mondrake, smustgrave, longwave, Wim Leers: '@requires...

  • catch committed f0f1da16 on 10.1.x
    Revert "Issue #3362083 by mondrake, smustgrave, longwave, Wim Leers: '@...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 11.x, thanks! (ignore the 10.1 commits...)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

quietone’s picture

Published the change record.