You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you create a dataProvider method with any kind of Laravel call in it (e.g. using a model factory), we get an error.
Expected Behavior:
It should work?
Additional Context:
Adding parent::setup to provider method seems to fix it?
A dataProvider method without any calls to Laravel, works as expected.
This might be a complication related to how Laravel loads and how PHPunit works.
Versions:
Apiato Version: v11 & v12
PHP Version: 8.1.0
Steps To Reproduce:
Create a dataProvider method and use a model factory in it, e.g. User::factory()->create()
Use @dataProvider annotation of PHPunit on your test and call the created dataProvider method
Run the test
The text was updated successfully, but these errors were encountered:
PHPUnit will call the data provider methods before running any tests. Before each test it will also call the setUp() method in the test case. Laravel hooks into the setUp() method to call $this->createApplication() which will add the controller classes to the 'include path' so that they can be autoloaded correctly.
Here are two ways to get around this, and I prefer the second one.
Call refreshApplication() in your test setUp() method.
protectedfunctionsetUp(): void
{
parent::setUp();
// I don't know if this impact performance or cause any problems with parallel testing.$this->refreshApplication();
}
User closure to defer the call to any Laravel functionalities (e.g. model factories) to when you actually use it.
publicfunctiondataProvider(): array
{
return [
[
function () {
return [User::factory()->make()];
},
],
[
fn () => [User::factory()->make()],
]
];
}
/** * @dataProvider dataProvider */publicfunctiontestExample(Closure$data)
{
[$user] = $data();
// If you use any data from the test class you need to bind the closure to it.// [$user] = $data->bindTo($this)();
}
Description:
If you create a dataProvider method with any kind of Laravel call in it (e.g. using a model factory), we get an error.
Expected Behavior:
It should work?
Additional Context:
Addingparent::setup
to provider method seems to fix it?A dataProvider method without any calls to Laravel, works as expected.
This might be a complication related to how Laravel loads and how PHPunit works.
Versions:
Steps To Reproduce:
User::factory()->create()
@dataProvider
annotation of PHPunit on your test and call the created dataProvider methodThe text was updated successfully, but these errors were encountered: