Skip to content

Latest commit

 

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

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

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages