Skip to content

Commit 13a51a2

Browse files
pl-githubtemp
authored andcommitted
feat: Support dama/doctrine-test-bundle in schema tests
1 parent 6afc0ff commit 13a51a2

32 files changed

+1475
-438
lines changed

composer.json

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,30 @@
1515
"ext-tidy": "*",
1616
"brainbits/phpcs-standard": "^6.0",
1717
"brainbits/phpstan-rules": "^3.0",
18-
"doctrine/dbal": "^2.11|^3.0",
19-
"doctrine/event-manager": "^1.1",
18+
"dama/doctrine-test-bundle": "^6.0|^7.0",
19+
"doctrine/dbal": "^3.4",
20+
"doctrine/event-manager": "^1.1.1",
2021
"ergebnis/phpstan-rules": "^1.0",
2122
"jangregor/phpstan-prophecy": "^1.0",
2223
"mikey179/vfsstream": "^1.6.11",
2324
"monolog/monolog": "^2.3|^3.0",
2425
"php-coveralls/php-coveralls": "^2.4",
25-
"phpstan/phpstan": "^1.0",
26+
"phpstan/phpstan": "^1.2",
2627
"phpstan/phpstan-phpunit": "^1.0",
2728
"phpstan/phpstan-symfony": "^1.0",
2829
"phpunit/phpunit": "^10.0",
2930
"riverline/multipart-parser": "^2.0",
3031
"slam/phpstan-extensions": "^6.0",
31-
"squizlabs/php_codesniffer": "^3.6.2,!=3.7.0",
32-
"symfony/browser-kit": "^5.3|^6.0",
32+
"squizlabs/php_codesniffer": "^3.7.1",
33+
"symfony/browser-kit": "^5.4|^6.0",
3334
"symfony/console": "^5.3|^6.0",
3435
"symfony/dependency-injection": "^5.3|^6.0",
3536
"symfony/filesystem": "^5.3|^6.0",
36-
"symfony/framework-bundle": "^5.3|^6.0",
37-
"symfony/http-client": "^5.3|^6.0",
38-
"symfony/http-foundation": "^5.3|^6.0",
37+
"symfony/framework-bundle": "^5.4|^6.0",
38+
"symfony/http-client": "^6.0",
39+
"symfony/http-foundation": "^5.3.7|^6.0",
3940
"symfony/security-core": "^5.3|^6.0",
40-
"thecodingmachine/phpstan-safe-rule": "^1.0",
41+
"thecodingmachine/phpstan-safe-rule": "^1.1",
4142
"thecodingmachine/phpstan-strict-rules": "^1.0"
4243
},
4344
"suggest": {
@@ -49,6 +50,7 @@
4950
"ext-tidy": "For html snapshots",
5051
"doctrine/dbal": "For schema trait",
5152
"doctrine/event-manager": "For schema trait",
53+
"dama/doctrine-test-bundle": "For schema trait, when using DAMA Static Driver",
5254
"monolog/monolog": "For http client mock trait",
5355
"riverline/multipart-parser": "For multipart file uploads",
5456
"symfony/browser-kit": "For request trait",

src/Schema/ApplySchema.php

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/Schema/CreateApplySchema.php

Lines changed: 0 additions & 61 deletions
This file was deleted.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Brainbits\FunctionalTestHelpers\Schema;
6+
7+
use Brainbits\FunctionalTestHelpers\Schema\Strategy\MysqlBasedSchemaStrategy;
8+
use Brainbits\FunctionalTestHelpers\Schema\Strategy\MysqlDamaBasedSchemaStrategy;
9+
use Brainbits\FunctionalTestHelpers\Schema\Strategy\SchemaStrategy;
10+
use Brainbits\FunctionalTestHelpers\Schema\Strategy\SqliteFileBasedSchemaStrategy;
11+
use Brainbits\FunctionalTestHelpers\Schema\Strategy\SqliteFileDamaBasedSchemaStrategy;
12+
use Brainbits\FunctionalTestHelpers\Schema\Strategy\SqliteMemoryBasedSchemaStrategy;
13+
use DAMA\DoctrineTestBundle\Doctrine\DBAL\StaticDriver;
14+
use Doctrine\DBAL\Connection;
15+
use Doctrine\DBAL\Driver;
16+
17+
use function class_exists;
18+
use function str_contains;
19+
use function str_ends_with;
20+
21+
final class CreateSchemaStrategy
22+
{
23+
public function __invoke(Connection $connection): SchemaStrategy
24+
{
25+
$params = $connection->getParams();
26+
27+
if ($this->isSqLiteMemory($params)) {
28+
return new SqliteMemoryBasedSchemaStrategy();
29+
}
30+
31+
if ($this->isSqLiteFile($params)) {
32+
if ($this->isDamaDoctrineCacheBundleActive($connection->getDriver())) {
33+
return new SqliteFileDamaBasedSchemaStrategy();
34+
}
35+
36+
return new SqliteFileBasedSchemaStrategy();
37+
}
38+
39+
if ($this->isMysql($params)) {
40+
if ($this->isDamaDoctrineCacheBundleActive($connection->getDriver())) {
41+
return new MysqlDamaBasedSchemaStrategy();
42+
}
43+
44+
return new MysqlBasedSchemaStrategy();
45+
}
46+
47+
throw NoSchemaStrategyFound::forConnectionParameters($params);
48+
}
49+
50+
/** @param mixed[] $params */
51+
private function isSqLiteMemory(array $params): bool
52+
{
53+
$url = (string) ($params['url'] ?? '');
54+
$driver = (string) ($params['driver'] ?? '');
55+
$memory = (bool) ($params['memory'] ?? false);
56+
57+
return (str_contains($url, 'sqlite:') && str_contains($url, ':memory:'))
58+
|| ($memory === true && str_ends_with($driver, 'sqlite'));
59+
}
60+
61+
/** @param mixed[] $params */
62+
private function isSqLiteFile(array $params): bool
63+
{
64+
$url = (string) ($params['url'] ?? '');
65+
$driver = (string) ($params['driver'] ?? '');
66+
$path = (string) ($params['path'] ?? '');
67+
68+
return $path !== '' && (str_contains($url, 'sqlite:') || str_ends_with($driver, 'sqlite'));
69+
}
70+
71+
/** @param mixed[] $params */
72+
private function isMysql(array $params): bool
73+
{
74+
$driver = (string) ($params['driver'] ?? '');
75+
76+
return str_ends_with($driver, 'mysql');
77+
}
78+
79+
private function isDamaDoctrineCacheBundleActive(Driver|null $driver): bool
80+
{
81+
if (!class_exists(StaticDriver::class)) {
82+
return false;
83+
}
84+
85+
return $driver instanceof StaticDriver && StaticDriver::isKeepStaticConnections();
86+
}
87+
}

src/Schema/MysqlBasedApplySchema.php

Lines changed: 0 additions & 92 deletions
This file was deleted.

src/Schema/NoApplySchemaStrategyFound.php renamed to src/Schema/NoSchemaStrategyFound.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
use RuntimeException;
88

99
use function Safe\json_encode;
10-
use function sprintf;
10+
use function Safe\sprintf;
1111

12-
final class NoApplySchemaStrategyFound extends RuntimeException
12+
final class NoSchemaStrategyFound extends RuntimeException
1313
{
1414
/** @param mixed[] $connectionParameters */
1515
public static function forConnectionParameters(array $connectionParameters): self

0 commit comments

Comments
 (0)