Skip to content

Commit 8d96998

Browse files
authored
1.x dev (#3)
* wip * added json based configuration, rabbitmq wip * fix travis
1 parent 36389e0 commit 8d96998

21 files changed

+1015
-127
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
/build/
44
composer.lock
55
.php_cs.cache
6-
phpunit.xml
6+
phpunit.xml
7+
.phpunit.result.cache

.integration-testing.json

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
"pdo": {
3+
"dsn": "mysql:host=localhost:3306;dbname=test;charset=utf8",
4+
"user": "test",
5+
"password": "test",
6+
"fixtures": {
7+
"beforeFirstTest": {
8+
"path": "tests/fixtures/before-first-test",
9+
"extension": "sql"
10+
},
11+
"beforeTest": {
12+
"path": "tests/fixtures/before-test",
13+
"extension": "sql"
14+
},
15+
"afterTest": {
16+
"path": "tests/fixtures/after-test"
17+
},
18+
"afterLastTest": {
19+
"path": "tests/fixtures/after-last-test"
20+
}
21+
}
22+
},
23+
"amqp": {
24+
"host": "localhost",
25+
"port": 5672,
26+
"user": "test",
27+
"password": "test",
28+
"vhost": "test",
29+
"fixtures": {
30+
"beforeFirstTest": {
31+
"purgeQueues": [
32+
"test-queue"
33+
],
34+
"publishMessages": [
35+
{
36+
"exchange": "test-exchange",
37+
"queue": "test-queue",
38+
"routing_key": "before-first-test",
39+
"path": "tests/fixtures/before-first-test",
40+
"extension": "json"
41+
}
42+
]
43+
},
44+
"beforeTest": {
45+
"purgeQueues": [
46+
"test-queue"
47+
],
48+
"publishMessages": [
49+
{
50+
"exchange": "test-exchange",
51+
"queue": "test-queue",
52+
"routing_key": "before-test",
53+
"path": "tests/fixtures/before-test"
54+
}
55+
]
56+
},
57+
"afterTest": {
58+
"purgeQueues": [
59+
"test-queue"
60+
]
61+
},
62+
"afterLastTest": {
63+
"purgeQueues": [
64+
"test-queue"
65+
]
66+
}
67+
}
68+
}
69+
}

.phpunit.result.cache

Lines changed: 0 additions & 1 deletion
This file was deleted.

.travis.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ cache:
44
directories:
55
- $HOME/.composer/cache
66

7-
env:
8-
global:
9-
- PHPUNIT_FLAGS='--testdox --verbose'
10-
117
sudo: false
128

139
notifications:
@@ -21,6 +17,8 @@ matrix:
2117
fast_finish: true
2218

2319
install:
24-
- composer update
20+
- make install
2521

26-
script: vendor/bin/phpunit $PHPUNIT_FLAGS
22+
script:
23+
- make test-unit
24+
- make test-integration

Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.PHONY : install beautify up down test-unit test-integration debug-test-integration
2+
.DEFAULT : install
3+
4+
install:
5+
composer install -o
6+
beautify:
7+
vendor/bin/phpcbf --standard=PSR2 src tests
8+
up:
9+
docker-compose up -d --build
10+
down:
11+
docker-compose down --remove-orphans
12+
test-unit:
13+
vendor/bin/phpunit --testdox --verbose --color
14+
test-integration: up
15+
sleep 20
16+
@-vendor/bin/phpunit --color --testdox --verbose -c phpunit-integration.xml.dist
17+
make down
18+
debug-test-integration:
19+
php -dxdebug.remote_mode=jit vendor/bin/phpunit --no-coverage --color --testdox --group debug -c phpunit-integration.xml.dist

README.md

Lines changed: 32 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -34,78 +34,56 @@ composer require --dev hrodic/php-integration-testing
3434

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

37-
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)
38-
39-
As an example, look into phpunit-integration.xml.dist.
40-
41-
42-
### PDO Driver
43-
44-
If you need to test the integration of MySQL or MariaDB, use the PDO driver extension.
37+
You are able to specify the configuration filename that you will be using. Defaults to .integration-testing.json
4538

