TestAPI module
This module contains dependencies, helpers and base classes for application tests.
Add tests to your modules!
Module tests should live in the module that provides the functionality that needs testing. Add tests to the Tests dir in your module, eg Modules/ExampleModule/Tests.
- PHP tests should be within a
UnitorFeaturedir and ideally nested within a sub dir under that based on type. Eg.Modules/ExampleModule/Tests/Unit/Service/MyServiceTest.php. As long as your test file is inModules/ExampleModule/Testsand ends withTest.phpit should get detected. - Cypress tests MUST be in
Modules/ExampleModule/Tests/Integrationand end inspec.jsfor them to be detected. Cypress tests calling seeders that live in that module need to supply full namesapce with\escaped. eg.cy.seed("Modules\\Example\\Database\\Seeders\\ExampleDatabaseSeeder")
Testing components supplied by a module.
Using the base theme to serve dynamic components so they can be tested.
- Create controller in your module, eg
class CypressTestController extends CypressController - Add a method like so:
public function myComponent(): Response { return Inertia::render(CypressController::DYNAMIC_COMPONENT_PAGE, [ 'component' => 'my-module-vue-component', 'componentProps' => [ 'foo' => 'bar' ], ]); } - Add
routes/tests.phpto your module. NOTE: alltestsroute paths will start with/__test__and route name will be prefixed withtest. - In the cypress integration,
cy.visit({route: 'test.my.route.name'})
Base Test Class
All PHP tests should extend Modules\TestApi\Tests\TestCase
Request Mocking
This includes a dependency for Request Factories which are great for mocking requests.
Trait setUp methods
A test trait can provide a method that gets called in setUp automatically by using the naming convention camelTraitNameSetUp. Eg adding a trait MyTestTrait to your test and if it contains the method myTestTraitSetUp then that will get called in the test setup.