vgirol/formrequest-tester

Tools to test Laravel FormRequest

v1.1.0 2020-11-19 10:39 UTC

This package is auto-updated.

Last update: 2021-01-19 10:57:50 UTC


README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Infection MSI Total Downloads

This package provides a set of tools to test Laravel FormRequest. It is strongly inspired by the package mohammedmanssour/form-request-tester.

Technologies

  • PHP 7.3+
  • Laravel 6+

Install

To install through composer, simply put the following in your composer.json file:

{
    "require-dev": {
        "vgirol/formrequest-tester": "dev-master"
    }
}

And then run composer install from the terminal.

Quick Installation

Above installation can also be simplified by using the following command:

$ composer require vgirol/formrequest-tester

Usage

Assertions can be chained :

use App\Requests\DummyFormRequest;
use Orchestra\Testbench\TestCase;
use VGirol\FormRequestTesterer\TestFormRequests;

class FormRequestTester extends TestCase
{
    use TestFormRequests;

    /**
     * @test
     */
    public function myFirtsTest()
    {
        // Creates a form
        $form = [
            'data' => [
                'type' => 'dummy',
                'attributes' => [
                    'attr' => 'value'
                ]
            ]
        ];

        // Create and validate form request for DummyFormRequest class
        $this->formRequest(
            DummyFormRequest::class,
            $form,
            [
                'method' => 'POST',
                'route' => '/dummy-route'
            ]
        )->assertValidationPassed();
    }
}

Documentation

The API documentation is available in XHTML format at the url http://formrequest-tester.girol.fr/docs/ref/index.html.

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

composer test

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

Security

If you discover any security related issues, please email vincent@girol.fr instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.