Download the PHP package romegasoftware/nova-test-suite without Composer
On this page you can find all versions of the php package romegasoftware/nova-test-suite. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download romegasoftware/nova-test-suite
More information about romegasoftware/nova-test-suite
Files in romegasoftware/nova-test-suite
Package nova-test-suite
Short Description Library to help testing laravel nova resources faster
License MIT
Informations about the package nova-test-suite
Nova Test Suite
Install
composer require romegasoftware/nova-test-suite --dev
Usage
Generate Resource Test Cases
To get you started run php artisan nova:test resource_name
. This will generate a Resource test and publish the NovaResourceTestCase
if it was not already published.
First thing you will need to do after creating a resource tests is filling the remapResource()
method. This method must map the nova fields names to
the resource properties. It's also not needed to map each property of the resource, just the ones that change or are required to be diferent.
The $resource
parameter is a fresh generated model instance via factory()
and therefore should hold any necessary values you need. The $data
parameter is only filled if you call a nova request method with any data like $this->storeResource(['name' => 'test'])
.
requests
get resources
store resources
If a resource is stored successfully the returned status code of the response is 201
.
update resources
delete resources
relationships
assertHasOneRelationships(array)
assertHasManyRelationships(array)
assertBelongsToRelationships(array)
assertBelongsToManyRelationships(array)
assertMorphToRelationships(array)
assertMorphOneRelationships(array)
assertMorphManyRelationships(array)
actions
Use assertHasActions()
lenses
use assertHasLenses()
filters
use assertHasFilters()
Asserting a request has failed
Since failed nova request return a redirect with status code 301
we introduced a new method assertNovaFailed()
which checks for this without having to think about what status code a failed nova response returns.
Testing required fields
To test if your Nova resource is setup correctly and check if all required fields are set as expected you can use the setNullValuesOn([..])
method, which assignes every key you enter a null
value for the next request.
Using the default user
By default each nova request method checks whether a request was already authenticated through actingAs($user, 'api')
. If no user was provided to authenticate the request we will use the getDefaultUser()
method to authenticate your request. If you want to be explicit about using the default user for a request you can use $this->beDefaultUser()
which will return the current class, therefore it will also work with chaining e.g. $this->beDefaultUser()->storeResource()
.
If you want to use your own user for every request you can override the getDefaultUser()
method.
Debugging failing requests
To debug more easily why your nova request is failing you can chain assertSessionDoesntHaveErrors()
before you make any assertions about the status. This method will dump all session errors and the json response of the request.
If you still can't figure out why you are receiving the status code of the response, try to get behind the reason of the response with withoutNovaExceptionHandling()
. This method call will create a callback which calls the underlying withoutExceptionHandling()
as soon as the Nova middleware runs. You can also chain the calls:
Testing
Run the tests with:
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Credits
Security
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.
All versions of nova-test-suite with dependencies
ext-json Version *
illuminate/support Version *
illuminate/filesystem Version *
illuminate/testing Version *
illuminate/contracts Version *