Skip to content

Commit

Permalink
Merge pull request #421 from craue/tests-with-databases
Browse files Browse the repository at this point in the history
run tests with MySQL, PostgreSQL, SQLite
  • Loading branch information
craue committed Aug 31, 2023
2 parents 515871d + 1fae5f6 commit 8c3ab2a
Show file tree
Hide file tree
Showing 27 changed files with 249 additions and 70 deletions.
65 changes: 55 additions & 10 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ jobs:
env:
SYMFONY_REQUIRE: ${{ matrix.symfony }}
SYMFONY_DEPRECATIONS_HELPER: ${{ matrix.symfony-deprecations }}
PARAM_DB_DRIVER: ${{ matrix.db-driver }}
DB_DSN_MYSQL: mysql://test:test@127.0.0.1/craue_form_flow_tests
DB_DSN_POSTGRESQL: pgsql://test:test@127.0.0.1/craue_form_flow_tests
DB_DSN_SQLITE: sqlite:///sqlite.db

strategy:
fail-fast: false
Expand All @@ -31,11 +33,6 @@ jobs:
-
php: '7.3'
symfony: '4.4.*'
-
php: '7.3'
symfony: '4.4.*'
note: sqlite
db-driver: pdo_sqlite
-
php: '7.4'
symfony: '5.4.*'
Expand All @@ -60,6 +57,36 @@ jobs:
stability: dev
allow-failure: true

services:
mysql:
image: mysql:${{ (matrix.php == '7.3' && '5.7') || '8.0' }}
env:
MYSQL_USER: test
MYSQL_PASSWORD: test
MYSQL_DATABASE: craue_form_flow_tests
MYSQL_ALLOW_EMPTY_PASSWORD: yes
options: >-
--health-cmd "mysqladmin ping --silent"
--health-interval 5s
--health-timeout 5s
--health-retries 5
ports:
- 3306:3306

postgres:
image: postgres
env:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: craue_form_flow_tests
options: >-
--health-cmd pg_isready
--health-interval 5s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

steps:
- name: checkout
uses: actions/checkout@v3
Expand All @@ -68,9 +95,9 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mysql, redis
extensions: pdo_mysql, pdo_pgsql, pdo_sqlite
coverage: pcov
ini-values: memory_limit=-1
ini-values: memory_limit=-1, variables_order="EGPCS"
tools: flex
env:
fail-fast: true # interrupt on extension setup error
Expand All @@ -91,7 +118,25 @@ jobs:
composer-options: --prefer-dist

- name: run PHPUnit
run: vendor/bin/phpunit -v --coverage-clover build/logs/clover.xml
run: vendor/bin/phpunit -v --coverage-clover build/logs/clover.xml --exclude-group run-with-multiple-databases-only

- name: run PHPUnit with MySQL
if: always()
run: vendor/bin/phpunit -v --coverage-clover build/logs/clover-mysql.xml --group run-with-multiple-databases,run-with-multiple-databases-only
env:
DB_FLAVOR: mysql

- name: run PHPUnit with PostgreSQL
if: always()
run: vendor/bin/phpunit -v --coverage-clover build/logs/clover-postgresql.xml --group run-with-multiple-databases,run-with-multiple-databases-only
env:
DB_FLAVOR: postgresql

- name: run PHPUnit with SQLite
if: always()
run: vendor/bin/phpunit -v --coverage-clover build/logs/clover-sqlite.xml --group run-with-multiple-databases,run-with-multiple-databases-only
env:
DB_FLAVOR: sqlite

- name: upload code coverage data
if: github.repository == 'craue/CraueFormFlowBundle'
Expand All @@ -101,4 +146,4 @@ jobs:
run: |
unset SYMFONY_REQUIRE
composer global require php-coveralls/php-coveralls
php-coveralls --coverage_clover=build/logs/clover.xml -v
php-coveralls -v --coverage_clover "build/logs/clover*.xml"
26 changes: 26 additions & 0 deletions Storage/SerializableFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,30 @@ public static function isSupported($file) {
return $file instanceof UploadedFile;
}

public function __serialize() : array {
return [
'content' => $this->content,
'type' => $this->type,
'clientOriginalName' => $this->clientOriginalName,
'clientMimeType' => $this->clientMimeType,
];
}

