A sample RESTful API in Laravel with PHPunit test.

Overview

Laravel PHP Framework

URL

    | URI                                                                          | Action                           |
    |  ---------------------------------------------------------------------------:|---------------------------------:|
    | POST api/user/register                                                       | UserController@register          |
    | POST api/user/login                                                          | UserController@login             |
    | GET api/user/logout                                                          | UserController@logout            |
    | POST api/user/password/remind                                                | RemindersController@postRemind   |
    | GET|HEAD api/user/password/reset                                             | RemindersController@getReset     |
    | POST api/user/password/reset                                                 | RemindersController@postReset    |
    | GET|HEAD api/user/password/staus-code                                        | RemindersController@getStausCode |
    | GET api/user/status                                                          | UserController@status            |
    | GET api/user/{user}                                                          | UserController@show              |
    | PUT api/user/{user}                                                          | UserController@update            |
    | PATCH api/user/{user}                                                        | UserController@update            |
    | DELETE api/user/{user}                                                       | UserController@destroy           |
    |                                                                                                                 |
    | POST api/user/password/update                                                | UserController@postUserPasswordUpdate |                                |
    | POST api/user/profile/image                                                  | UserController@postUserImage     |
    | POST api/favorite                                                            | FavoriteController@store         |
    | GET api/favorite/count                                                       | FavoriteController@count         |
    | GET|HEAD api/favorites                                                        | FavoriteController@index         |
    | PUT api/favorites/{favorite}                                                  | FavoriteController@update        |
    | PATCH api/favorites/{favorite}                                                | FavoriteController@update        |
    | DELETE api/favorites/{favorite}                                               | FavoriteController@destroy       |

Register fields

'username' : 'required|unique:users',

'email' : 'required|unique:users|email',

'password' : 'required',

'fname' : 'required|min:3|max:30',

'lname' : 'required|max:20',

'address' : 'required|min:10',

Login

'username' : 'required',

'password' : 'required'

#Post image

'image': 'required'

#password

>'password':      'required|min:5'

>'passwordmatch': 'required|same:password|min:5'

#Post favorites:

'name':    'required|min:2'

'address': 'required|min:5'

'lat' :    'required'

'lng' :    'required'

#Update favorites

'name' :  'required|min:2'

Note: Laravel's PATCH and PUT request are just cheating, by adding a hidden field. Ex: <input type="hidden" name="_method" value="PATCH">. Laravel will create such a field automatically in all laravel's HTML forms. In postman you should point that the data you send is 'x-www-url-formurlencoded' for PATCH. Alternatively your can sent a POST request with an hidden field named _method and value PATCH.
You might also like...
PHPUnit to Pest Converter

PestConverter PestConverter is a PHP library for converting PHPUnit tests to Pest tests. Before use Before using this converter, make sure your files

Allows the running of PHPUnit within ExpressionEngine

EE Unit Tests EE Unit Tests is an Add-on for ExpressionEngine that allows developers to execute unit tests from the Command Line. EE Unit Tests uses P

PHP libraries that makes Selenium WebDriver + PHPUnit functional testing easy and robust
PHP libraries that makes Selenium WebDriver + PHPUnit functional testing easy and robust

Steward: easy and robust testing with Selenium WebDriver + PHPUnit Steward is a set of libraries made to simplify writing and running robust functiona

PHPUnit extension for database interaction testing.

This extension is no longer maintained DbUnit PHPUnit extension for database interaction testing. Installation Composer If you use Composer to manage

Mock implementation of the Translation package, for testing with PHPUnit

PoP Translation - Mock Mock implementation of the Translation package, for testing with PHPUnit Install Via Composer composer require getpop/translati

Magento PHPUnit Integration

Magento PHPUnit Integration Magento is a quite complex platform without built in unit test suite, so the code is not oriented on running tests over it

The objective of ParaTest is to support parallel testing in PHPUnit

The objective of ParaTest is to support parallel testing in PHPUnit. Provided you have well-written PHPUnit tests, you can drop paratest in your project and start using it with no additional bootstrap or configurations!

Report high memory usage PHPUnit tests: Managed by opg-org-infra & Terraform

phpunit-memory-usage Report high memory usage PHPUnit tests: Managed by opg-org-infra & Terraform Configuration Add into the phpunit.xml extensions se

PHPStan PHPUnit extensions and rules

PHPStan PHPUnit extensions and rules PHPStan PHPUnit This extension provides following features: createMock(), getMockForAbstractClass() and getMockFr

Owner
Fasil
Laravel fan
Fasil
Qase-phpunit - Qase TMS PHPUnit reporter.

Qase TMS PHPUnit reporter Publish results simple and easy. How to integrate composer require qase/phpunit-reporter Example of usage The PHPUnit report

Qase TMS 6 Nov 24, 2022
Mockery - Designed as a drop in alternative to PHPUnit's phpunit-mock-objects library

Mockery Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing framework. Its c

Mockery 10.3k Jan 1, 2023
vfsStream is a stream wrapper for a virtual file system that may be helpful in unit tests to mock the real file system. It can be used with any unit test framework, like PHPUnit or SimpleTest.

vfsStream vfsStream is a stream wrapper for a virtual file system that may be helpful in unit tests to mock the real file system. It can be used with

null 1.4k Dec 23, 2022
PHPUnit Application Architecture Test

PHPUnit Application Architecture Test Idea: write architecture tests as well as feature and unit tests Installation Install via composer composer requ

null 19 Dec 11, 2022
Very simple mock HTTP Server for testing Restful API, running via Docker.

httpdock Very simple mock HTTP Server for testing Restful API, running via Docker. Start Server Starting this server via command: docker run -ti -d -p

Vo Duy Tuan 4 Dec 24, 2021
The most powerful and flexible mocking framework for PHPUnit / Codeception.

AspectMock AspectMock is not an ordinary PHP mocking framework. With the power of Aspect Oriented programming and the awesome Go-AOP library, AspectMo

Codeception Testing Framework 777 Dec 12, 2022
:computer: Parallel testing for PHPUnit

ParaTest The objective of ParaTest is to support parallel testing in PHPUnit. Provided you have well-written PHPUnit tests, you can drop paratest in y

null 2k Dec 31, 2022
Rector upgrades rules for PHPUnit

Rector Rules for PHPUnit See available PHPUnit rules Install composer require rector/rector-phpunit Use Sets To add a set to your config, use Rector\P

RectorPHP 34 Dec 27, 2022
Add mocking capabilities to Pest or PHPUnit

This repository contains the Pest Plugin Mock. The Mocking API can be used in regular PHPUnit projects. For that, you just have to run the following c

PEST 16 Dec 3, 2022