I’m trying to do testing on a Laravel application using Phpunit and data provider (I want to test for each field being wrong, so I thought it would be awesome to use a Data Provider)
However, I can’t manage to get it to work, it always gives me this error
Argument #2 ($code) must be of type int, string is given
Here is the code I used (redacted)
Test Function
/**
* @dataProvider invalidAddress
*/
public function test_admin_cannot_create_client_with_invalid_address_data($invalidAddressData,$errors){
$this->actingAs(AppModelsUser::factory()->create());
Livewire::test(ClientResourcePagesCreateClient::class)
->fillForm($invalidAddressData)
->call('create')
->assertHasFormErrors($errors);
}
The function that generates the data
private function getFormDataForInvalidAddress(string $field, string | int $value, string $rule = ''): array
{
$record = $this->client->getAttributes();
......
return [$record, $rules];
}
Data Provider
public function invalidAddress(): array
{
$this->setUp();
return [
'missing street' => self::getFormDataForInvalidAddress('street', '', 'required'),
'missing postal code' => self::getFormDataForInvalidAddress('postalCode', '', 'required'),
'too long postal code' => self::getFormDataForInvalidAddress('postalCode', '888888888'),
'non-numeric postalCode' => self::getFormDataForInvalidAddress('postalCode', 'aaaaa'),
];
}
Really, I can’t figure out what I’m doing wrong. It seems all okay to me, any advice on how I can debug this?