Problem/Motivation

The PHPUnit --filter option works by pattern-matching. This means that

--filter=testFoo

will match 'function testFoo' and also 'function testFooBar'. AFAIK there is no way to make it a strict comparison.

This means that if you have a test class such as ContentEntityChangedTest with:

  public function testChanged(): void {
  public function testChangedSyncing(): void {

then it is not possible to run only testChanged when debugging.

Benefits

If we adopted this change, the Drupal Project would benefit by making local development easier.

Three supporters required

  1. https://www.drupal.org/u/{userid} (yyyy-mm-dd they added support)
  2. https://www.drupal.org/u/{userid} (yyyy-mm-dd they added support)
  3. https://www.drupal.org/u/{userid} (yyyy-mm-dd they added support)

Proposed changes

Provide all proposed changes to the Drupal Coding standards. Give a link to each section that will be changed, and show the current text and proposed text as in the following layout:

1. {link to the documentation heading that is to change}

Current text

Add current text in blockquotes

Proposed text

Add proposed text in blockquotes

2. Repeat the above for each page or sub-page that needs to be changed.

Remaining tasks

  1. Create this issue in the Coding Standards queue, using the defined template
  2. Add supporters
  3. Create a Change Record
  4. Review by the Coding Standards Committee
  5. Coding Standards Committee takes action as required
  6. Discussed at a Core Committee meeting, if it impacts Drupal Core
  7. Final review by Coding Standards Committee
  8. Documentation updates
    1. Edit all pages
    2. Publish change record
    3. Remove 'Needs documentation edits' tag
  9. If applicable, create follow-up issues for PHPCS rules/sniffs changes

For a full explanation of these steps see the Coding Standards project page

Comments

joachim created an issue. See original summary.

quietone’s picture

Status: Active » Needs review

Try using a $ at then end of the filter pattern.

The file core/tests/Drupal/Tests/Core/Display/DisplayVariantTest.php has test methods testGetWeight and testGetWeightDefault. Using --filter=testGetWeight results in both tests running and using --filter=testGetWeight$ results in just testGetWeigh() running.

$ phpunit -c core --colors=always core/tests/Drupal/Tests/Core/Display/DisplayVariantTest.php --filter=testGetWeight
PHPUnit 11.5.39 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.4.12
Configuration: /var/www/html/core/phpunit.xml

..                                                                  2 / 2 (100%)

Time: 00:00.017, Memory: 6.00 MB

OK (2 tests, 2 assertions)
$ phpunit -c core --colors=always core/tests/Drupal/Tests/Core/Display/DisplayVariantTest.php --filter=testGetWeight$
PHPUnit 11.5.39 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.4.12
Configuration: /var/www/html/core/phpunit.xml

.                                                                   1 / 1 (100%)

Time: 00:00.019, Memory: 6.00 MB

OK (1 test, 1 assertion)

Reference https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regula...

joachim’s picture

Ah I hadn't thought of using a $ at the end!

In which case, we can maybe close this as not necessary.

quietone’s picture

Status: Needs review » Closed (won't fix)

@joachim, thanks for commenting.

I also agree this can be closed and there is no need to add a coding standard for Drupal.

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.