blok / laravel-mock
An easy mock api helper that simulate GET, PUT, DELETE, POST requests in a json folder
Requires
- php: >=7.0
- laravel/framework: ^5.5|^5.6|^5.7|^5.8|^6.0|^7.0
Requires (Dev)
- phpunit/phpunit: ~7.0
This package is auto-updated.
Last update: 2024-11-24 17:06:34 UTC
README
A simple mock api helper that simulate GET, PUT, DELETE, POST requests and store it to a json folder.
Installation
Install via composer
composer require blok/laravel-mock
Register Service Provider
Note! This and next step are optional if you use laravel>=5.5 with package auto discovery feature.
Add service provider to config/app.php
in providers
section
Blok\Mock\ServiceProvider::class,
Register Facade
Register package facade in config/app.php
in aliases
section
Blok\Mock\Facades\Mock::class,
Publish Configuration File
php artisan vendor:publish --provider="Blok\Mock\ServiceProvider" --tag="config"
Usage
Folder mode
Let's say that you have this in your mock folder
storage/mock
|- users
|-- 1.json
|-- 2.json
If you make that requests :
GET /mock/users it will return :
[
{
"1" : {
"id" : 1,
"name" : "foo"
}
},
{
"2" : {
"id" : 2,
"name" : "bar"
}
}
]
GET /mock/users/1 will return :
{
"id" : 1,
"name" : "foo"
}
PUT /mock/users/1 will save your request into /mock/users/1.json
DELETE /mock/users/1 will delete your request in /mock/users/1.json
Factory mode
If you see the config/mock.php you will see a commented array in entrypoints.
If you uncommented that you will be able to call your factory for the model you want.
=> if enabled it will return mock data from your factories instead from json.
Test a FormRequest or mock a validation
You can easily test your FormRequest or Validation by adding in the entrypoint "$action$_validation" in your config file => it could receive an array or a FormRequest.
Force to json
By default, the config will only accept json request, but if you want for some reason disable or test a redirection instead. You can do it in your config file (at a global or in the method level of the controller).
Security
If you discover any security related issues, please email me instead of using the issue tracker.
Credits
This package is bootstrapped with the help of blok/laravel-package-generator.