pest icon indicating copy to clipboard operation
pest copied to clipboard

[Bug]: Breaking change in 3.8.1 architecture test, no longer allowing wildcard (*) for partial file names

Open sgilberg opened this issue 8 months ago • 2 comments

What Happened

We have the following architecture tests in our Laravel app:

arch('json resources')
    ->expect('App\Http\Resources\*Resource')
    ->toExtend('Illuminate\Http\Resources\Json\JsonResource');

arch('json resource collections')
    ->expect('App\Http\Resources\*ResourceCollection')
    ->toExtend('Illuminate\Http\Resources\Json\ResourceCollection');

Previously, this test was passing (we just upgraded from 3.7.4). As of the latest update, this throws a DirectoryNotFoundException, saying 'The "[redacted]../app/Http/Resources/*Resource" directory does not exist'.

How to Reproduce

Install a fresh Laravel app, add Pest (3.8.1), add a file directory App\Http\Resources, with a class in it that uses the "Resource" suffix and extends Illuminate\Http\Resources\Json\JsonResource.

Add the following architecture test:

arch('json resources')
    ->expect('App\Http\Resources\*Resource')
    ->toExtend('Illuminate\Http\Resources\Json\JsonResource');

Sample Repository

No response

Pest Version

3.8.1

PHP Version

8.4.2

Operation System

macOS

Notes

No response

sgilberg avatar Apr 07 '25 18:04 sgilberg

Bump. Wildcards don't really seem to work much at all currently. ->expect(['App\Models', 'Olympus\*\Models']) for example does not result in matching anything in a namespace like Olympus\Test\Models

Orrison avatar Apr 16 '25 17:04 Orrison

I'm also experiencing on v4.1.0.

<?php

// Tests\Architecture\HookTests.php

arch()
    ->expect('Platforms\Users\Hooks')
    ->toBeClasses()
    ->toUseTrait(BasePlatformHook::class)->only();

arch()
    ->expect('Platforms\*\Hooks')
    ->toBeClasses()
    ->toUseTrait(BasePlatformHook::class)->only();

Outputs:

./vendor/bin/pest --testsuite=Architecture

   FAIL  Tests\Architecture\HookTests
  ⨯ expect 'Platforms\Users\Hooks' → toBeClasses → toUseTrait 'App\Traits\BasePlatformHook'                                                  0.52s
  ✓ expect 'Platforms\*\Hooks' → toBeClasses → toUseTrait 'App\Traits\BasePlatformHook'

Jas-n avatar Sep 17 '25 08:09 Jas-n