Skip to content

Commit 2ee7256

Browse files
authored
Packages tests (#10)
* Moved unit tests to their respective packages * Added dev autoload for tests in every package * Normalize .gitignore files * Add tests dir to git export-ignore * Updated tests configuration to be able to run all tests * Add tests config for each package * Updated to PhpUnit 9.4
1 parent 0c922b0 commit 2ee7256

File tree

101 files changed

+577
-138
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+577
-138
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/build/
1+
/.phpcs-cache
2+
/.phpunit.result.cache
23
/tests/.artifacts/
34
/vendor/
4-
/*.lock
5+
/composer.lock

composer.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"symfony/validator": "^4.4|^5.0"
2626
},
2727
"require-dev": {
28-
"phpunit/phpunit": "^7.5",
28+
"phpspec/prophecy-phpunit": "^2.0",
29+
"phpunit/phpunit": "^9.4",
2930
"squizlabs/php_codesniffer": "^3.5",
3031
"symplify/monorepo-builder": "^8.2"
3132
},
@@ -57,8 +58,16 @@
5758
},
5859
"autoload-dev": {
5960
"psr-4": {
60-
"Yokai\\Batch\\Tests\\Integration\\": "tests/integration/",
61-
"Yokai\\Batch\\Tests\\Unit\\": "tests/unit/"
61+
"Yokai\\Batch\\Sources\\Tests\\Integration\\": "tests/integration/",
62+
"Yokai\\Batch\\Tests\\": "src/batch/tests/",
63+
"Yokai\\Batch\\Tests\\Bridge\\Box\\Spout\\": "src/batch-box-spout/tests/",
64+
"Yokai\\Batch\\Tests\\Bridge\\Doctrine\\DBAL\\": "src/batch-doctrine-dbal/tests/",
65+
"Yokai\\Batch\\Tests\\Bridge\\Doctrine\\ORM\\": "src/batch-doctrine-orm/tests/",
66+
"Yokai\\Batch\\Tests\\Bridge\\Doctrine\\Persistence\\": "src/batch-doctrine-persistence/tests/",
67+
"Yokai\\Batch\\Tests\\Bridge\\Symfony\\Console\\": "src/batch-symfony-console/tests/",
68+
"Yokai\\Batch\\Tests\\Bridge\\Symfony\\Framework\\": "src/batch-symfony-framework/tests/",
69+
"Yokai\\Batch\\Tests\\Bridge\\Symfony\\Messenger\\": "src/batch-symfony-messenger/tests/",
70+
"Yokai\\Batch\\Tests\\Bridge\\Symfony\\Serializer\\": "src/batch-symfony-serializer/tests/"
6271
}
6372
}
6473
}

phpunit.xml

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

33
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
44
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5-
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.5/phpunit.xsd"
5+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
66
backupGlobals="false"
77
colors="true"
88
bootstrap="tests/bootstrap.php"
@@ -13,17 +13,17 @@
1313
</php>
1414

1515
<testsuites>
16-
<testsuite name="Unit">
17-
<directory>./tests/unit</directory>
16+
<testsuite name="Package">
17+
<directory>./src/*/tests</directory>
1818
</testsuite>
1919
<testsuite name="Integration">
2020
<directory>./tests/integration</directory>
2121
</testsuite>
2222
</testsuites>
2323

24-
<filter>
25-
<whitelist>
26-
<directory>./src</directory>
27-
</whitelist>
28-
</filter>
24+
<coverage>
25+
<include>
26+
<directory>./src/*/src</directory>
27+
</include>
28+
</coverage>
2929
</phpunit>

src/batch-box-spout/.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.gitattributes export-ignore
22
.gitignore export-ignore
33
docs/ export-ignore
4+
tests/ export-ignore
45
LICENSE export-ignore
56
*.md export-ignore

src/batch-box-spout/.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
vendor/
2-
composer.lock
1+
/.phpunit.result.cache
2+
/tests/.artifacts/
3+
/vendor/
4+
/composer.lock

src/batch-box-spout/composer.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,14 @@
1919
"psr-4": {
2020
"Yokai\\Batch\\Bridge\\Box\\Spout\\": "src/"
2121
}
22+
},
23+
"require-dev": {
24+
"phpunit/phpunit": "^9.4",
25+
"symfony/filesystem": "^4.4|^5.0"
26+
},
27+
"autoload-dev": {
28+
"psr-4": {
29+
"Yokai\\Batch\\Tests\\Bridge\\Box\\Spout\\": "tests/"
30+
}
2231
}
2332
}

src/batch-box-spout/phpunit.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
4+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
6+
backupGlobals="false"
7+
colors="true"
8+
bootstrap="tests/bootstrap.php"
9+
>
10+
<php>
11+
<env name="ARTIFACT_DIR" value="tests/.artifacts"/>
12+
</php>
13+
14+
<testsuites>
15+
<testsuite name="Tests">
16+
<directory>./tests</directory>
17+
</testsuite>
18+
</testsuites>
19+
20+
<coverage>
21+
<include>
22+
<directory>./src</directory>
23+
</include>
24+
</coverage>
25+
</phpunit>

tests/unit/Bridge/Box/Spout/FlatFileReaderTest.php renamed to src/batch-box-spout/tests/FlatFileReaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Yokai\Batch\Tests\Unit\Bridge\Box\Spout;
5+
namespace Yokai\Batch\Tests\Bridge\Box\Spout;
66

77
use Box\Spout\Common\Type;
88
use PHPUnit\Framework\TestCase;

tests/unit/Bridge/Box/Spout/FlatFileWriterTest.php renamed to src/batch-box-spout/tests/FlatFileWriterTest.php

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

33
declare(strict_types=1);
44

5-
namespace Yokai\Batch\Tests\Unit\Bridge\Box\Spout;
5+
namespace Yokai\Batch\Tests\Bridge\Box\Spout;
66

77
use Box\Spout\Common\Type;
88
use Box\Spout\Reader\Wrapper\XMLReader;
@@ -14,9 +14,9 @@
1414

1515
class FlatFileWriterTest extends TestCase
1616
{
17-
private const WRITE_DIR = UNIT_ARTIFACT_DIR . '/flat-file-writer';
17+
private const WRITE_DIR = ARTIFACT_DIR . '/flat-file-writer';
1818

19-
public static function setUpBeforeClass()
19+
public static function setUpBeforeClass(): void
2020
{
2121
if (!is_dir(self::WRITE_DIR)) {
2222
mkdir(self::WRITE_DIR, 0777, true);
@@ -58,7 +58,7 @@ public function testWrite(
5858
): void {
5959
$file = self::WRITE_DIR . '/' . $filename;
6060

61-
self::assertFileNotExists($file);
61+
self::assertFileDoesNotExist($file);
6262

6363
$writer = new FlatFileWriter($type, $headers);
6464
$writer->setJobExecution(
@@ -124,15 +124,15 @@ private function assertFileContents(string $type, string $filePath, string $inli
124124
case Type::CSV:
125125
$fileContents = file_get_contents($filePath);
126126
foreach ($strings as $string) {
127-
self::assertContains($string, $fileContents);
127+
self::assertStringContainsString($string, $fileContents);
128128
}
129129
break;
130130

131131
case Type::XLSX:
132132
$pathToSheetFile = $filePath . '#xl/worksheets/sheet1.xml';
133133
$xmlContents = file_get_contents('zip://' . $pathToSheetFile);
134134
foreach ($strings as $string) {
135-
self::assertContains($string, $xmlContents);
135+
self::assertStringContainsString($string, $xmlContents);
136136
}
137137
break;
138138

@@ -142,7 +142,7 @@ private function assertFileContents(string $type, string $filePath, string $inli
142142
$xmlReader->readUntilNodeFound('table:table');
143143
$sheetXmlAsString = $xmlReader->readOuterXml();
144144
foreach ($strings as $string) {
145-
self::assertContains("<text:p>$string</text:p>", $sheetXmlAsString);
145+
self::assertStringContainsString("<text:p>$string</text:p>", $sheetXmlAsString);
146146
}
147147
break;
148148
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
// phpcs:disable PSR1.Files.SideEffects
6+
7+
use Symfony\Component\Filesystem\Filesystem;
8+
9+
require_once __DIR__ . '/../vendor/autoload.php';
10+
11+
$artifactDir = @getenv('ARTIFACT_DIR');
12+
if (false === $artifactDir) {
13+
throw new \LogicException('Missing "ARTIFACT_DIR" env var.');
14+
}
15+
16+
if (is_dir($artifactDir)) {
17+
(new Filesystem())->remove($artifactDir);
18+
}
19+
20+
(new Filesystem())->mkdir($artifactDir);
21+
22+
define('ARTIFACT_DIR', $artifactDir);

0 commit comments

Comments
 (0)