Trait with some test utilities for testing up validation in your requests.
Download and copy the TestUtilites.php trait into tests/ folder of your Laravel project. It will test your requests against 422 response status and check the validation errors.
Use trait in your Test class
use Tests\TestUtilities;
class CreateAreaTest extends TestCase
{
use RefreshDatabase, TestUtilities;
// ..
}
/** @test */
public function should_validate_manager()
{
$this->actingAs(factory(User::class)->create(), 'api');
// Required
$this->fieldIsPresent('manager');
// Exists
$this->fieldValueIsInvalid('manager', 9999);
// Selected user has role => manager
$this->fieldValueIsInvalid('manager', factory(User::class)->create([
'role' => Role::CategoryManager
])->id);
}
- How to install
- Examples
- Docs
- Convert to composer package