Skip to content

Commit c650ccf

Browse files
authored
Merge pull request #9 from hrodic/1.x-dev
1.x dev
2 parents 7643b64 + a7ae457 commit c650ccf

14 files changed

+419
-102
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ install:
3131
script:
3232
- make test-unit
3333
- make test-integration
34-
- make merge-coverage
3534

3635
after_script:
37-
- cp build/coverage/merged.xml clover.xml
36+
- cp build/coverage/unit.xml clover.xml
3837
- ./cc-test-reporter after-build -t clover --exit-code $TRAVIS_TEST_RESULT

Makefile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ test-unit:
1313
vendor/bin/phpunit --testdox --verbose --color
1414
test-integration: up
1515
sleep 20
16-
@-vendor/bin/phpunit --color --testdox --verbose -c phpunit-integration.xml.dist
16+
@-vendor/bin/phpunit --no-coverage --color --testdox --verbose -c phpunit-integration.xml.dist
1717
make down
18-
merge-coverage:
19-
vendor/bin/phpcov merge --clover build/coverage/merged.xml build/coverage
20-
debug-test-integration:
18+
test-group-integration:
2119
php vendor/bin/phpunit --no-coverage --color --testdox --group debug -c phpunit-integration.xml.dist

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"ext-xml": "*",
3232
"friendsofphp/php-cs-fixer": "^2.16",
3333
"php-amqplib/php-amqplib": "^2.11",
34-
"phpunit/phpcov": "^6.0",
3534
"phpunit/phpunit": "^8.5",
3635
"squizlabs/php_codesniffer": "^3.5"
3736
},

phpunit-integration.xml.dist

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,4 @@
3030
</arguments>
3131
</extension>
3232
</extensions>
33-
<filter>
34-
<whitelist processUncoveredFilesFromWhitelist="true">
35-
<directory suffix=".php">src</directory>
36-
</whitelist>
37-
</filter>
38-
<logging>
39-
<log type="coverage-php" target="build/coverage/integration.cov"/>
40-
<log type="coverage-text" target="php://stdout" showOnlySummary="true"/>
41-
</logging>
4233
</phpunit>

phpunit.xml.dist

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
</whitelist>
2020
</filter>
2121
<logging>
22-
<log type="coverage-php" target="build/coverage/unit.cov"/>
2322
<log type="coverage-text" target="php://stdout" showOnlySummary="true"/>
23+
<log type="coverage-php" target="build/coverage/unit.cov"/>
24+
<log type="coverage-clover" target="build/coverage/unit.xml"/>
25+
<log type="coverage-html" target="build/coverage/unit"/>
2426
</logging>
2527
</phpunit>

src/PHPUnit/Runner/Extension/AMQPFixtureConfig.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace IntegrationTesting\PHPUnit\Runner\Extension;
44

5+
use IntegrationTesting\Exception\TestingException;
56
use IntegrationTesting\PHPUnit\Runner\Extension\AMQP\PublishMessageConfig;
67
use Iterator;
78

@@ -10,7 +11,7 @@ class AMQPFixtureConfig
1011
private const BEFORE_FIRST_TEST_KEY = 'beforeFirstTest';
1112
private const BEFORE_TEST_KEY = 'beforeTest';
1213
private const AFTER_TEST_KEY = 'afterTest';
13-
private const AFTER_LAST_TEST_KEY = 'afterLastKey';
14+
private const AFTER_LAST_TEST_KEY = 'afterLastTest';
1415
private const PURGE_QUEUES_KEY = 'purgeQueues';
1516
private const PUBLISH_MESSAGES_KEY = 'publishMessages';
1617
private static $defaultParams = [
@@ -29,11 +30,26 @@ class AMQPFixtureConfig
2930
self::PURGE_QUEUES_KEY => []
3031
]
3132
];
32-
private $params;
33+
private $params = [];
3334

3435
public function __construct(array $params)
3536
{
37+
if ($invalidConfigParams = array_diff_key($params, self::$defaultParams)) {
38+
throw new TestingException(
39+
'The following elements are not valid AMQP configuration params: ' . json_encode($invalidConfigParams)
40+
);
41+
}
3642
$this->params = array_merge(self::$defaultParams, $params);
43+
foreach ($this->params as $key => $value) {
44+
if (isset($params[$key])) {
45+
if ($invalidConfigParams = array_diff_key($params[$key], self::$defaultParams[$key])) {
46+
throw new TestingException(
47+
'The following elements are not valid AMQP configuration params: ' . json_encode($invalidConfigParams)
48+
);
49+
}
50+
$this->params[$key] = array_merge(self::$defaultParams[$key], $params[$key]);
51+
}
52+
}
3753
}
3854

