pest icon indicating copy to clipboard operation
pest copied to clipboard

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

Open avenjamin opened this issue 9 months ago • 0 comments

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

  • Install a fresh Laravel app
  • Add Pest
  • Add a test:
arch('strict types')
    ->expect('App\Test')
    ->toUseStrictTypes();
  • Add a Test folder inside app
  • Add a new file, Test.php, with a class Test and function definition with required parameters after an optional parameter:
<?php declare(strict_types=1);

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 🤓

avenjamin avatar May 17 '24 01:05 avenjamin