Skip to content

Commit f35bebc

Browse files
committed
[CI] Add MySQL for integration tests
1 parent 371db9f commit f35bebc

File tree

12 files changed

+87
-36
lines changed

12 files changed

+87
-36
lines changed

.gitattributes

+12-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
/.editorconfig export-ignore
2-
/.gitattributes export-ignore
3-
/.github export-ignore
4-
/.gitignore export-ignore
5-
/.php-cs-fixer.php export-ignore
6-
/.php-version export-ignore
7-
/link export-ignore
8-
/Makefile export-ignore
9-
/phpunit.xml.dist export-ignore
10-
/res/img export-ignore
11-
/tests export-ignore
1+
/.editorconfig export-ignore
2+
/.gitattributes export-ignore
3+
/.github export-ignore
4+
/.gitignore export-ignore
5+
/.php-cs-fixer.php export-ignore
6+
/.php-version export-ignore
7+
/link export-ignore
8+
/Makefile export-ignore
9+
/docker-compose.yml export-ignore
10+
/phpunit.xml.dist export-ignore
11+
/res/img export-ignore
12+
/tests export-ignore

.github/workflows/ci.yml

+33-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
test:
3333
name: ${{ matrix.name }}
3434
runs-on: ${{ matrix.os }}
35-
timeout-minutes: 8
35+
timeout-minutes: 15
3636
continue-on-error: ${{ matrix.allow-failure == 1 }}
3737

3838
strategy:
@@ -60,19 +60,22 @@ jobs:
6060
symfony: '5.4.*@dev'
6161
allow-unstable: true
6262
mongodb: true
63+
mysql: true
6364

6465
- name: 'Test Symfony 5.4 [Windows, PHP 8.1]'
6566
os: 'windows-latest'
6667
php: '8.1'
6768
symfony: '5.4.*@dev'
6869
mongodb: true
70+
mysql: true
6971
allow-unstable: true
7072

7173
- name: 'Test Symfony 6.0 [Linux, PHP 8.1]'
7274
os: 'ubuntu-latest'
7375
php: '8.1'
7476
symfony: '6.0.*@dev'
7577
mongodb: true
78+
mysql: true
7679
allow-unstable: true
7780

7881
# Bleeding edge (unreleased dev versions where failures are allowed)
@@ -83,6 +86,7 @@ jobs:
8386
composer-flags: '--ignore-platform-req php'
8487
allow-unstable: true
8588
allow-failure: true
89+
mysql: true
8690
mongodb: true
8791

8892
steps:
@@ -98,7 +102,7 @@ jobs:
98102
uses: shivammathur/setup-php@v2
99103
with:
100104
php-version: ${{ matrix.php }}
101-
extensions: pdo_sqlite ${{ matrix.mongodb && ', mongodb' }}
105+
extensions: pdo_sqlite ${{ matrix.mongodb && ', mongodb' }} ${{ matrix.mysql && ', pdo_mysql' }}
102106
coverage: pcov
103107
tools: 'composer:v2,flex'
104108

@@ -112,6 +116,17 @@ jobs:
112116
args: install mongodb
113117
if: ${{ matrix.mongodb && matrix.os == 'windows-latest' }}
114118

119+
- name: 'Shutdown Default Ubuntu MySQL'
120+
run: sudo service mysql stop
121+
if: ${{ matrix.mysql && matrix.os == 'ubuntu-latest' }}
122+
123+
- name: 'Setup MySQL'
124+
uses: ankane/setup-mysql@v1
125+
with:
126+
mysql-version: '8.0'
127+
database: doctrine_tests
128+
if: ${{ matrix.mysql }}
129+
115130
- name: 'Get composer cache directory'
116131
id: composer-cache
117132
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
@@ -132,9 +147,24 @@ jobs:
132147
if: ${{ matrix.mongodb }}
133148

134149
- name: 'Install dependencies'
135-
run: composer update --prefer-dist ${{ matrix.composer-flags }} --ansi
150+
run: |
151+
echo "::group::Install project deps"
152+
composer update --prefer-dist ${{ matrix.composer-flags }} --ansi
153+
echo "::endgroup::"
154+
155+
echo "::group::Install PHPUnit"
156+
vendor/bin/simple-phpunit install
157+
echo "::endgroup::"
136158
env:
137159
SYMFONY_REQUIRE: "${{ matrix.symfony }}"
138160

161+
- name: 'Set Doctrine MySQL DSN (Linux)'
162+
run: echo "DOCTRINE_DBAL_URL=pdo-mysql://root@127.0.0.1:3306/doctrine_tests?serverVersion=8.0" >> $GITHUB_ENV
163+
if: ${{ matrix.mysql && matrix.os == 'ubuntu-latest' }}
164+
165+
- name: 'Set Doctrine MySQL DSN (Windows)'
166+
run: echo "DOCTRINE_DBAL_URL=pdo-mysql://root@127.0.0.1:3306/doctrine_tests?serverVersion=8.0" >> $env:GITHUB_ENV
167+
if: ${{ matrix.mysql && matrix.os == 'windows-latest' }}
168+
139169
- name: 'Run PHPUnit tests'
140170
run: vendor/bin/simple-phpunit --testdox --verbose ${{ matrix.code-coverage && '--coverage-text --coverage-clover build/logs/clover.xml' }}

Makefile

+12-3
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,20 @@ remove-odm:
4949
# Test #
5050
########
5151

52+
docker.start:
53+
docker-compose up -d --wait
54+
55+
docker.stop:
56+
docker-compose kill
57+
docker-compose rm --force
58+
5259
test:
53-
symfony php vendor/bin/simple-phpunit
60+
symfony php vendor/bin/simple-phpunit $(if $(TESTDOX), --testdox --verbose)
5461

55-
testdox:
56-
symfony php vendor/bin/simple-phpunit --testdox --verbose
62+
test.mysql: export DOCTRINE_DBAL_URL=pdo-mysql://app:password@127.0.0.1:63306/doctrine_tests
63+
test.mysql: docker.start
64+
test.mysql:
65+
symfony php vendor/bin/simple-phpunit $(if $(TESTDOX), --testdox --verbose)
5766

5867
########
5968
# Lint #

docker-compose.yml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: '3.3'
2+
3+
services:
4+
db:
5+
image: mysql:8.0
6+
restart: unless-stopped
7+
environment:
8+
MYSQL_DATABASE: 'doctrine_tests'
9+
MYSQL_USER: app
10+
MYSQL_PASSWORD: password
11+
MYSQL_ROOT_PASSWORD: password
12+
ports:
13+
- '63306:3306'
14+
expose:
15+
- '3306'

phpunit.xml.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<env name="MONGODB_URL" value="mongodb://localhost:27017" />
1515
<env name="MONGODB_DB" value="enum-test" />
1616
<env name="DOCTRINE_DBAL_URL" value="sqlite:///%kernel.cache_dir%/db.sqlite" />
17-
<!-- <env name="DOCTRINE_DBAL_URL" value="pdo-mysql://user:pass@localhost:3306/doctrine_tests" /> -->
17+
<!--<env name="DOCTRINE_DBAL_URL" value="pdo-mysql://root@localhost:3306/doctrine_tests" />-->
1818
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[direct]=0&amp;max[self]=0&amp;max[total]=9999&amp;verbose=1"/>
1919
<env name="SYMFONY_PHPUNIT_REQUIRE" value="phpspec/prophecy-phpunit"/>
2020
<env name="SYMFONY_PHPUNIT_VERSION" value="9.5"/>

src/Bridge/Doctrine/DBAL/Types/AbstractEnumSQLDeclarationType.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla
3131
}
3232

3333
$values = array_map(
34-
function ($val) {
35-
return "'{$val->value}'";
36-
},
37-
($this->getEnumClass())::cases()
34+
static fn ($val) => "'{$val->value}'",
35+
$this->getEnumClass()::cases()
3836
);
3937

4038
return 'ENUM(' . implode(', ', $values) . ')';

src/Bridge/Symfony/Bundle/DependencyInjection/ElaoEnumExtension.php

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ private function prependDoctrineDbalConfig(array $config, ContainerBuilder $cont
104104
$container->prependExtensionConfig('doctrine', [
105105
'dbal' => [
106106
'types' => $doctrineTypesConfig,
107+
'mapping_types' => ['enum' => 'string'],
107108
],
108109
]);
109110
}

src/Bridge/Symfony/Bundle/config/schema/elao_enum.xsd

-7
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,4 @@
3333
</xsd:simpleType>
3434
</xsd:attribute>
3535
</xsd:complexType>
36-
37-
<xsd:simpleType name="doctrine_type_type">
38-
<xsd:restriction base="xsd:string">
39-
<xsd:enumeration value="string"/>
40-
<xsd:enumeration value="int"/>
41-
</xsd:restriction>
42-
</xsd:simpleType>
4336
</xsd:schema>

tests/Fixtures/Integration/Symfony/config/mysql.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ doctrine:
55
is_bundle: false
66
type: attribute
77
dir: '%kernel.project_dir%/src/EntityMySQL'
8-
prefix: 'App\Entity'
9-
alias: App
8+
prefix: 'App\EntityMySQL'
9+
alias: AppMySQL
1010

1111
elao_enum:
1212
doctrine:
1313
types:
1414
suit_sql_enum:
1515
class: App\Enum\Suit
1616
type: enum
17-
default: !php/const App\Enum\Suit::Spades
17+
default: !php/const App\Enum\Suit::Spades

tests/Fixtures/Integration/Symfony/src/Kernel.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function registerContainerConfiguration(LoaderInterface $loader)
3838
{
3939
$loader->load($this->getProjectDir() . '/config/config.yml');
4040

41-
if (preg_match('/^pdo-mysql:\/\//i', $_ENV['DOCTRINE_DBAL_URL'])) {
41+
if (str_starts_with($_ENV['DOCTRINE_DBAL_URL'], 'pdo-mysql:')) {
4242
$loader->load($this->getProjectDir() . '/config/mysql.yml');
4343
}
4444

tests/Integration/Bridge/Doctrine/DBAL/Type/EnumTypeSQLEnumTest.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,20 @@ class EnumTypeSQLEnumTest extends KernelTestCase
2323
{
2424
private ?EntityManagerInterface $em;
2525

26-
protected function setUp(): void
26+
public static function setUpBeforeClass(): void
2727
{
28-
if (!preg_match('/^pdo-mysql:\/\//i', $_ENV['DOCTRINE_DBAL_URL'])) {
28+
if (!str_starts_with($_ENV['DOCTRINE_DBAL_URL'], 'pdo-mysql:')) {
2929
self::markTestSkipped('SQL Enums can be tested only with MySQL');
3030
}
31+
}
3132

33+
protected function setUp(): void
34+
{
3235
$kernel = static::bootKernel();
3336
$container = $kernel->getContainer();
3437
$this->em = $container->get('doctrine.orm.entity_manager');
35-
$this->em->getConnection()->executeQuery('DROP TABLE IF EXISTS cards_sql_enum');
3638
$schemaTool = new SchemaTool($this->em);
39+
$schemaTool->dropDatabase();
3740
$schemaTool->createSchema($this->em->getMetadataFactory()->getAllMetadata());
3841
}
3942

tests/Unit/Bridge/Symfony/Bundle/DependencyInjection/ElaoEnumExtensionTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public function testDoctrineTypesArePrepended(): void
7070
'request_status' => 'ELAO_ENUM_DT_DBAL\\Elao\\Enum\\Tests\\Fixtures\\Enum\\RequestStatusType',
7171
'suit_enum' => 'ELAO_ENUM_DT_DBAL\\Elao\\Enum\\Tests\\Fixtures\\Enum\\SuitEnumType',
7272
],
73+
'mapping_types' => ['enum' => 'string'],
7374
],
7475
],
7576
], $container->getExtensionConfig('doctrine'));

0 commit comments

Comments
 (0)