Skip to content

Commit

Permalink
1.x dev (#3)
Browse files Browse the repository at this point in the history
* wip

* added json based configuration, rabbitmq wip

* fix travis
  • Loading branch information
hrodic authored Apr 25, 2020
1 parent 36389e0 commit 8d96998
Show file tree
Hide file tree
Showing 21 changed files with 1,015 additions and 127 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
/build/
composer.lock
.php_cs.cache
phpunit.xml
phpunit.xml
.phpunit.result.cache
69 changes: 69 additions & 0 deletions .integration-testing.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"pdo": {
"dsn": "mysql:host=localhost:3306;dbname=test;charset=utf8",
"user": "test",
"password": "test",
"fixtures": {
"beforeFirstTest": {
"path": "tests/fixtures/before-first-test",
"extension": "sql"
},
"beforeTest": {
"path": "tests/fixtures/before-test",
"extension": "sql"
},
"afterTest": {
"path": "tests/fixtures/after-test"
},
"afterLastTest": {
"path": "tests/fixtures/after-last-test"
}
}
},
"amqp": {
"host": "localhost",
"port": 5672,
"user": "test",
"password": "test",
"vhost": "test",
"fixtures": {
"beforeFirstTest": {
"purgeQueues": [
"test-queue"
],
"publishMessages": [
{
"exchange": "test-exchange",
"queue": "test-queue",
"routing_key": "before-first-test",
"path": "tests/fixtures/before-first-test",
"extension": "json"
}
]
},
"beforeTest": {
"purgeQueues": [
"test-queue"
],
"publishMessages": [
{
"exchange": "test-exchange",
"queue": "test-queue",
"routing_key": "before-test",
"path": "tests/fixtures/before-test"
}
]
},
"afterTest": {
"purgeQueues": [
"test-queue"
]
},
"afterLastTest": {
"purgeQueues": [
"test-queue"
]
}
}
}
}
1 change: 0 additions & 1 deletion .phpunit.result.cache

This file was deleted.

10 changes: 4 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ cache:
directories:
- $HOME/.composer/cache

env:
global:
- PHPUNIT_FLAGS='--testdox --verbose'

sudo: false

notifications:
Expand All @@ -21,6 +17,8 @@ matrix:
fast_finish: true

install:
- composer update
- make install

script: vendor/bin/phpunit $PHPUNIT_FLAGS
script:
- make test-unit
- make test-integration
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.PHONY : install beautify up down test-unit test-integration debug-test-integration
.DEFAULT : install

install:
composer install -o
beautify:
vendor/bin/phpcbf --standard=PSR2 src tests
up:
docker-compose up -d --build
down:
docker-compose down --remove-orphans
test-unit:
vendor/bin/phpunit --testdox --verbose --color
test-integration: up
sleep 20
@-vendor/bin/phpunit --color --testdox --verbose -c phpunit-integration.xml.dist
make down
debug-test-integration:
php -dxdebug.remote_mode=jit vendor/bin/phpunit --no-coverage --color --testdox --group debug -c phpunit-integration.xml.dist
86 changes: 32 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,78 +34,56 @@ composer require --dev hrodic/php-integration-testing

On PHPUnit configuration XML file you must specify the extension with its configuration.

