Skip to content

Latest commit

 

History

History
50 lines (35 loc) · 1008 Bytes

File metadata and controls

50 lines (35 loc) · 1008 Bytes

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