Download the PHP package edmondscommerce/behat-db-context without Composer
On this page you can find all versions of the php package edmondscommerce/behat-db-context. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download edmondscommerce/behat-db-context
More information about edmondscommerce/behat-db-context
Files in edmondscommerce/behat-db-context
Package behat-db-context
Short Description A Behat Context for managing the testing database
License MIT
Homepage https://www.edmondscommerce.co.uk
Informations about the package behat-db-context
Behat DB Context
By Edmonds Commerce
A Behat context for managing your testing database.
Installation
Install via composer
"edmondscommerce/behat-db-context": "dev-master@dev"
Include Context in Behat Configuration
Features
Ensures You're Using the Testing Database
The context employs platform detection to ensure that your application is currently using
the test database you configured in behat.yml
using databaseName
.
If you're not using the correct database then you'll receive an exception and the tests won't proceed.
To add support for you're platform you can follow the steps detailed below in the 'Adding Support For New Platforms' section.
Import Fresh Testing Database
The context imports a fresh version of the testing database each time you run your test
suite. It imports the SQL dump configured in your behat.yml
using pathToSqlDump
and
imports this into the database databaseName
.
NOTE: this context assumes you have your MYSQL credentials configured in .my.cnf
.
Optional Testing Database Import
When importTestingDatabase
is set to false
the import step will be skipped. This is useful
while working on the tests locally but should always be set to true
when finally running
the test suite.
Even when this is set to false
the check to confirm you're using the correct database
and your custom assertions (see below) will still be run to ensure everything is
configured correctly.
Custom Assertions
In order to flexibly confirm the database is in the correct state the context supports
custom assertions. These are simple COUNT
SQL queries which need to return 1
in order
to pass. You can provide as many of these as you like.
For example:
Adding Support For New Platforms
All platform code is contained within the Platform class. In order to extend this you need to provide two functions; one which handles platform detection and one which handles database detection.
Platform Detection
Add Detection Method
You need to add a method that can detect the platform from the project root. The Magento platform detection
simply does this by looking for local.xml
:
Add Method to Detect
You then need to add this to the detect method:
And add your platform as a constant:
Database Detection
Now that you have platform detection in place you need to handle database configuration detection.
Add Assertion Method
You need to add a method that can assert that the platforms database is currently configured to use the testing database. If the platform isn't configured correctly it should throw an exception.
Here's the Magento 1 assertion for example:
Add Method to Assert
You then need to add this platform specific assertion to the generic assertion method:
Your platform is now supported!