Skip to content

MaTToX3/laravel-validation-test-utilities

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

Validation test utilities for Laravel

Trait with some test utilities for testing up validation in your requests.

Installation

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.

Usage

Use trait in your Test class

use Tests\TestUtilities;

class CreateAreaTest extends TestCase
{
    use RefreshDatabase, TestUtilities;
    
    // ..
}

Examples

/** @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);
}

TODO

  • How to install
  • Examples
  • Docs
  • Convert to composer package

About

Some utility methods I use in feature tests.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages