"Swapi package" is a simple wrapper package that provide the list of people and the information related to a planet accessible using the following APIs:
- GET /api/people (Provide a paginated list of people, filterable and orderable)
- GET /api/people/{peopleId} (Provide selected people data including planet details)
Laravel 8.*
guzzlehttp/guzzle
phpunit/phpunit
inertiajs/inertia-laravel
To install Swapi package run this command:
composer require christiancocco/swapi --with-all-dependenciesNow you can configure testing environment file to be able to run test script.
- Create testing DB
- Create .env.testing file in your root application folder and change DB connection parameter
- Add following to phpunit.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<!-- ... -->
<testsuites>
<!-- ... -->
<testsuite name="SwapiUnit">
<directory suffix="Test.php">./vendor/christiancocco/swapi/tests/Unit</directory>
</testsuite>
<testsuite name="SwapiTest">
<directory suffix="Test.php">./vendor/christiancocco/swapi/tests/Feature</directory>
</testsuite>
</testsuites>
After installation you have to run the following command:
php artisan swapi:installThis command initialize package (copy configuration file) and run migration for planet and people table.
php artisan swapi:initThis command initialize data retrieved data from swapi.dev.
(Full documentation: https://swapi.dev/documentation)
NB. To initialize testing database run this command:
php artisan migrate --env=testingIf you want to filtering, ordering and paging /api/people result you can use this querystring parameter:
- query: string to search in all people fields
- itemperpage: item per page (default value = 10)
- page: page number
- sort: sorting field
- sortVer: sorting versus (ASC: ascending - default value; DESC: descending)
Example: /api/people?query=fair&sort=name&sortVer=DESC&itemperpage=2&page=2
To launch the Unit Test run this command:
php artisan test --filter=Swapi --stop-on-failureTo test api run
php artisan serveand visit
http://localhost:8000/swapi-test
The Swapi Laravel package is open-sourced software licensed under the MIT license.