Skip to content

Commit 49d3aa1

Browse files
committed
added json based configuration, rabbitmq wip
1 parent 7cfca0c commit 49d3aa1

21 files changed

+416
-129
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"pdo": {
3-
"dsn": "mysql:host=mariadb;dbname=content;charset=utf8",
3+
"dsn": "mysql:host=localhost:3306;dbname=test;charset=utf8",
44
"user": "test",
55
"password": "test",
66
"fixtures": {
@@ -21,7 +21,7 @@
2121
}
2222
},
2323
"amqp": {
24-
"host": "rabbitmq",
24+
"host": "localhost",
2525
"port": 5672,
2626
"user": "test",
2727
"password": "test",

.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 unit
24+
- make 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>

resources/jsonschema/integration-testing.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"default": {},
1414
"examples": [
1515
{
16+
1617
"extension": "sql",
1718
"path": "tests/fixtures/before-first-test"
1819
}

src/Driver/FileSystem.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,36 @@ class FileSystem
1111
{
1212
/**
1313
* @param string $path
14-
* @param string $extension
15-
* @return Iterator
14+
* @return string
1615
* @throws TestingException
1716
*/
18-
public static function getFileListIteratorFromPathByExtension(string $path, string $extension): Iterator
17+
private function getRealPath(string $path): string
1918
{
2019
$realPath = realpath($path);
2120
if (!$realPath) {
2221
throw new TestingException("The path [$path] is not valid");
2322
}
24-
$iterator = new FilesystemIterator($realPath);
23+
return $realPath;
24+
}
25+
26+
public function getFileContents(string $path): string
27+
{
28+
$path = $this->getRealPath($path);
29+
if (!is_readable($path)) {
30+
throw new TestingException("Filepath [$path] is not readable");
31+
}
32+
return file_get_contents($path);
33+
}
34+
35+
/**
36+
* @param string $path
37+
* @param string $extension
38+
* @return Iterator
39+
* @throws TestingException
40+
*/
41+
public function getFileListIteratorFromPathByExtension(string $path, string $extension): Iterator
42+
{
43+
$iterator = new FilesystemIterator($this->getRealPath($path));
2544
$fileList = new ArrayIterator();
2645
foreach ($iterator as $path => $fileInfo) {
2746
if ($fileInfo->isFile() && $fileInfo->isReadable() && $fileInfo->getExtension() === $extension) {
@@ -35,7 +54,7 @@ public static function getFileListIteratorFromPathByExtension(string $path, stri
3554
* @param Iterator $iterator
3655
* @param callable $callback
3756
*/
38-
public static function runCallbackOnEachFileIteratorContents(Iterator $iterator, callable $callback): void
57+
public function runCallbackOnEachFileIteratorContents(Iterator $iterator, callable $callback): void
3958
{
4059
foreach ($iterator as $filePath) {
4160
$callback(file_get_contents($filePath));

0 commit comments

Comments
 (0)