Package to easily test crudable controllers for Laravel based API

Overview

Laravel Crudable Test

This package is very usefull to easily test crudable controllers.

Installation

You can install package via composer. Add repository to your composer.json

"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/mindz-team/laravel-crudable-test"
    }
],

And run

composer require mindz-team/laravel-crudable-test

Usage

This package contains command that creates crudable test to test crudable controller. It creates test class that extends Mindz\LaravelCrudableTest\Blueprints blueprint with test methods.

To create class by using this command you need to run

php artisan make:crudable-test Example

This command creates test class file in tests/Feature directory. Class name is based on controller name provided in command. You can use partial name like Example or full like ExampleController. After creation you can move class as you please, but remember to adjust namespace.

Remember that class will not be created if its already exists.

Test methods

By default command creates methods to test crudable index, show, store, update, destroy but not every crudable controller utilize all methods. To avoid empty tests you can adjust command to create only methods you need by using command options. Command below will create test class only with desired methods passed to --only option as comma separated values

php artisan make:crudable-test Example --only=index,show

To create methods by exclusion you can use --except option. This will creates test methods to all crudable functions but passed to options

php artisan make:crudable-test Example --except=destroy

Resources

By default crudable test class tests responses structure against Illuminate\Http\Resources\Json\JsonResource class you can indicate your own resource class for both - collection and single object resource.

protected function getCollectionResource(): ?string
{
    return SomeResource::class;
}

And for single object

protected function getResource(): ?string
{
     return SomeSingleObjectResource::class;
}

Important think to know is that getResource method has also influence to collection resource shape if getCollectionResource does not exists

Default headers

If your application requires additional headers when performing requests you can add globaly headers to all methods by using method defaultHeaders

protected function defaultHeaders(): array
{
    return [
        'Accept'=>'application/json'
    ];
}

User used to perform requests

By default user used to perform requests is created by user factory User::factory()->make(). If you like to modify it or add permissions on the fly or something else - you can use method getUser which should return class implementing Authenticable interface.

protected function getUser(): Authenticatable
{
    $user = User::factory()->create();
    $user->addRole('admin');

    return $user;
}

Change log

Please see CHANGELOG for more information what has changed recently.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

Author: Roman Szymański [email protected]

License

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

You might also like...
Lightflows Technical Test

Installation git clone composer install cp .env.example .env php artisan key:generate setup database in .env php artisan migrate --seed php artisan pa

🧾 Online test site with the human sciences theme. Using: HTML5, CSS3, Js., PHP7 and MySQL. 🚀
🧾 Online test site with the human sciences theme. Using: HTML5, CSS3, Js., PHP7 and MySQL. 🚀

form-ciencias-humanas 🚀 Technologies Lunacy HTML5 CSS3 PHP7 MYSQL Animate.css Illustrations from icons8: Earth care from Anna Antipina Earth and Moon

A package to easily make use of Iconic icons in your Laravel Blade views.
A package to easily make use of Iconic icons in your Laravel Blade views.

Blade Iconic A package to easily make use of Iconic icons in your Laravel Blade views. For a full list of available icons see the SVG directory. Iconi

A package to easily make use of Simple Icons in your Laravel Blade views.
A package to easily make use of Simple Icons in your Laravel Blade views.

Blade Simple Icons A package to easily make use of Simple Icons in your Laravel Blade views. For a full list of available icons see the SVG directory.

This package allows you to easily track your laravel jobs!
This package allows you to easily track your laravel jobs!

Trackable Jobs For Laravel This package allows you to track your laravel jobs! Using this package, you can easily persist the output and the status of

Zarinpal is a laravel package to easily use zarinpal.com payment services in your applications
Zarinpal is a laravel package to easily use zarinpal.com payment services in your applications

پکیج اتصال به درگاه پرداخت زرین پال zarinpal.com برای اتصال به درگاه پرداخت اینترنتی زرین پال و استفاده از api های آن می توانید از این پکیج استفاده کن

Smeify is a Stable Automated Solution for Airtime and Data businesses in Nigeria, this package helps you integrate smeify easily into your laravel application.

Smeify is a Stable Automated Solution for Airtime and Data businesses in Nigeria, this package helps you integrate smeify easily into your laravel application.

Laravel 5.* package to easily introduce a transformation layer for your data

Laraformer Laraformer is a laravel 5.* package that lets you easily introduce a transformation layer for your data. Laraformer (originated from Larave

A package to easily make use of SVG icons in your Laravel Blade views.
A package to easily make use of SVG icons in your Laravel Blade views.

Blade Icons A package to easily make use of SVG icons in your Laravel Blade views. Originally "Blade SVG" by Adam Wathan. Turn... !-- camera.svg --

Releases(1.0.1)
Owner
null
Laravel magical helpers such as Controllers / Requests / Models

Laravel Magic provides Abstract Controller, Model, generic Request, Traits, Exceptions and various middlewares in order to generate very easily and quickly API resources from scratch.

Dominique Vienne 1 Sep 1, 2022
A Laravel Wrapper for the CoinDCX API. Now easily connect and consume the CoinDCX Public API in your Laravel apps without any hassle.

This package provides a Laravel Wrapper for the CoinDCX API and allows you to easily communicate with it. Important Note This package is in early deve

Moinuddin S. Khaja 2 Feb 16, 2022
Need some filters? This package is based on the Repository Design Pattern to let you create specific queries easily.

DevMakerLab/Laravel-Filters Need some filters? This package is based on the Repository Design Pattern to let you create specific queries easily. Insta

DevMakerLab 19 Feb 20, 2022
Laravel-OvalFi helps you Set up, test, and manage your OvalFi integration directly in your Laravel App.

OvalFi Laravel Package Laravel-OvalFi helps you Set up, test, and manage your OvalFi integration directly in your Laravel App. Installation You can in

Paul Adams 2 Sep 8, 2022
⛽ Set of utilities to test Laravel applications powered by Octane.

⛽ Octane Testbench Set of utilities to test Laravel applications powered by Octane. Install Via Composer: composer require --dev cerbero/octane-testbe

Andrea Marco Sartori 35 Dec 7, 2022
Test your Laravel applications with phpspec

phpspec Laravel Extension phpspec extension for testing Laravel applications. Versions Depending on the version of Laravel and/or Phpspec you're using

Ben Constable 145 Sep 27, 2022
Laravel 2-Step Verification is a package to add 2-Step user authentication to any Laravel project easily.

Laravel 2-Step verification is a package to add 2-Step user authentication to any Laravel project easily. It is configurable and customizable. It uses notifications to send the user an email with a 4-digit verification code. Laravel 2-Step Authentication Verification for Laravel. Can be used in out the box with Laravel's authentication scaffolding or integrated into other projects.

Jeremy Kenedy 204 Dec 23, 2022
Easily add a full Laravel blog (with built in admin panel and public views) to your laravel project with this simple package.

Webdevetc BlogEtc - Complete Laravel Blog Package Quickly add a blog with admin panel to your existing Laravel project. It has everything included (ro

WebDevEtc. 227 Dec 25, 2022
Laravel-Mediable is a package for easily uploading and attaching media files to models with Laravel 5.

Laravel-Mediable Laravel-Mediable is a package for easily uploading and attaching media files to models with Laravel. Features Filesystem-driven appro

Plank Design 654 Dec 30, 2022
Laravel comments - This package enables to easily associate comments to any Eloquent model in your Laravel application

Laravel comments - This package enables to easily associate comments to any Eloquent model in your Laravel application

Rubik 4 May 12, 2022