Skip to content

Conversation

@sunchayn
Copy link

@sunchayn sunchayn commented Jan 17, 2026

What:

  • Bug Fix
  • New Feature

Description:

This PR introduces a suffix(string $suffix) method to the uses() configuration chain. This allows developers to apply different configurations to different test suites living in the same folder structure.

Example in PHPUnit,

    <testsuites>
        <testsuite name="Functional">
            <directory suffix="FunctionalTest.php">App</directory>
        </testsuite>
        <testsuite name="Unit">
            <directory suffix="UnitTest.php">App</directory>
        </testsuite>
    </testsuites>

Equivalent in Pest (as part of this PR)

Pest()
  ->uses(TestCase::class)
  ->in('App')
  ->beforeEach(...)
  ->suffix('FunctionalTest.php');

Pest()
  ->uses(\PHPUnit\Framework\TestCase)
  ->afterEach(...)
  ->in('App')
  ->suffix('UnitTest.php');

This use case is for developers willing to have a testing structure that mirrors their source code structure, so that functional and unit tests live next to each other.

└── tests/
    ├── Pest.php
    ├── TestCase.php
    └── App/
        └── Modules/
            └── Users/
                ├── ValueObjects/
                │   └── UserEmailUnitTest.php
                ├── Actions/
                │   └── LoginUserActionFunctionalTest
                └── Models/
                    ├── UserModelAnotherThingUnitTest.php
                    └── UserModelSomethingFunctionalTest.php

Introduces a `.suffix()` method to `uses()` for fine-grained configuration targeting.

Example: uses(TestCase::class)->in('App')->suffix('FunctionalTest.php');

This ensures that only test files ending with the specified suffix within the targeted directory receive the associated traits, classes, or hooks.

This is similar to PHPUnit's <directory suffix="FunctionalTest.php">./tests</directory> directive.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant