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.06k stars 313 forks source link

[Bug]: DEPR error doesn't show file name. #1154

Open avenjamin opened 1 month ago

avenjamin commented 1 month ago

What Happened

I have a simple test:

arch('strict types used everywhere')
    ->expect('App')
    ->toUseStrictTypes();

that works, but once I'd fixed my missing declare(strict_types=1); it displayed the following error:

DEPR  Tests\Unit\ArchitectureTest
  ! strict types used everywhere → Optional parameter $displayname declared before required parameter $status is implicitly treated as a required parameter // vendor/ta-tikoma/phpunit-architecture-test/src/Asserts/Dependencies/ObjectDependenciesDescription.php:44

There's no mention of what file the error was in, and the only clue was the $displayname and $status parameters.

I eventually found the file with the offending issue, and as the error said, I'd mistakenly put a required parameter after an optional one in a function definition:

public function __construct(
        public string|null $displayname = null,
        public AccountStatus $status,
        ....

Note: AccountStatus above is an enum, and line 44 of ObjectDependenciesDescription.php is enum_exists($nameAsString) => true,

How to Reproduce

namespace App\Test;

class Test { function test(string $optional = 'optional', string $required) { // } }

- Run tests and see following output:

DEPR Tests\Unit\ExampleTest ! strict types → Optional parameter $optional declared before required parameter $required is implicitly treated as a required parameter // vendor/ta-tikoma/phpunit-architecture-test/src/Elements/ObjectDescriptionBase.php:111


- Observe no mention of `Test.php`

### Sample Repository

https://github.com/avenjamin/Pest-Test

### Pest Version

2.34.7

### PHP Version

8.3.7

### Operation System

macOS

### Notes

This is my first time using pest so I might have done something wrong 🤓