If you need help with PHPUnit extensions, please refer to the [Official Documentation](https://phpunit.readthedocs.io/en/9.1/configuration.html#the-extensions-element)

As an example, look into phpunit-integration.xml.dist.


### PDO Driver

If you need to test the integration of MySQL or MariaDB, use the PDO driver extension.
You are able to specify the configuration filename that you will be using. Defaults to .integration-testing.json

```
<extensions>
<extension class="IntegrationTesting\PHPUnit\Runner\Extension\PDODatabaseExtension">
<extension class="IntegrationTesting\PHPUnit\Runner\Extension\Handler">
<arguments>
<object class="IntegrationTesting\PHPUnit\Runner\Extension\PDODatabaseExtensionConfig">
<arguments>
<array>
<element key="BEFORE_FIRST_TEST_PDO_FIXTURES_PATH">
<string>tests/fixtures/before-first-test</string>
</element>
<element key="BEFORE_TEST_PDO_FIXTURES_PATH">
<string>tests/fixtures/before-test</string>
</element>
<element key="AFTER_TEST_PDO_FIXTURES_PATH">
<string>tests/fixtures/after-test</string>
</element>
<element key="AFTER_LAST_TEST_PDO_FIXTURES_PATH">
<string>tests/fixtures/after-last-test</string>
</element>
</array>
</arguments>
</object>
<object class="IntegrationTesting\Driver\PDOConnection">
<arguments>
<string>mysql:host=localhost:3306;dbname=test;charset=utf8</string>
<string>test</string>
<string>test</string>
</arguments>
</object>
<string>.integration-testing.json</string>
</arguments>
</extension>
</extensions>
```

The extension class is
```
IntegrationTesting\PHPUnit\Runner\Extension\PDODatabaseExtension
```
You also check phpunit-integration.xml.dist example

which requires a configuration and a PDO connection as arguments via XML config

The configuration class allows you to define in which paths your fixtures will be located
If you need help with PHPUnit extensions, please refer to the [Official Documentation](https://phpunit.readthedocs.io/en/9.1/configuration.html#the-extensions-element)

```
IntegrationTesting\PHPUnit\Runner\Extension\PDODatabaseExtensionConfig
```
### PDO Fixtures

The config keys to define each hook type are:
If you need to test the integration of MySQL or MariaDB, use the PDO driver extension.

* BEFORE_FIRST_TEST_PDO_FIXTURES_PATH
* BEFORE_TEST_PDO_FIXTURES_PATH
* AFTER_TEST_PDO_FIXTURES_PATH
* AFTER_LAST_TEST_PDO_FIXTURES_PATH
It requires configuration parameters that can be found in the json config file.

The PDOConnection class is just a wrapper of the PDO PHP class.
The most important parameters are DSN, username and password of your database + some fixture path definitions.

Example:
```
IntegrationTesting\Driver\PDOConnection
"pdo": {
"dsn": "mysql:host=localhost:3306;dbname=test;charset=utf8",
"user": "test",
"password": "test",
"fixtures": {
"beforeFirstTest": {
"path": "tests/fixtures/before-first-test",
"extension": "sql"
},
"beforeTest": {
"path": "tests/fixtures/before-test",
"extension": "sql"
},
"afterTest": {
"path": "tests/fixtures/after-test"
},
"afterLastTest": {
"path": "tests/fixtures/after-last-test"
}
}
},
```

It requires DSN, username and password of your database.

### RabbitMQ driver
### RabbitMQ fixtures

@todo

Expand Down
28 changes: 2 additions & 26 deletions phpunit-integration.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,9 @@
</testsuite>
</testsuites>
<extensions>
<extension class="IntegrationTesting\PHPUnit\Runner\Extension\PDODatabaseExtension">
<extension class="IntegrationTesting\PHPUnit\Runner\Extension\Handler">
<arguments>
<object class="IntegrationTesting\PHPUnit\Runner\Extension\PDODatabaseExtensionConfig">
<arguments>
<array>
<element key="BEFORE_FIRST_TEST_PDO_FIXTURES_PATH">
<string>tests/fixtures/before-first-test</string>
</element>
<element key="BEFORE_TEST_PDO_FIXTURES_PATH">
<string>tests/fixtures/before-test</string>
</element>
<element key="AFTER_TEST_PDO_FIXTURES_PATH">
<string>tests/fixtures/after-test</string>
</element>
<element key="AFTER_LAST_TEST_PDO_FIXTURES_PATH">
<string>tests/fixtures/after-last-test</string>
</element>
</array>
</arguments>
</object>
<object class="IntegrationTesting\Driver\PDOConnection">
<arguments>
<string>mysql:host=localhost:3306;dbname=test;charset=utf8</string>
<string>test</string>
<string>test</string>
</arguments>
</object>
<string>.integration-testing.json</string>
</arguments>
</extension>
</extensions>
Expand Down
Loading

0 comments on commit 8d96998

Please sign in to comment.