- Tests properties
- Tests functions
- Create live Testing Data
- Debugging with PsySH
Apiato provides additional helper functions, on top of the Laravel's default Tests, to make testing your API much faster and fun.
Writing functional tests, makes implementing, debugging and modifying a feature faster.
With Apiato you just prepare the data you want to send for your POST request, call the
makeCall() function and start
asserting the response. Everything else is set for you. There are helper functions to create and prepare a testing user
with the right authorization (roles and permissions) for each request.
Some test helper functions read your test class properties, to perform their jobs. below we will see those properties and who uses them:
$endpoint = '[email protected]'; property is where you define the endpoints you are trying to access when calling
endpoint property value in some test functions#
$auth = false; property defines if the endpoint you are trying to call requires authentication or not. By default
$auth is equal to true, also when not defined on your test class it will be defaulted to true.
$auth is true, the
makeCall() will create a testing user if none already found, and it will inject his access
token in the headers, before making the call.
So only use this property when your endpoint is not protected, for example the register and login tests.
auth property value in some test functions#
$access property is where you define the permissions/roles that you need to give to your testing users in that
test class. So when using
$user = $this->getTestingUser(); it will automatically take all the roles and permissions
you gave him.
access property value in some test functions#
getTestingUser and pass roles and permissions as the second argument.
Or you can call
getTestingUserWithoutAccess() to get user without permissions and roles.
All the test helper functions are provided by traits are living inside
vendor/apiato/core/Traits/TestsTraits/PhpUnit/* folder,and they are all
available for usage from every test class in your application.
makeCall(array $data = , array $headers = ) is one of the most important helper functions for an API.
getTestingUser($userDetails = null, $access = null) is another very important helper function:
Just use it from any test:
There's an instance of faker in every class.
Just use it:
See the Tests Page, for more details about the Tests components.
To test your app with some live testing data (like creating items in an inventory) you can use this feature to automatically generate those data. This is also helpful for staging when real people are testing your app with some testing data.
app/Ship/Seeder/SeedTestingData.phpseeder class, and create your live testing data.
Run this command
php artisan apiato:seed-test
For better debugging and development, you can open a runtime developer console while executing your test.
Using PsySH (interactive debugger and REPL "read-eval-print loop" for PHP). The package is required by the Laravel Tinker Package.
To use it set the breakpoint
eval(\Psy\sh()); anywhere you want in any Actions, Controllers, Tasks... and run your