3955
/**

src/PHPUnit/Runner/Extension/Configuration.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,24 @@ public function __construct(array $params)
4646
if (empty($params)) {
4747
throw new TestingException('Configuration parameters are empty');
4848
}
49-
if (isset($params[self::PDO_KEY])) {
50-
if ($invalidConfigParams = array_diff_key($params[self::PDO_KEY], self::$defaultPDOParams)) {
51-
throw new TestingException(
52-
'The following elements are not valid PDO configuration params: ' . json_encode($invalidConfigParams)
53-
);
54-
}
55-
$this->PDOParams = array_merge(self::$defaultPDOParams, $params[self::PDO_KEY]);
49+
if (!isset($params[self::PDO_KEY])) {
50+
$params[self::PDO_KEY] = [];
5651
}
57-
if (isset($params[self::AMQP_KEY])) {
58-
if ($invalidConfigParams = array_diff_key($params[self::AMQP_KEY], self::$defaultAMQPParams)) {
59-
throw new TestingException(
60-
'The following elements are not valid AMQP configuration params: ' . json_encode($invalidConfigParams)
61-
);
62-
}
63-
$this->AMQPParams = array_merge(self::$defaultAMQPParams, $params[self::AMQP_KEY]);
52+
if ($invalidConfigParams = array_diff_key($params[self::PDO_KEY], self::$defaultPDOParams)) {
53+
throw new TestingException(
54+
'The following elements are not valid PDO configuration params: ' . json_encode($invalidConfigParams)
55+
);
6456
}
57+
if (!isset($params[self::AMQP_KEY])) {
58+
$params[self::AMQP_KEY] = [];
59+
}
60+
if ($invalidConfigParams = array_diff_key($params[self::AMQP_KEY], self::$defaultAMQPParams)) {
61+
throw new TestingException(
62+
'The following elements are not valid AMQP configuration params: ' . json_encode($invalidConfigParams)
63+
);
64+
}
65+
$this->PDOParams = array_merge(self::$defaultPDOParams, $params[self::PDO_KEY]);
66+
$this->AMQPParams = array_merge(self::$defaultAMQPParams, $params[self::AMQP_KEY]);
6567
}
6668

6769
public function getPDODSN(): string

src/PHPUnit/Runner/Extension/Handler.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ final class Handler implements BeforeFirstTestHook, BeforeTestHook, AfterTestHoo
2323
*/
2424
private $fileSystem;
2525

