Example project illustrating comet abilities.
> Introduction ..................................................................... > Setup ............................................................................ > Testing .......................................................................... > Documentation ....................................................................
This project contains the implementation of a simple Laravel example RESTful API for travel books. We have several different models: countries, languages, authors and books. Travel books are written by one author, in one language, for one country. Some endpoints allow additional filtering or including of relationships.
The different API routes and their parameters are:
# Countries
GET /countries{?include}
GET /countries/{code}{?include}
POST /countries
PATCH /countries/{code}
DELETE /countries/{code}
# Languages
GET /languages{?include}
GET /languages/{id}{?include}
POST /languages
PATCH /languages/{id}
DELETE /languages/{id}
# Authors
GET /authors{?filter[name],include}
GET /authors/{id}{?include}
POST /authors
PATCH /authors/{id}
DELETE /authors/{id}
# Books
GET /books{?filter[title],filter[publisher],filter[author],filter[country],filter[language],include}
GET /books/{id}{?include}
POST /books
PATCH /books/{id}
DELETE /books/{id}
After cloning the repository, initialize the project with:
cp .env.example .env
composer install
php artisan key:generate
php artisan migrate --seed
yarn # or npm install
When using Homestead (recommended), don't forget to update your site configuration and add an entry to your local hosts file.
For this relatively simple API with 20 endpoints, Comet is able to generate 112 test-cases.
By executing npx comet make:tests specification.yml
all test-cases will be generated. What this does is:
- Add a Comet test suite to your
phpunit.xml
file, if not already present. - Add the necessary dependencies to your
composer.json
(Make sure to runcomposer install
afterwards). - Generate the hook trait and the actual test cases (@
tests/Comet
) To execute the tests, runmake test
. In order to generate a code-coverage report, runmake code-coverage
.
Coming soon.