Skip to content

Commit

Permalink
[CI] Add MySQL for integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ogizanagi committed Apr 22, 2022
1 parent 371db9f commit f35bebc
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 36 deletions.
23 changes: 12 additions & 11 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/.editorconfig export-ignore
/.gitattributes export-ignore
/.github export-ignore
/.gitignore export-ignore
/.php-cs-fixer.php export-ignore
/.php-version export-ignore
/link export-ignore
/Makefile export-ignore
/phpunit.xml.dist export-ignore
/res/img export-ignore
/tests export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.github export-ignore
/.gitignore export-ignore
/.php-cs-fixer.php export-ignore
/.php-version export-ignore
/link export-ignore
/Makefile export-ignore
/docker-compose.yml export-ignore
/phpunit.xml.dist export-ignore
/res/img export-ignore
/tests export-ignore
36 changes: 33 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
test:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
timeout-minutes: 8
timeout-minutes: 15
continue-on-error: ${{ matrix.allow-failure == 1 }}

strategy:
Expand Down Expand Up @@ -60,19 +60,22 @@ jobs:
symfony: '5.4.*@dev'
allow-unstable: true
mongodb: true
mysql: true

- name: 'Test Symfony 5.4 [Windows, PHP 8.1]'
os: 'windows-latest'
php: '8.1'
symfony: '5.4.*@dev'
mongodb: true
mysql: true
allow-unstable: true

- name: 'Test Symfony 6.0 [Linux, PHP 8.1]'
os: 'ubuntu-latest'
php: '8.1'
symfony: '6.0.*@dev'
mongodb: true
mysql: true
allow-unstable: true

# Bleeding edge (unreleased dev versions where failures are allowed)
Expand All @@ -83,6 +86,7 @@ jobs:
composer-flags: '--ignore-platform-req php'
allow-unstable: true
allow-failure: true
mysql: true
mongodb: true

steps:
Expand All @@ -98,7 +102,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: pdo_sqlite ${{ matrix.mongodb && ', mongodb' }}
extensions: pdo_sqlite ${{ matrix.mongodb && ', mongodb' }} ${{ matrix.mysql && ', pdo_mysql' }}
coverage: pcov
tools: 'composer:v2,flex'

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

- name: 'Shutdown Default Ubuntu MySQL'
run: sudo service mysql stop
if: ${{ matrix.mysql && matrix.os == 'ubuntu-latest' }}

- name: 'Setup MySQL'
uses: ankane/setup-mysql@v1
with:
mysql-version: '8.0'
database: doctrine_tests
if: ${{ matrix.mysql }}

- name: 'Get composer cache directory'
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
Expand All @@ -132,9 +147,24 @@ jobs:
if: ${{ matrix.mongodb }}

- name: 'Install dependencies'
run: composer update --prefer-dist ${{ matrix.composer-flags }} --ansi
run: |
echo "::group::Install project deps"
composer update --prefer-dist ${{ matrix.composer-flags }} --ansi
echo "::endgroup::"
echo "::group::Install PHPUnit"
vendor/bin/simple-phpunit install
echo "::endgroup::"
env:
SYMFONY_REQUIRE: "${{ matrix.symfony }}"

- name: 'Set Doctrine MySQL DSN (Linux)'
run: echo "DOCTRINE_DBAL_URL=pdo-mysql://root@127.0.0.1:3306/doctrine_tests?serverVersion=8.0" >> $GITHUB_ENV
if: ${{ matrix.mysql && matrix.os == 'ubuntu-latest' }}

- name: 'Set Doctrine MySQL DSN (Windows)'
run: echo "DOCTRINE_DBAL_URL=pdo-mysql://root@127.0.0.1:3306/doctrine_tests?serverVersion=8.0" >> $env:GITHUB_ENV
if: ${{ matrix.mysql && matrix.os == 'windows-latest' }}

- name: 'Run PHPUnit tests'
run: vendor/bin/simple-phpunit --testdox --verbose ${{ matrix.code-coverage && '--coverage-text --coverage-clover build/logs/clover.xml' }}
15 changes: 12 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,20 @@ remove-odm:
# Test #
########

