Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
avenjamin opened this issue May 17, 2024 · 0 comments
Open

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

avenjamin opened this issue May 17, 2024 · 0 comments
Labels

Comments

@avenjamin
Copy link

avenjamin commented May 17, 2024

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 avenjamin added the bug label May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant