'Laravel test how to find which assertion count failed
im using Illuminate\Foundation\Testing\TestCase class for my feature tests.
My test looks like this:
public function test_cant_store_category()
{
$params = [
'name' => [
true, false, null, 1, 0, 123, '@', '~', '<input>', 'UNION 1=2', "'1'=1`", ['canIPostArrayHere', 'canIPostArrayHereTwo']
],
'owner' => [
true, false, null, 1, 0, 123, '@', '~', '<h1>', 'UNION 1=3', "'2'=2`", 'ticke', 'fa', 'servic', ['canIPostArrayHere', 'canIPostArrayHereTwo']
],
'description' => [
true, false, null, 1, 0, 123, 05555555555, '@', '~', '<h2>', "UNION 1=4", "'3' = 3`", ['canIPostArrayHere', 'canIPostArrayHereTwo']
],
'category' => [
'id' => [
"String", true, null, false, 0, 1, ['canIPostArrayHere', 'canIPostArrayHereTwo']
]
]
];
foreach ($params as $value) {
try {
$this->actingAs($this->actionUser())
->withHeaders($this->headers)
->postJson('myendpoint/', $value)
->assertStatus(422)
->assertJsonStructure(['errors'])
->assertJsonCount(4, ['errors']);
} catch (\Throwable $th) {
dd($value);
}
}
}
As you can see, I create an array to try post some invalid datas and I assert that count will match the error message. But in this array, some datas will be accept for my request, so i want to catch this datas but I cant find.
Anyone has some idea how can I catch this unwanted datas? I get bored to try each field on postman. It must be an easier way, right?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