docker.start:
docker-compose up -d --wait

docker.stop:
docker-compose kill
docker-compose rm --force

test:
symfony php vendor/bin/simple-phpunit
symfony php vendor/bin/simple-phpunit $(if $(TESTDOX), --testdox --verbose)

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

########
# Lint #
Expand Down
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3.3'

services:
db:
image: mysql:8.0
restart: unless-stopped
environment:
MYSQL_DATABASE: 'doctrine_tests'
MYSQL_USER: app
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: password
ports:
- '63306:3306'
expose:
- '3306'
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<env name="MONGODB_URL" value="mongodb://localhost:27017" />
<env name="MONGODB_DB" value="enum-test" />
<env name="DOCTRINE_DBAL_URL" value="sqlite:///%kernel.cache_dir%/db.sqlite" />
<!-- <env name="DOCTRINE_DBAL_URL" value="pdo-mysql://user:pass@localhost:3306/doctrine_tests" /> -->
<!--<env name="DOCTRINE_DBAL_URL" value="pdo-mysql://root@localhost:3306/doctrine_tests" />-->
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[direct]=0&amp;max[self]=0&amp;max[total]=9999&amp;verbose=1"/>
<env name="SYMFONY_PHPUNIT_REQUIRE" value="phpspec/prophecy-phpunit"/>
<env name="SYMFONY_PHPUNIT_VERSION" value="9.5"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla
}

$values = array_map(
function ($val) {
return "'{$val->value}'";
},
($this->getEnumClass())::cases()
static fn ($val) => "'{$val->value}'",
$this->getEnumClass()::cases()
);

return 'ENUM(' . implode(', ', $values) . ')';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ private function prependDoctrineDbalConfig(array $config, ContainerBuilder $cont
$container->prependExtensionConfig('doctrine', [
'dbal' => [
'types' => $doctrineTypesConfig,
'mapping_types' => ['enum' => 'string'],
],
]);
}
Expand Down
7 changes: 0 additions & 7 deletions src/Bridge/Symfony/Bundle/config/schema/elao_enum.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,4 @@
</xsd:simpleType>
</xsd:attribute>
</xsd:complexType>

<xsd:simpleType name="doctrine_type_type">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="string"/>
<xsd:enumeration value="int"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
6 changes: 3 additions & 3 deletions tests/Fixtures/Integration/Symfony/config/mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ doctrine:
is_bundle: false
type: attribute
dir: '%kernel.project_dir%/src/EntityMySQL'
prefix: 'App\Entity'
alias: App
prefix: 'App\EntityMySQL'
alias: AppMySQL

elao_enum:
doctrine:
types:
suit_sql_enum:
class: App\Enum\Suit
type: enum
default: !php/const App\Enum\Suit::Spades
default: !php/const App\Enum\Suit::Spades
2 changes: 1 addition & 1 deletion tests/Fixtures/Integration/Symfony/src/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load($this->getProjectDir() . '/config/config.yml');

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,20 @@ class EnumTypeSQLEnumTest extends KernelTestCase
{
private ?EntityManagerInterface $em;

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

protected function setUp(): void
{
$kernel = static::bootKernel();
$container = $kernel->getContainer();
$this->em = $container->get('doctrine.orm.entity_manager');
$this->em->getConnection()->executeQuery('DROP TABLE IF EXISTS cards_sql_enum');
$schemaTool = new SchemaTool($this->em);
$schemaTool->dropDatabase();
$schemaTool->createSchema($this->em->getMetadataFactory()->getAllMetadata());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function testDoctrineTypesArePrepended(): void
'request_status' => 'ELAO_ENUM_DT_DBAL\\Elao\\Enum\\Tests\\Fixtures\\Enum\\RequestStatusType',
'suit_enum' => 'ELAO_ENUM_DT_DBAL\\Elao\\Enum\\Tests\\Fixtures\\Enum\\SuitEnumType',
],
'mapping_types' => ['enum' => 'string'],
],
],
], $container->getExtensionConfig('doctrine'));
Expand Down

0 comments on commit f35bebc

Please sign in to comment.