Giter Site home page Giter Site logo

laravel-test's Introduction

Laravel test

Setup Mysql db

Pull docker image and run a container

docker pull mysql:8.0.1
docker run --name mysql-local -e MYSQL_ROOT_PASSWORD={ROOT PASSWORD} -p 3306:3306 -d mysql:8.0.1
#docker ps -a
#docker exec -it mysql-local bash

Setup PhpMyAdmin (optional)

docker pull phpmyadmin/phpmyadmin:latest
docker run --name phpmyadmin-local -d --link mysql-local:db -p 8081:80 phpmyadmin/phpmyadmin
http://localhost:8081/

Update db credentials in .env file

  • DB_DATABASE
  • DB_USERNAME
  • DB_PASSWORD

Seed database

Put sql files in database/seeders/sql and run

php artisan db:seed

Usage

php artisan serve

Get active users, filtered by country

  • API queries and returns only active users
  • Accepts GET param country which is two-letter country code, by default AT
  • Loads relationships: user detail and country
GET http://localhost:8000/api/users
GET http://localhost:8000/api/users?country=at
GET http://localhost:8000/api/users?country=ru

Update user detail

  • API validates the payload
  • Checks user if exists
  • Checks user detail if exists
  • Checks if user detail id belongs for the user
PUT http://localhost:8000/api/users/6/details/5
{
    "id": 5,
    "user_id": 6,
    "citizenship_country_id": 1,
    "first_name": "Max",
    "last_name": "Mustermann",
    "phone_number": "00436645555555"
}

Delete user

  • API check if user exists and if the user has detail, deletes the user only if detail does not exist
  • API returns 409 HTTP Response code if the user has detail

To run tests:

vendor/bin/phpunit --filter test_user_is_deleted_when_user_detail_does_not_exist
vendor/bin/phpunit --filter test_user_is_not_deleted_when_user_detail_exist

Get all transactions

  • API returns all transactions from a source
  • Requires GET param source which can be either db or csv
GET http://localhost:8000/api/transactions?source=db
GET http://localhost:8000/api/transactions?source=csv

laravel-test's People

Watchers

Nik avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.