public function __unserialize(array $data) : void {
// TODO remove for 4.0
// handle representation of object which got serialized before `__serialize` method was added
if (count(array_diff(array_keys($data), ["\x00*\x00content", "\x00*\x00type", "\x00*\x00clientOriginalName", "\x00*\x00clientMimeType"])) === 0) {
$this->content = $data["\x00*\x00content"];
$this->type = $data["\x00*\x00type"];
$this->clientOriginalName = $data["\x00*\x00clientOriginalName"];
$this->clientMimeType = $data["\x00*\x00clientMimeType"];
return;
}

$this->content = $data['content'];
$this->type = $data['type'];
$this->clientOriginalName = $data['clientOriginalName'];
$this->clientMimeType = $data['clientMimeType'];
}

}
1 change: 1 addition & 0 deletions Tests/ConcurrentFlowsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

/**
* @group integration
* @group run-with-multiple-databases
*
* @author Christian Raue <christian.raue@gmail.com>
* @copyright 2011-2023 Christian Raue
Expand Down
1 change: 1 addition & 0 deletions Tests/CreateTopicFlowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

/**
* @group integration
* @group run-with-multiple-databases
*
* @author Christian Raue <christian.raue@gmail.com>
* @copyright 2011-2023 Christian Raue
Expand Down
1 change: 1 addition & 0 deletions Tests/CreateVehicleFlowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

/**
* @group integration
* @group run-with-multiple-databases
*
* @author Christian Raue <christian.raue@gmail.com>
* @copyright 2011-2023 Christian Raue
Expand Down
1 change: 1 addition & 0 deletions Tests/Demo1FlowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

/**
* @group integration
* @group run-with-multiple-databases
*
* @author Christian Raue <christian.raue@gmail.com>
* @copyright 2011-2023 Christian Raue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Craue\FormFlowBundle\Tests\IntegrationTestBundle\DependencyInjection\Compiler;

use Craue\FormFlowBundle\Storage\DoctrineStorage;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand All @@ -20,7 +19,7 @@
class DoctrineStorageCompilerPass implements CompilerPassInterface {

public function process(ContainerBuilder $container) : void {
if ($container->getParameter('db.driver') !== null) {
if ($container->has('doctrine.dbal.default_connection')) {
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../Resources/config'));
$loader->load('doctrine_storage.xml');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

use Craue\FormFlowBundle\Storage\DoctrineStorage;
use Craue\FormFlowBundle\Storage\SessionStorage;
use Craue\FormFlowBundle\Storage\StorageInterface;
use Craue\FormFlowBundle\Tests\IntegrationTestBundle\DependencyInjection\Compiler\DoctrineStorageCompilerPass;
use Craue\FormFlowBundle\Tests\IntegrationTestCase;

/**
* @group integration
* @group run-without-database
* @group run-with-multiple-databases
*
* @author Christian Raue <christian.raue@gmail.com>
* @copyright 2011-2023 Christian Raue
Expand All @@ -24,9 +24,8 @@ class StorageImplementationTest extends IntegrationTestCase {
* may silently fail leading to a wrong implementation being used in tests.
*/
public function testUseCorrectStorageImplementation() {
$dbDriver = static::$kernel->getContainer()->getParameter('db.driver');
$storage = $this->getService('craue.form.flow.storage');
$expectedClass = $dbDriver !== null ? DoctrineStorage::class : SessionStorage::class;
$expectedClass = empty($_ENV['DB_DSN']) ? SessionStorage::class : DoctrineStorage::class;
$this->assertInstanceOf($expectedClass, $storage);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,8 @@
<argument type="service" id="request_stack" />
</service>

<service id="integrationTestBundle.doctrineConnection" class="Doctrine\DBAL\Connection" public="false">
<factory class="Doctrine\DBAL\DriverManager" method="getConnection" />
<argument type="collection">
<argument key="charset">UTF8</argument>
<argument key="driver">%db.driver%</argument>
<argument key="host">%db.host%</argument>
<argument key="port">%db.port%</argument>
<argument key="dbname">%db.name%</argument>
<argument key="user">%db.user%</argument>
<argument key="password">%db.password%</argument>
<argument key="path">%db.path%</argument>
</argument>
</service>

<service id="craue.form.flow.storage.doctrine" class="Craue\FormFlowBundle\Storage\DoctrineStorage" public="false">
<argument type="service" id="integrationTestBundle.doctrineConnection" />
<argument type="service" id="doctrine.dbal.default_connection" />
<argument type="service" id="craue.form.flow.storageKeyGenerator" />
</service>

Expand Down
6 changes: 6 additions & 0 deletions Tests/IntegrationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ protected static function createKernel(array $options = []) : KernelInterface {
$environment = $options['environment'] ?? self::ENV_FLOWS_WITH_AUTOCONFIGURATION;
$configFile = $options['config'] ?? sprintf('config_%s.yml', $environment);

// ensure different caches are used for each database flavor
if (!empty($_ENV['DB_FLAVOR'])) {
$environment .= '_' . $_ENV['DB_FLAVOR'];
$_ENV['DB_DSN'] = $_ENV['DB_DSN_' . strtoupper($_ENV['DB_FLAVOR'])];
}

return new AppKernel($environment, $configFile);
}

Expand Down
1 change: 1 addition & 0 deletions Tests/Issue149Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

/**
* @group integration
* @group run-with-multiple-databases
* @see https://github.com/craue/CraueFormFlowBundle/issues/149
*
* @author Christian Raue <christian.raue@gmail.com>
Expand Down
1 change: 1 addition & 0 deletions Tests/Issue303Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

/**
* @group integration
* @group run-with-multiple-databases
* @see https://github.com/craue/CraueFormFlowBundle/issues/303
*
* @author Christian Raue <christian.raue@gmail.com>
Expand Down
1 change: 1 addition & 0 deletions Tests/Issue64Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

/**
* @group integration
* @group run-with-multiple-databases
* @see https://github.com/craue/CraueFormFlowBundle/issues/64
*
* @author Christian Raue <christian.raue@gmail.com>
Expand Down
1 change: 1 addition & 0 deletions Tests/Issue87Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

/**
* @group integration
* @group run-with-multiple-databases
* @see https://github.com/craue/CraueFormFlowBundle/issues/87
*
* @author Christian Raue <christian.raue@gmail.com>
Expand Down
1 change: 1 addition & 0 deletions Tests/OnlyOneStepFlowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

/**
* @group integration
* @group run-with-multiple-databases
*
* @author Christian Raue <christian.raue@gmail.com>
* @copyright 2011-2023 Christian Raue
Expand Down
9 changes: 9 additions & 0 deletions Tests/PhotoUploadFlowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

/**
* @group integration
* @group run-with-multiple-databases
*
* @author Christian Raue <christian.raue@gmail.com>
* @copyright 2011-2023 Christian Raue
Expand All @@ -15,6 +16,14 @@ class PhotoUploadFlowTest extends IntegrationTestCase {

const IMAGE = '/Fixtures/blue-pixel.png';

protected function setUp() : void {
if (\version_compare(\PHP_VERSION, '7.4', '<') && ($_ENV['DB_FLAVOR'] ?? '') === 'postgresql') {
$this->markTestSkipped('Would fail because SerializableFile::__serialize is only supported as of PHP 7.4.');
}

parent::setUp();
}

public function testPhotoUpload() {
$image = __DIR__ . self::IMAGE;

Expand Down
1 change: 1 addition & 0 deletions Tests/RemoveSecondStepSkipMarkOnResetFlowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

/**
* @group integration
* @group run-with-multiple-databases
*
* @author Christian Raue <christian.raue@gmail.com>
* @copyright 2011-2023 Christian Raue
Expand Down
1 change: 1 addition & 0 deletions Tests/RevalidatePreviousStepsFlowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/**
* @group integration
* @group run-with-multiple-databases
*
* @author Christian Raue <christian.raue@gmail.com>
* @copyright 2011-2023 Christian Raue
Expand Down
1 change: 1 addition & 0 deletions Tests/SkipFirstStepUsingClosureFlowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

/**
* @group integration
* @group run-with-multiple-databases
*
* @author Christian Raue <christian.raue@gmail.com>
* @copyright 2011-2023 Christian Raue
Expand Down

0 comments on commit 8c3ab2a

Please sign in to comment.