Download the PHP package hrodic/php-integration-testing without Composer
On this page you can find all versions of the php package hrodic/php-integration-testing. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hrodic/php-integration-testing
More information about hrodic/php-integration-testing
Files in hrodic/php-integration-testing
Package php-integration-testing
Short Description Integration testing library for PHP
License MIT
Informations about the package php-integration-testing
PHP Integration Testing
Integration testing library in PHP for databases and other common infrastructure related tests.
It is developed as a set of extensions for PHPUnit that hooks on different events and executes your fixtures.
Currently you can run custom fixtures on the following PHPUnit hooks:
- BeforeFirstTest
- BeforeTest
- AfterTest
- AfterLastTest
Road map
- WIP: AMQP specific test fixtures with WithBeforeTestFixtureName and WithAfterTestFixtureName
Requirements
Installation
Via composer
Configuration
On PHPUnit configuration XML file you must specify the extension with its configuration.
You are able to specify the configuration filename that you will be using. Defaults to .integration-testing.json
You also check phpunit-integration.xml.dist example
If you need help with PHPUnit extensions, please refer to the Official Documentation
PDO Fixtures
If you need to test the integration of MySQL or MariaDB, use the PDO driver extension.
It requires configuration parameters that can be found in the json config file.
The most important parameters are DSN, username and password of your database + some fixture path definitions.
Example:
AMQP fixtures
You can also try out AMQP (tested on RabbitMQ) fixtures and operations.
Configure your connectivity and the hook operations using the configuration file.
Notes:
- Hook definitions are optional, so just configure the ones you need.
- You can only publish messages on
beforeFirstTest
and onbeforeTest
. - You can purge queues in all four hooks.
- file extension of message bodies to publish defaults to
json
- use
routing_key
if you have your exchange configured asdirect
. You can define it as empty string iffanout
Fixture creation
A PDO fixture is just an SQL file.
All the fixtures located in a specific hook category will be executed in order and inside a transaction.
How you create the SQL and the integrity of the database in each stage is up to you. The library does not force you to follow any convention although is common to setup fixtures at the beginning and clean your mess after each test.
You can create, insert, delete or whatever you configure your user to do. Remember, your testing database must be isolated from any real database!
All four fixture hook types could be placed in the directory that you prefer.
For BeforeTest and AfterTest hooks, which occur in every specific test, you can also provide specific fixtures to be executed just after the generic Before and After fixtures by implementing the interfaces WithBeforeTestFixtureName and/or WithAfterTestFixtureName.
The Extension will check if the methods are defined, and use them to locate subdirectories inside the main BEFORE_TEST_PDO_FIXTURES_PATH and AFTER_TEST_PDO_FIXTURES_PATH directories.
Execution flow
If you take a look onto the tests/fixtures folder, you will see an example on how you can organize your fixtures. You can have multiple SQL files and the extension will read and execute them in order.
Troubleshooting
Integration testing requires some infrastructure to be in place.
This library assumes (you can check docker-compose.yml file for inspiration) that you have an accessible database or other infrastructure already in place and the database is created.
All versions of php-integration-testing with dependencies
ext-json Version *
ext-pdo Version *