Feature Testing
#39764
Replies: 1 comment 2 replies
-
Hey @kingdomac, we also stumbled upon this issue. After a lot of debugging, we fixed it by using Hope this helps someone else in the future. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description:
In my test classes, I'm creating records inside my database (using LazilyRefreshDatabase) and sending requests to the endpoint of my API, so when running the test:
Steps To Reproduce:
The problem is that in some testing functions I'm creating a number of records for the same table in each function using the factory.
In my controller function, I have set a validation rule to check for an array of IDs if it exists in the database and when referring for some records using the array[0] or array[1] (in my test functions) and sending to the API endpoint, when the whole test run the response returns the validation error: ""errors": {
"items.0": [
"The selected items.0 is invalid."
],
"items.1": [
"The selected items1 is invalid."
]
}"
In my test function:
$products = Product::factory(5)->create();
// I am creating other products in the same class and other testing classes
$order = [
'name' => $this->faker->name(),
'email' => $this->faker->email(),
'address' => $this->faker->address(),
'paymentMethod' => PayPalService::PAYMENT_METHOD,
'items' => [
['id' => $products[0]->id, 'quantity' => 2],
['id' => $products[1]->id, 'quantity' => 1]
]
];
The validation rule is : 'items.*' => [Rule::exists('products', 'id')],
It seems it is related to the state of the database when refreshing, some other testing classes or functions are changing the state which deletes other states and gives like the created records in the factory doesn't exist anymore.
Beta Was this translation helpful? Give feedback.
All reactions