tyler36 / cypress-cake
Cypress plugin for CakePHP
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:cakephp-plugin
Requires
- php: ^7.4|^8.1
- vierge-noire/cakephp-fixture-factories: ^2.5|^3.0
This package is auto-updated.
Last update: 2025-03-21 07:04:36 UTC
README
Overview
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-cake
endpoints. - This plugin bypasses
Authentication
oncypress-cake
endpoints.
Important
This plugin exposes an API to work with the database. It is recommend for local development only. Do not use in production!
Installation
-
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.js
to import the helpersimport '../../vendor/tyler36/cypress-cake/src/support/cypress-commands'
Helpers
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. |
Clear Database
Use the Cypress command cy.clearDatabase()
to clear all data from database.
cy.clearDatabase()
Import Database
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')
Create An Entity
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' })
Run Arbitrary Cake Command
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')
Contributing
PRs, especially with tests, will be considered.
Contributed and maintained by tyler36