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]: Pest errors if namespaced class name string appears multiple times inside a single dataset #1115

Open
bakerkretzmar opened this issue Mar 15, 2024 · 4 comments
Labels

Comments

@bakerkretzmar
Copy link

bakerkretzmar commented Mar 15, 2024

What Happened

If more than one of the values in a single dataset are namespaced class strings Pest fails or errors.

How to Reproduce

The following test causes Pest to error out with the message Typed static property P\Tests\Feature\ExampleTest::$__latestDescription must not be accessed before initialization:

use App\Http\Controllers\Controller;
use Illuminate\Database\Eloquent\Model;

test('returns a successful response', function (string $first) {
    expect(true)->toBeTrue();
})->with([Model::class, Controller::class]);

Changing either Model::class or Controller::class to a literal string (e.g. 'App\Model') fixes that particular example, but this doesn't always work.

Sample Repository

No response

Pest Version

2.34.4

PHP Version

8.2.15

Operation System

macOS

Notes

This doesn't seem to reproduce consistently. I can make it fail with some class name strings but not others, sometimes using ::class notation and sometimes with literal strings, etc.

@bakerkretzmar bakerkretzmar changed the title [Bug]: Pest errors if certain ::class notation appears multiple times inside a single dataset [Bug]: Pest errors if namespaced class name string appears multiple times inside a single dataset Mar 15, 2024
@faissaloux
Copy link
Contributor

I can confirm the issue in your first example.

In your second example it's working as it is supposed to, actually you are passing only one argument.

It's going through the dataset one by one so it is providing only one argument in your case (Controller::class in first iteration then Model::class in second). If you need to pass two your need to rewrite your dataset like:

[
    ['controller', Controller::class],
    ['model', Model::class]
    .
    .
    .
]

In this case

  • first iteration: the first argument gonna be 'controller' and the second Controller::class.
  • second iteration: the first argument gonna be 'model' and Model::class for the second.
    and so on

@bakerkretzmar
Copy link
Author

Ah thanks you're right, missed that. I'll update the examples.

@bakerkretzmar
Copy link
Author

I think this might be happening because Pest is trying to parse any data providers that are 2-element arrays as callables...

@bakerkretzmar
Copy link
Author

Works fine:

test('returns a successful response', function (string $first, string $second) {
    expect(true)->toBeTrue();
})->with([Controller::class])->with([User::class, 'update']);

Errors:

test('returns a successful response', function (string $first, string $second) {
    expect(true)->toBeTrue();
})->with([Controller::class])->with([User::class, 'notAMethodOnTheUserClass']);

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

2 participants