This add-on adds some helper files for working with Cypress and CakePHP.
- This plugin injects a CSRF token into POST requests made to
cypress-cakeendpoints. - This plugin bypasses
Authenticationoncypress-cakeendpoints.
Important
This plugin exposes an API to work with the database. It is recommend for local development only. Do not use in production!
-
Install plugin
ddev composer require tyler36/cypress-cake ddev cake plugin load Tyler36/CypressCake
-
Install Cypress if not available. Eg.
- via NPM:
npm require cypress - via tyler36/ddev-cypress:
ddev addon get tyler36/ddev-cypress
- via NPM:
-
Update
cypress/support/commands.jsto import the helpersimport '../../vendor/tyler36/cypress-cake/src/support/cypress-commands'
| API | Description |
|---|---|
/cypress/clear-database |
Clear all data from database. |
/cypress/import-database |
Import a database file. |
/cypress/csrf-token |
Get a CSRF token. This is required POST forms. |
/cypress/create |
Run a factory to generate a entity. |
/cypress/cake |
Run arbitrary cake commands. |
Use the Cypress command cy.clearDatabase() to clear all data from database.
cy.clearDatabase()Use cy.importDatabase() to import a SQL file.
By default, this it will import a file located at env('SQL_TESTING_BASE_DUMP'), relative to the root.
However, you can provide a path as the first parameter.
// Import `env('SQL_TESTING_BASE_DUMP')` database file.
cy.importDatabase()
// Import '/tmp/test.sql'.
cy.importDatabase('/tmp/test.sql')Use cy.create('User') to generate an entity from a configured factory.
This packages expects to find vierge-noire/cakephp-fixture-factories factories. Please see their documentation for creating factories.
cy.create('User')It is possible to pass additional attributes to the factory allowing to to set default data.
For example, the following creates a User entity with the email set to foobar@example.com.
cy.create('User', { email: 'example@example.com' })Post a request to /cypress/cake to run CakePHP commands.
# To get CakePHP version
cy.cake('version')
# To clear all caches
cy.cake('cache clear_all')PRs, especially with tests, will be considered.
Contributed and maintained by tyler36