26+
/**
27+
* Handler constructor.
28+
* @param string $configurationFileName
29+
* @param null $fileSystem
30+
* @throws TestingException
31+
*/
2632
public function __construct(string $configurationFileName = '', $fileSystem = null)
2733
{
2834
if (null === $fileSystem) {
@@ -83,16 +89,7 @@ private function getConfigurationFromFileName(string $fileName): Configuration
8389
public function initPDOFixtureLoader(Configuration $configuration): void
8490
{
8591
if ($configuration->getPDODSN()) {
86-
$pdoFixtureConfig = new PDOFixtureConfig([
87-
PDOFixtureConfig::BEFORE_FIRST_TEST_PDO_FIXTURES_PATH =>
88-
$configuration->getPDOFixtures()['beforeFirstTest']['path'],
89-
PDOFixtureConfig::BEFORE_TEST_PDO_FIXTURES_PATH =>
90-
$configuration->getPDOFixtures()['beforeTest']['path'],
91-
PDOFixtureConfig::AFTER_TEST_PDO_FIXTURES_PATH =>
92-
$configuration->getPDOFixtures()['afterTest']['path'],
93-
PDOFixtureConfig::AFTER_LAST_TEST_PDO_FIXTURES_PATH =>
94-
$configuration->getPDOFixtures()['afterLastTest']['path']
95-
]);
92+
$pdoFixtureConfig = new PDOFixtureConfig($configuration->getPDOFixtures());
9693
$pdoConnection = new PDOConnection(
9794
$configuration->getPDODSN(),
9895
$configuration->getPDOUser(),

src/PHPUnit/Runner/Extension/PDOFixtureConfig.php

Lines changed: 52 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,77 @@
66

77
class PDOFixtureConfig
88
{
9-
const BEFORE_FIRST_TEST_PDO_FIXTURES_PATH = 'BEFORE_FIRST_TEST_PDO_FIXTURES_PATH';
10-
const BEFORE_TEST_PDO_FIXTURES_PATH = 'BEFORE_TEST_PDO_FIXTURES_PATH';
11-
const AFTER_TEST_PDO_FIXTURES_PATH = 'AFTER_TEST_PDO_FIXTURES_PATH';
12-
const AFTER_LAST_TEST_PDO_FIXTURES_PATH = 'AFTER_LAST_TEST_PDO_FIXTURES_PATH';
9+
private const BEFORE_FIRST_TEST_KEY = 'beforeFirstTest';
10+
private const BEFORE_TEST_KEY = 'beforeTest';
11+
private const AFTER_TEST_KEY = 'afterTest';
12+
private const AFTER_LAST_TEST_KEY = 'afterLastTest';
13+
private const DEFAULT_EXTENSION = 'sql';
1314

1415
public static $defaultParams = [
15-
self::BEFORE_FIRST_TEST_PDO_FIXTURES_PATH => '',
16-
self::BEFORE_TEST_PDO_FIXTURES_PATH => '',
17-
self::AFTER_TEST_PDO_FIXTURES_PATH => '',
18-
self::AFTER_LAST_TEST_PDO_FIXTURES_PATH => '',
16+
self::BEFORE_FIRST_TEST_KEY => [
17+
'path' => '',
18+
'extension' => self::DEFAULT_EXTENSION
19+
],
20+
self::BEFORE_TEST_KEY => [
21+
'path' => '',
22+
'extension' => self::DEFAULT_EXTENSION
23+
],
24+
self::AFTER_TEST_KEY => [
25+
'path' => '',
26+
'extension' => self::DEFAULT_EXTENSION
27+
],
28+
self::AFTER_LAST_TEST_KEY => [
29+
'path' => '',
30+
'extension' => self::DEFAULT_EXTENSION
31+
]
1932
];
2033
private $params = [];
2134

2235
/**
23-
* PDODatabaseExtensionConfig constructor.
24-
*
25-
* @param array $params
36+
* PDOFixtureConfig constructor.
37+
* @param array $params
2638
* @throws TestingException
2739
*/
2840
public function __construct(array $params)
2941
{
30-
if (empty($params)) {
31-
throw new TestingException('Configuration parameters are empty');
32-
}
3342
if ($invalidConfigParams = array_diff_key($params, self::$defaultParams)) {
3443
throw new TestingException(
35-
'The following elements are not valid configuration params: ' . json_encode($invalidConfigParams)
44+
'The following elements are not valid PDO configuration params: ' . json_encode($invalidConfigParams)
3645
);
3746
}
3847
$this->params = array_merge(self::$defaultParams, $params);
48+
foreach ($this->params as $key => $value) {
49+
if (isset($params[$key])) {
50+
if ($invalidConfigParams = array_diff_key($params[$key], self::$defaultParams[$key])) {
51+
throw new TestingException(
52+
'The following elements are not valid PDO configuration params: ' . json_encode($invalidConfigParams)
53+
);
54+
}
55+
$this->params[$key] = array_merge(self::$defaultParams[$key], $params[$key]);
56+
}
57+
}
3958
}
4059

4160
/**
42-
* @param string $key
43-
* @return string
44-
* @throws TestingException
61+
* @return array['path' => 'extension']
4562
*/
46-
public function getParam(string $key): string
63+
public function getBeforeFirstTest(): array
4764
{
48-
if (isset($this->params[$key])) {
49-
return $this->params[$key];
50-
}
51-
throw new TestingException("Parameter [$key] does not exists");
65+
return $this->params[self::BEFORE_FIRST_TEST_KEY];
66+
}
67+
68+
public function getBeforeTest(): array
69+
{
70+
return $this->params[self::BEFORE_TEST_KEY];
71+
}
72+
73+
public function getAfterTest(): array
74+
{
75+
return $this->params[self::AFTER_TEST_KEY];
76+
}
77+
78+
public function getAfterLastTest(): array
79+
{
80+
return $this->params[self::AFTER_LAST_TEST_KEY];
5281
}
5382
}

src/PHPUnit/Runner/Extension/PDOFixtureLoader.php

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
final class PDOFixtureLoader implements FixtureLoader
1010
{
11-
const EXTENSION_SQL = 'sql';
12-
1311
private $fileSystem;
1412
private $config;
1513
private $connection;
@@ -26,8 +24,8 @@ public function __construct(FileSystem $fileSystem, PDOFixtureConfig $config, PD
2624
*/
2725
public function executeBeforeFirstTest(): void
2826
{
29-
$path = $this->config->getParam(PDOFixtureConfig::BEFORE_FIRST_TEST_PDO_FIXTURES_PATH);
30-
$this->runFixturesUnderPath($path);
27+
$params = $this->config->getBeforeFirstTest();
28+
$this->runFixturesUnderPathWithExtension($params['path'], $params['extension']);
3129
}
3230

3331
/**
@@ -36,18 +34,11 @@ public function executeBeforeFirstTest(): void
3634
*/
3735
public function executeBeforeTest(string $test): void
3836
{
39-
$stage = PDOFixtureConfig::BEFORE_TEST_PDO_FIXTURES_PATH;
40-
$path = $this->config->getParam($stage);
41-
$this->runFixturesUnderPath($path);
37+
$params = $this->config->getBeforeTest();
38+
$this->runFixturesUnderPathWithExtension($params['path'], $params['extension']);
4239
$className = '\\' . substr($test, 0, strpos($test, ':'));
4340
$methodName = 'getBeforeTestFixtureName';
44-
if (method_exists($className, $methodName)) {
45-
$fixtureNameFunc = "$className::$methodName";
46-
$path = $this->config->getParam($stage)
47-
. DIRECTORY_SEPARATOR
48-
. $fixtureNameFunc();
49-
$this->runFixturesUnderPath($path);
50-
}
41+
$this->runSpecificFixturesFromStatic($className, $methodName, $params);
5142
}
5243

5344
/**
@@ -57,38 +48,34 @@ public function executeBeforeTest(string $test): void
5748
*/
5849
public function executeAfterTest(string $test, float $time): void
5950
{
60-
$stage = PDOFixtureConfig::AFTER_TEST_PDO_FIXTURES_PATH;
61-
$path = $this->config->getParam($stage);
62-
$this->runFixturesUnderPath($path);
51+
$params = $this->config->getAfterTest();
52+
$this->runFixturesUnderPathWithExtension($params['path'], $params['extension']);
6353
$className = '\\' . substr($test, 0, strpos($test, ':'));
6454
$methodName = 'getAfterTestFixtureName';
65-
if (method_exists($className, $methodName)) {
66-
$fixtureNameFunc = "$className::$methodName";
67-
$path = $this->config->getParam($stage) . DIRECTORY_SEPARATOR . $fixtureNameFunc();
68-
$this->runFixturesUnderPath($path);
69-
}
55+
$this->runSpecificFixturesFromStatic($className, $methodName, $params);
7056
}
7157

7258
/**
7359
* @throws TestingException
7460
*/
7561
public function executeAfterLastTest(): void
7662
{
77-
$path = $this->config->getParam(PDOFixtureConfig::AFTER_LAST_TEST_PDO_FIXTURES_PATH);
78-
$this->runFixturesUnderPath($path);
63+
$params = $this->config->getAfterLastTest();
64+
$this->runFixturesUnderPathWithExtension($params['path'], $params['extension']);
7965
}
8066

8167
/**
8268
* @param string $path
69+
* @param string $extension
8370
* @throws TestingException
8471
*/
85-
public function runFixturesUnderPath(string $path): void
72+
public function runFixturesUnderPathWithExtension(string $path, string $extension): void
8673
{
8774
try {
8875
$this->connection->PDO()->beginTransaction();
8976
$iterator = $this->fileSystem->getFileListIteratorFromPathByExtension(
9077
$path,
91-
self::EXTENSION_SQL
78+
$extension
9279
);
9380
$this->fileSystem->runCallbackOnEachFileIteratorContents(
9481
$iterator,
@@ -102,4 +89,21 @@ function (string $contents) {
10289
throw $exception;
10390
}
10491
}
92+
93+
/**
94+
* @param string $className
95+
* @param string $methodName
96+
* @param array $params
97+
* @throws TestingException
98+
*/
99+
public function runSpecificFixturesFromStatic(string $className, string $methodName, array $params): void
100+
{
101+
if (method_exists($className, $methodName)) {
102+
$fixtureNameFunc = "$className::$methodName";
103+
$this->runFixturesUnderPathWithExtension(
104+
$params['path'] . DIRECTORY_SEPARATOR . $fixtureNameFunc(),
105+
$params['extension']
106+
);
107+
}
108+
}
105109
}

0 commit comments

Comments
 (0)