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

Create PHPStan extension and add HigherOrderTapProxy to universalObjectCratesClasses #996

Merged
merged 2 commits into from
Oct 31, 2023

Conversation

calebdw
Copy link
Contributor

@calebdw calebdw commented Oct 30, 2023

What:

  • New Feature

Description:

Hello!

With the release of PHP 8.2, dynamic property creation is deprecated unless the class uses the AllowDynamicProperties attribute or defines the __get/__set magic methods. However, PHPStan still reports the dynamic properties as being undefined unless the class is added to the universalObjectCratesClasses config.

Because of this, PHPStan is throwing errors for the below example even though the HigherOrderTapProxy (returned by empty test() call) does implement the __get/__set magic methods:

beforeEach(function () {
    test()->dateFormat = 'Y-m-d';
});

it('...', function () {
    // ...
    now()->format(test()->dateFormat);
});

// yields
Access to an undefined property Pest\PendingCalls\TestCall|Pest\Support\HigherOrderTapProxy::$dateFormat.

This PR creates an auto-registerable PHPStan extension that adds the HigherOrderTapProxy to the universalObjectCratesClasses config to fix these errors.

Thanks!

@calebdw
Copy link
Contributor Author

calebdw commented Oct 30, 2023

Note, I also added Expectation to universalObjectCratesClasses to fix the below error type:

expect($log)->finished_at->toBeNull();

Access to an undefined property Pest\Expectation<mixed>::$finished_at.

@nunomaduro nunomaduro merged commit 9aad417 into pestphp:2.x Oct 31, 2023
@calebdw calebdw deleted the phpstan branch October 31, 2023 02:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants