pestphp / pest

Pest is an elegant PHP testing Framework with a focus on simplicity, meticulously designed to bring back the joy of testing in PHP.
https://pestphp.com
MIT License
9.45k stars 341 forks source link

[Bug]: toOnlyUse not working as documented in the Pest Docs #973

Open spont4e opened 12 months ago

spont4e commented 12 months ago

What Happened

When I used either the toOnlyUse examples even directly copied from the docs, it returns this exception.

How to Reproduce

  1. Install a fresh laravel app with pest
  2. Replace Feature\ExampleTest with the following basically clipped from the docs
<?php

test('models')
    ->expect('App\Models')
    ->toOnlyUse('Illuminate\Database');

Exception stacktrace

ErrorException: Attempt to read property "stmts" on null
at vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:254
at vendor/pestphp/pest-plugin-arch/src/Blueprint.php:235
at vendor/pestphp/pest-plugin-arch/src/Blueprint.php:148
at vendor/pestphp/pest-plugin-arch/src/Expectations/ToOnlyUse.php:37
at vendor/pestphp/pest-plugin-arch/src/SingleArchExpectation.php:156
at vendor/pestphp/pest-plugin-arch/src/SingleArchExpectation.php:140
at vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:174

  Tests:    1 failed (1 assertions)
  Duration: 1.76s

Process finished with exit code 2

Sample Repository

No response

Pest Version

2.19.2

PHP Version

8.2.10

Operation System

Linux

Notes

No response

devajmeireles commented 11 months ago

Hey, @spont4e . Thanks for your report.

I was able to reproduce that. I will investigate the issue. Feel free to open a PR fixing this issue.

wblondel commented 3 months ago

Hello,

Is help still wanted on this issue? It seems PR https://github.com/pestphp/pest-plugin-arch/pull/10 from December 2023 fixes the issue. It would be great to have it merged!