4639
```
4740
<extensions>
48-
<extension class="IntegrationTesting\PHPUnit\Runner\Extension\PDODatabaseExtension">
41+
<extension class="IntegrationTesting\PHPUnit\Runner\Extension\Handler">
4942
<arguments>
50-
<object class="IntegrationTesting\PHPUnit\Runner\Extension\PDODatabaseExtensionConfig">
51-
<arguments>
52-
<array>
53-
<element key="BEFORE_FIRST_TEST_PDO_FIXTURES_PATH">
54-
<string>tests/fixtures/before-first-test</string>
55-
</element>
56-
<element key="BEFORE_TEST_PDO_FIXTURES_PATH">
57-
<string>tests/fixtures/before-test</string>
58-
</element>
59-
<element key="AFTER_TEST_PDO_FIXTURES_PATH">
60-
<string>tests/fixtures/after-test</string>
61-
</element>
62-
<element key="AFTER_LAST_TEST_PDO_FIXTURES_PATH">
63-
<string>tests/fixtures/after-last-test</string>
64-
</element>
65-
</array>
66-
</arguments>
67-
</object>
68-
<object class="IntegrationTesting\Driver\PDOConnection">
69-
<arguments>
70-
<string>mysql:host=localhost:3306;dbname=test;charset=utf8</string>
71-
<string>test</string>
72-
<string>test</string>
73-
</arguments>
74-
</object>
43+
<string>.integration-testing.json</string>
7544
</arguments>
7645
</extension>
7746
</extensions>
7847
```
7948

80-
The extension class is
81-
```
82-
IntegrationTesting\PHPUnit\Runner\Extension\PDODatabaseExtension
83-
```
49+
You also check phpunit-integration.xml.dist example
8450

85-
which requires a configuration and a PDO connection as arguments via XML config
86-
87-
The configuration class allows you to define in which paths your fixtures will be located
51+
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)
8852

89-
```
90-
IntegrationTesting\PHPUnit\Runner\Extension\PDODatabaseExtensionConfig
91-
```
53+
### PDO Fixtures
9254

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

95-
* BEFORE_FIRST_TEST_PDO_FIXTURES_PATH
96-
* BEFORE_TEST_PDO_FIXTURES_PATH
97-
* AFTER_TEST_PDO_FIXTURES_PATH
98-
* AFTER_LAST_TEST_PDO_FIXTURES_PATH
57+
It requires configuration parameters that can be found in the json config file.
9958

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

61+
Example:
10262
```
103-
IntegrationTesting\Driver\PDOConnection
63+
"pdo": {
64+
"dsn": "mysql:host=localhost:3306;dbname=test;charset=utf8",
65+
"user": "test",
66+
"password": "test",
67+
"fixtures": {
68+
"beforeFirstTest": {
69+
"path": "tests/fixtures/before-first-test",
70+
"extension": "sql"
71+
},
72+
"beforeTest": {
73+
"path": "tests/fixtures/before-test",
74+
"extension": "sql"
75+
},
76+
"afterTest": {
77+
"path": "tests/fixtures/after-test"
78+
},
79+
"afterLastTest": {
80+
"path": "tests/fixtures/after-last-test"
81+
}
82+
}
83+
},
10484
```
10585

106-
It requires DSN, username and password of your database.
107-
108-
### RabbitMQ driver
86+
### RabbitMQ fixtures
10987

11088
@todo
11189

phpunit-integration.xml.dist

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,9 @@
2020
</testsuite>
2121
</testsuites>
2222
<extensions>
23-
<extension class="IntegrationTesting\PHPUnit\Runner\Extension\PDODatabaseExtension">
23+
<extension class="IntegrationTesting\PHPUnit\Runner\Extension\Handler">
2424
<arguments>
25-
<object class="IntegrationTesting\PHPUnit\Runner\Extension\PDODatabaseExtensionConfig">
26-
<arguments>
27-
<array>
28-
<element key="BEFORE_FIRST_TEST_PDO_FIXTURES_PATH">
29-
<string>tests/fixtures/before-first-test</string>
30-
</element>
31-
<element key="BEFORE_TEST_PDO_FIXTURES_PATH">
32-
<string>tests/fixtures/before-test</string>
33-
</element>
34-
<element key="AFTER_TEST_PDO_FIXTURES_PATH">
35-
<string>tests/fixtures/after-test</string>
36-
</element>
37-
<element key="AFTER_LAST_TEST_PDO_FIXTURES_PATH">
38-
<string>tests/fixtures/after-last-test</string>
39-
</element>
40-
</array>
41-
</arguments>
42-
</object>
43-
<object class="IntegrationTesting\Driver\PDOConnection">
44-
<arguments>
45-
<string>mysql:host=localhost:3306;dbname=test;charset=utf8</string>
46-
<string>test</string>
47-
<string>test</string>
48-
</arguments>
49-
</object>
25+
<string>.integration-testing.json</string>
5026
</arguments>
5127
</extension>
5228
</extensions>

0 commit comments

Comments
 (0)