From 49659aba3bb1c546e57934a2309000eefb648f5c Mon Sep 17 00:00:00 2001 From: David Badura Date: Wed, 12 Jan 2022 15:38:26 +0100 Subject: [PATCH 01/25] fix case insititiv column names --- src/Store/DoctrineStore.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Store/DoctrineStore.php b/src/Store/DoctrineStore.php index 309a4196..c97ea673 100644 --- a/src/Store/DoctrineStore.php +++ b/src/Store/DoctrineStore.php @@ -30,7 +30,7 @@ public function connection(): Connection abstract public function schema(): Schema; /** - * @param array{aggregateId: string, playhead: string, event: class-string, payload: string, recordedOn: string} $result + * @param array{aggregateId: string, playhead: string, event: class-string, payload: string, recordedOn: string, recordedon: ?string, aggregateid: ?string} $result * * @return array{aggregateId: string, playhead: int, event: class-string, payload: string, recordedOn: DateTimeImmutable} * @@ -38,6 +38,13 @@ abstract public function schema(): Schema; */ final protected static function normalizeResult(AbstractPlatform $platform, array $result): array { + if (array_key_exists('aggregateid', $result) && array_key_exists('recordedon', $result)) { + $result['aggregateId'] = $result['aggregateid']; + $result['recordedOn'] = $result['recordedon']; + + unset($result['aggregateid'], $result['recordedon']); + } + $result['recordedOn'] = self::normalizeRecordedOn($result['recordedOn'], $platform); $result['playhead'] = self::normalizePlayhead($result['playhead'], $platform); From 151c1a92b711751e810dace88aaa91804d813433 Mon Sep 17 00:00:00 2001 From: David Badura Date: Wed, 12 Jan 2022 16:12:34 +0100 Subject: [PATCH 02/25] add integration tests --- .github/workflows/coding-standard.yml | 21 +----- .github/workflows/integration.yml | 61 ++++++++++++++++++ .github/workflows/mutation-tests.yml | 21 +----- .github/workflows/phpstan.yml | 21 +----- .github/workflows/phpunit.yml | 64 ------------------- .github/workflows/psalm.yml | 21 +----- .github/workflows/unit.yml | 47 ++++++++++++++ phpunit.xml.dist | 1 + .../BasicIntegrationTest.php | 15 +---- 9 files changed, 118 insertions(+), 154 deletions(-) create mode 100644 .github/workflows/integration.yml delete mode 100644 .github/workflows/phpunit.yml create mode 100644 .github/workflows/unit.yml diff --git a/.github/workflows/coding-standard.yml b/.github/workflows/coding-standard.yml index 73c91151..d6c35df1 100644 --- a/.github/workflows/coding-standard.yml +++ b/.github/workflows/coding-standard.yml @@ -35,26 +35,9 @@ jobs: ini-values: memory_limit=-1 extensions: pdo_sqlite - - name: "Cache dependencies" - uses: "actions/cache@v2" + - uses: "ramsey/composer-install@v2" with: - path: | - ~/.composer/cache - vendor - key: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}" - restore-keys: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}" - - - name: "Install lowest dependencies" - if: ${{ matrix.dependencies == 'lowest' }} - run: "composer update --prefer-lowest --no-interaction --no-progress --no-suggest" - - - name: "Install highest dependencies" - if: ${{ matrix.dependencies == 'highest' }} - run: "composer update --no-interaction --no-progress --no-suggest" - - - name: "Install locked dependencies" - if: ${{ matrix.dependencies == 'locked' }} - run: "composer install --no-interaction --no-progress --no-suggest" + dependency-versions: ${{ matrix.dependencies }} - name: "Coding Standard" run: "vendor/bin/phpcs" diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml new file mode 100644 index 00000000..308b32b8 --- /dev/null +++ b/.github/workflows/integration.yml @@ -0,0 +1,61 @@ +# https://help.github.com/en/categories/automating-your-workflow-with-github-actions + +name: "Integration tests" + +on: + pull_request: + push: + branches: + - "[0-9]+.[0-9]+.x" + +jobs: + postgres: + name: "Postgres tests" + + runs-on: ${{ matrix.operating-system }} + + services: + postgres: + # Docker Hub image + image: postgres + # Provide the password for postgres + env: + POSTGRES_PASSWORD: postgres + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + strategy: + matrix: + dependencies: + - "locked" + php-version: + - "8.0" + operating-system: + - "ubuntu-latest" + images: + - "postgres:latest" + + env: + DB_URL: 'postgresql://postgres:postgres@127.0.0.1:5432/db?serverVersion=13&charset=utf8' + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "pcov" + php-version: "${{ matrix.php-version }}" + ini-values: memory_limit=-1 + extensions: pdo_sqlite + + - uses: "ramsey/composer-install@v2" + with: + dependency-versions: ${{ matrix.dependencies }} + + - name: "Tests" + run: "vendor/bin/phpunit --testsuite=integration --coverage-clover=clover.xml --coverage-text" diff --git a/.github/workflows/mutation-tests.yml b/.github/workflows/mutation-tests.yml index b0dc6e52..562f338e 100644 --- a/.github/workflows/mutation-tests.yml +++ b/.github/workflows/mutation-tests.yml @@ -34,26 +34,9 @@ jobs: php-version: "${{ matrix.php-version }}" ini-values: memory_limit=-1 - - name: "Cache dependencies" - uses: "actions/cache@v2" + - uses: "ramsey/composer-install@v2" with: - path: | - ~/.composer/cache - vendor - key: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}" - restore-keys: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}" - - - name: "Install lowest dependencies" - if: ${{ matrix.dependencies == 'lowest' }} - run: "composer update --prefer-lowest --no-interaction --no-progress --no-suggest" - - - name: "Install highest dependencies" - if: ${{ matrix.dependencies == 'highest' }} - run: "composer update --no-interaction --no-progress --no-suggest" - - - name: "Install locked dependencies" - if: ${{ matrix.dependencies == 'locked' }} - run: "composer install --no-interaction --no-progress --no-suggest" + dependency-versions: ${{ matrix.dependencies }} - name: "Infection" run: "vendor/bin/infection" diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 06841a76..f24975ff 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -35,26 +35,9 @@ jobs: ini-values: memory_limit=-1 extensions: pdo_sqlite - - name: "Cache dependencies" - uses: "actions/cache@v2" + - uses: "ramsey/composer-install@v2" with: - path: | - ~/.composer/cache - vendor - key: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}" - restore-keys: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}" - - - name: "Install lowest dependencies" - if: ${{ matrix.dependencies == 'lowest' }} - run: "composer update --prefer-lowest --no-interaction --no-progress --no-suggest" - - - name: "Install highest dependencies" - if: ${{ matrix.dependencies == 'highest' }} - run: "composer update --no-interaction --no-progress --no-suggest" - - - name: "Install locked dependencies" - if: ${{ matrix.dependencies == 'locked' }} - run: "composer install --no-interaction --no-progress --no-suggest" + dependency-versions: ${{ matrix.dependencies }} - name: "PHPStan" run: "vendor/bin/phpstan analyse" diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml deleted file mode 100644 index 2cabcebe..00000000 --- a/.github/workflows/phpunit.yml +++ /dev/null @@ -1,64 +0,0 @@ -# https://help.github.com/en/categories/automating-your-workflow-with-github-actions - -name: "PHPUnit tests" - -on: - pull_request: - push: - branches: - - "[0-9]+.[0-9]+.x" - -jobs: - phpunit: - name: "PHPUnit tests" - - runs-on: ${{ matrix.operating-system }} - - strategy: - matrix: - dependencies: - - "lowest" - - "highest" - - "locked" - php-version: - - "7.4" - - "8.0" - operating-system: - - "ubuntu-latest" - - "windows-latest" - - steps: - - name: "Checkout" - uses: "actions/checkout@v2" - - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" - with: - coverage: "pcov" - php-version: "${{ matrix.php-version }}" - ini-values: memory_limit=-1 - extensions: pdo_sqlite - - - name: "Cache dependencies" - uses: "actions/cache@v2" - with: - path: | - ~/.composer/cache - vendor - key: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}" - restore-keys: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}" - - - name: "Install lowest dependencies" - if: ${{ matrix.dependencies == 'lowest' }} - run: "composer update --prefer-lowest --no-interaction --no-progress --no-suggest" - - - name: "Install highest dependencies" - if: ${{ matrix.dependencies == 'highest' }} - run: "composer update --no-interaction --no-progress --no-suggest" - - - name: "Install locked dependencies" - if: ${{ matrix.dependencies == 'locked' }} - run: "composer install --no-interaction --no-progress --no-suggest" - - - name: "Tests" - run: "vendor/bin/phpunit --coverage-clover=clover.xml --coverage-text" diff --git a/.github/workflows/psalm.yml b/.github/workflows/psalm.yml index 31c81a6f..59fa138d 100644 --- a/.github/workflows/psalm.yml +++ b/.github/workflows/psalm.yml @@ -35,26 +35,9 @@ jobs: ini-values: memory_limit=-1 extensions: pdo_sqlite - - name: "Cache dependencies" - uses: "actions/cache@v2" + - uses: "ramsey/composer-install@v2" with: - path: | - ~/.composer/cache - vendor - key: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}" - restore-keys: "php-${{ matrix.php-version }}-${{ matrix.dependencies }}" - - - name: "Install lowest dependencies" - if: ${{ matrix.dependencies == 'lowest' }} - run: "composer update --prefer-lowest --no-interaction --no-progress --no-suggest" - - - name: "Install highest dependencies" - if: ${{ matrix.dependencies == 'highest' }} - run: "composer update --no-interaction --no-progress --no-suggest" - - - name: "Install locked dependencies" - if: ${{ matrix.dependencies == 'locked' }} - run: "composer install --no-interaction --no-progress --no-suggest" + dependency-versions: ${{ matrix.dependencies }} - name: "psalm" run: "vendor/bin/psalm --shepherd --stats" diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml new file mode 100644 index 00000000..54589e2b --- /dev/null +++ b/.github/workflows/unit.yml @@ -0,0 +1,47 @@ +# https://help.github.com/en/categories/automating-your-workflow-with-github-actions + +name: "Unit tests" + +on: + pull_request: + push: + branches: + - "[0-9]+.[0-9]+.x" + +jobs: + phpunit: + name: "Unit tests" + + runs-on: ${{ matrix.operating-system }} + + strategy: + matrix: + dependencies: + - "lowest" + - "highest" + - "locked" + php-version: + - "7.4" + - "8.0" + operating-system: + - "ubuntu-latest" + - "windows-latest" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "pcov" + php-version: "${{ matrix.php-version }}" + ini-values: memory_limit=-1 + extensions: pdo_sqlite + + - uses: "ramsey/composer-install@v2" + with: + dependency-versions: ${{ matrix.dependencies }} + + - name: "Tests" + run: "vendor/bin/phpunit --testsuite=unit --coverage-clover=clover.xml --coverage-text" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 34cd3f32..b2624e3a 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -21,6 +21,7 @@ + diff --git a/tests/Integration/BasicImplementation/BasicIntegrationTest.php b/tests/Integration/BasicImplementation/BasicIntegrationTest.php index 1375ae5b..921f39f2 100644 --- a/tests/Integration/BasicImplementation/BasicIntegrationTest.php +++ b/tests/Integration/BasicImplementation/BasicIntegrationTest.php @@ -5,7 +5,6 @@ namespace Patchlevel\EventSourcing\Tests\Integration\BasicImplementation; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Driver\PDO\SQLite\Driver; use Doctrine\DBAL\DriverManager; use Patchlevel\EventSourcing\EventBus\DefaultEventBus; use Patchlevel\EventSourcing\EventBus\SymfonyEventBus; @@ -22,9 +21,6 @@ use Patchlevel\EventSourcing\Tests\Integration\BasicImplementation\Projection\ProfileProjection; use PHPUnit\Framework\TestCase; -use function file_exists; -use function unlink; - /** * @coversNothing */ @@ -32,17 +28,10 @@ final class BasicIntegrationTest extends TestCase { private Connection $connection; - private const DB_PATH = __DIR__ . '/data/db.sqlite3'; - public function setUp(): void { - if (file_exists(self::DB_PATH)) { - unlink(self::DB_PATH); - } - $this->connection = DriverManager::getConnection([ - 'driverClass' => Driver::class, - 'path' => self::DB_PATH, + 'url' => getenv('DB_URL') ]); } @@ -50,8 +39,6 @@ public function tearDown(): void { $this->connection->close(); SendEmailMock::reset(); - - unlink(self::DB_PATH); } public function testSuccessful(): void From a8abcbc6c1d5459d9cc92ad267341840667a50b8 Mon Sep 17 00:00:00 2001 From: David Badura Date: Wed, 12 Jan 2022 16:17:06 +0100 Subject: [PATCH 03/25] try to fix ci --- .github/workflows/integration.yml | 4 ++-- src/Store/DoctrineStore.php | 3 ++- .../Integration/BasicImplementation/BasicIntegrationTest.php | 4 +++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 308b32b8..34313408 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -39,7 +39,7 @@ jobs: - "postgres:latest" env: - DB_URL: 'postgresql://postgres:postgres@127.0.0.1:5432/db?serverVersion=13&charset=utf8' + DB_URL: 'postgresql://postgres:postgres@postgres:5432/db?serverVersion=13&charset=utf8' steps: - name: "Checkout" @@ -58,4 +58,4 @@ jobs: dependency-versions: ${{ matrix.dependencies }} - name: "Tests" - run: "vendor/bin/phpunit --testsuite=integration --coverage-clover=clover.xml --coverage-text" + run: "vendor/bin/phpunit --testsuite=integration" diff --git a/src/Store/DoctrineStore.php b/src/Store/DoctrineStore.php index c97ea673..88aee822 100644 --- a/src/Store/DoctrineStore.php +++ b/src/Store/DoctrineStore.php @@ -11,6 +11,7 @@ use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Types; +use function array_key_exists; use function is_int; abstract class DoctrineStore implements Store @@ -30,7 +31,7 @@ public function connection(): Connection abstract public function schema(): Schema; /** - * @param array{aggregateId: string, playhead: string, event: class-string, payload: string, recordedOn: string, recordedon: ?string, aggregateid: ?string} $result + * @param array{aggregateId: string, playhead: string, event: class-string, payload: string, recordedOn: string, recordedon?: string, aggregateid?: string} $result * * @return array{aggregateId: string, playhead: int, event: class-string, payload: string, recordedOn: DateTimeImmutable} * diff --git a/tests/Integration/BasicImplementation/BasicIntegrationTest.php b/tests/Integration/BasicImplementation/BasicIntegrationTest.php index 921f39f2..7f11c173 100644 --- a/tests/Integration/BasicImplementation/BasicIntegrationTest.php +++ b/tests/Integration/BasicImplementation/BasicIntegrationTest.php @@ -21,6 +21,8 @@ use Patchlevel\EventSourcing\Tests\Integration\BasicImplementation\Projection\ProfileProjection; use PHPUnit\Framework\TestCase; +use function getenv; + /** * @coversNothing */ @@ -31,7 +33,7 @@ final class BasicIntegrationTest extends TestCase public function setUp(): void { $this->connection = DriverManager::getConnection([ - 'url' => getenv('DB_URL') + 'url' => getenv('DB_URL'), ]); } From 3d781cb05ab6600035634fb39873c975bcfbb85f Mon Sep 17 00:00:00 2001 From: David Badura Date: Wed, 12 Jan 2022 16:22:21 +0100 Subject: [PATCH 04/25] fix ports for integration tests --- .github/workflows/integration.yml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 34313408..e8f44a7d 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -17,15 +17,14 @@ jobs: services: postgres: # Docker Hub image - image: postgres + image: "postgres:${{ matrix.postgres-version }}" # Provide the password for postgres env: POSTGRES_PASSWORD: postgres options: >- - --health-cmd pg_isready - --health-interval 10s - --health-timeout 5s - --health-retries 5 + --health-cmd "pg_isready" + ports: + - "5432:5432" strategy: matrix: @@ -35,8 +34,10 @@ jobs: - "8.0" operating-system: - "ubuntu-latest" - images: - - "postgres:latest" + postgres-version: + - "9.4" + - "13" + - "14" env: DB_URL: 'postgresql://postgres:postgres@postgres:5432/db?serverVersion=13&charset=utf8' From c221d02ae4dc09b3ae8c7f523704d0d55f0211e1 Mon Sep 17 00:00:00 2001 From: David Badura Date: Wed, 12 Jan 2022 16:25:29 +0100 Subject: [PATCH 05/25] try with localhost --- .github/workflows/integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index e8f44a7d..4ad60a7c 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -40,7 +40,7 @@ jobs: - "14" env: - DB_URL: 'postgresql://postgres:postgres@postgres:5432/db?serverVersion=13&charset=utf8' + DB_URL: 'postgresql://postgres:postgres@localhost:5432/db?serverVersion=13&charset=utf8' steps: - name: "Checkout" From 9a112faaaea64d695000962ad1b7da9ebf4fc2b6 Mon Sep 17 00:00:00 2001 From: David Badura Date: Wed, 12 Jan 2022 16:31:21 +0100 Subject: [PATCH 06/25] create postgres db & add sqlite integration tests --- .github/workflows/integration.yml | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 4ad60a7c..5e571fa6 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -21,6 +21,7 @@ jobs: # Provide the password for postgres env: POSTGRES_PASSWORD: postgres + POSTGRES_DB: db options: >- --health-cmd "pg_isready" ports: @@ -60,3 +61,36 @@ jobs: - name: "Tests" run: "vendor/bin/phpunit --testsuite=integration" + + sqlite: + name: "Sqlite tests" + + runs-on: ${{ matrix.operating-system }} + + strategy: + matrix: + dependencies: + - "locked" + php-version: + - "8.0" + operating-system: + - "ubuntu-latest" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "pcov" + php-version: "${{ matrix.php-version }}" + ini-values: memory_limit=-1 + extensions: pdo_sqlite + + - uses: "ramsey/composer-install@v2" + with: + dependency-versions: ${{ matrix.dependencies }} + + - name: "Tests" + run: "vendor/bin/phpunit --testsuite=integration" From 9cb79caecd275a4f650a51279c3c6df2c43610ba Mon Sep 17 00:00:00 2001 From: David Badura Date: Wed, 12 Jan 2022 16:40:06 +0100 Subject: [PATCH 07/25] cleanup database for each tests --- .github/workflows/integration.yml | 4 ++-- .../BasicImplementation/BasicIntegrationTest.php | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 5e571fa6..92a94297 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -10,7 +10,7 @@ on: jobs: postgres: - name: "Postgres tests" + name: "Postgres" runs-on: ${{ matrix.operating-system }} @@ -63,7 +63,7 @@ jobs: run: "vendor/bin/phpunit --testsuite=integration" sqlite: - name: "Sqlite tests" + name: "Sqlite" runs-on: ${{ matrix.operating-system }} diff --git a/tests/Integration/BasicImplementation/BasicIntegrationTest.php b/tests/Integration/BasicImplementation/BasicIntegrationTest.php index 7f11c173..5b953b9d 100644 --- a/tests/Integration/BasicImplementation/BasicIntegrationTest.php +++ b/tests/Integration/BasicImplementation/BasicIntegrationTest.php @@ -5,6 +5,7 @@ namespace Patchlevel\EventSourcing\Tests\Integration\BasicImplementation; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Driver\AbstractSQLiteDriver; use Doctrine\DBAL\DriverManager; use Patchlevel\EventSourcing\EventBus\DefaultEventBus; use Patchlevel\EventSourcing\EventBus\SymfonyEventBus; @@ -35,6 +36,11 @@ public function setUp(): void $this->connection = DriverManager::getConnection([ 'url' => getenv('DB_URL'), ]); + + if (!$this->connection->getDriver() instanceof AbstractSQLiteDriver) { + $this->connection->createSchemaManager()->dropDatabase('db'); + $this->connection->createSchemaManager()->createDatabase('db'); + } } public function tearDown(): void @@ -64,7 +70,6 @@ public function testSuccessful(): void // create tables $profileProjection->create(); - (new DoctrineSchemaManager())->create($store); $profile = Profile::create('1'); From 456df8a4240ecdeb1e6bc99c7c037dd0c30b81f2 Mon Sep 17 00:00:00 2001 From: David Badura Date: Wed, 12 Jan 2022 16:44:55 +0100 Subject: [PATCH 08/25] create new connection without database name, so you can recreate the database --- .../BasicImplementation/BasicIntegrationTest.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/Integration/BasicImplementation/BasicIntegrationTest.php b/tests/Integration/BasicImplementation/BasicIntegrationTest.php index 5b953b9d..92a8c34a 100644 --- a/tests/Integration/BasicImplementation/BasicIntegrationTest.php +++ b/tests/Integration/BasicImplementation/BasicIntegrationTest.php @@ -7,6 +7,7 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver\AbstractSQLiteDriver; use Doctrine\DBAL\DriverManager; +use Patchlevel\EventSourcing\Console\DoctrineHelper; use Patchlevel\EventSourcing\EventBus\DefaultEventBus; use Patchlevel\EventSourcing\EventBus\SymfonyEventBus; use Patchlevel\EventSourcing\Projection\DefaultProjectionRepository; @@ -37,10 +38,16 @@ public function setUp(): void 'url' => getenv('DB_URL'), ]); - if (!$this->connection->getDriver() instanceof AbstractSQLiteDriver) { - $this->connection->createSchemaManager()->dropDatabase('db'); - $this->connection->createSchemaManager()->createDatabase('db'); + if ($this->connection->getDriver() instanceof AbstractSQLiteDriver) { + return; } + + $newConnection = (new DoctrineHelper())->copyConnectionWithoutDatabase($this->connection); + + $newConnection->createSchemaManager()->dropDatabase('db'); + $newConnection->createSchemaManager()->createDatabase('db'); + + $newConnection->close(); } public function tearDown(): void From b41b41bd9524db80d676a6939fd3736225827ab4 Mon Sep 17 00:00:00 2001 From: David Badura Date: Wed, 12 Jan 2022 16:49:31 +0100 Subject: [PATCH 09/25] try to remove the server version --- .github/workflows/integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 92a94297..8647cd1b 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -41,7 +41,7 @@ jobs: - "14" env: - DB_URL: 'postgresql://postgres:postgres@localhost:5432/db?serverVersion=13&charset=utf8' + DB_URL: 'postgresql://postgres:postgres@localhost:5432/db?charset=utf8' steps: - name: "Checkout" From 3cd8160c28dc4d63df93e71647dc829c4b82c96f Mon Sep 17 00:00:00 2001 From: David Badura Date: Wed, 12 Jan 2022 16:52:33 +0100 Subject: [PATCH 10/25] fix insert into in projection --- .../BasicImplementation/Projection/ProfileProjection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Integration/BasicImplementation/Projection/ProfileProjection.php b/tests/Integration/BasicImplementation/Projection/ProfileProjection.php index 9a7baaba..992018ce 100644 --- a/tests/Integration/BasicImplementation/Projection/ProfileProjection.php +++ b/tests/Integration/BasicImplementation/Projection/ProfileProjection.php @@ -35,7 +35,7 @@ public function drop(): void public function applyProfileCreated(ProfileCreated $profileCreated): void { $this->connection->executeStatement( - 'INSERT INTO projection_profile (`id`) VALUES(:id);', + 'INSERT INTO projection_profile ("id") VALUES(:id);', ['id' => $profileCreated->profileId()] ); } From 453bf3bba95ed67fd1fb07ff4b5f3a9f7e78937b Mon Sep 17 00:00:00 2001 From: David Badura Date: Wed, 12 Jan 2022 16:54:03 +0100 Subject: [PATCH 11/25] remove quotes for columns in projection --- .../BasicImplementation/Projection/ProfileProjection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Integration/BasicImplementation/Projection/ProfileProjection.php b/tests/Integration/BasicImplementation/Projection/ProfileProjection.php index 992018ce..246bc935 100644 --- a/tests/Integration/BasicImplementation/Projection/ProfileProjection.php +++ b/tests/Integration/BasicImplementation/Projection/ProfileProjection.php @@ -35,7 +35,7 @@ public function drop(): void public function applyProfileCreated(ProfileCreated $profileCreated): void { $this->connection->executeStatement( - 'INSERT INTO projection_profile ("id") VALUES(:id);', + 'INSERT INTO projection_profile (id) VALUES(:id);', ['id' => $profileCreated->profileId()] ); } From c1917cf34cbb6cdcc625ac7d48e16ee3bf699274 Mon Sep 17 00:00:00 2001 From: David Badura Date: Wed, 12 Jan 2022 16:56:19 +0100 Subject: [PATCH 12/25] use prepare statment for sql queries --- .../BasicImplementation/BasicIntegrationTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Integration/BasicImplementation/BasicIntegrationTest.php b/tests/Integration/BasicImplementation/BasicIntegrationTest.php index 92a8c34a..209fa023 100644 --- a/tests/Integration/BasicImplementation/BasicIntegrationTest.php +++ b/tests/Integration/BasicImplementation/BasicIntegrationTest.php @@ -82,7 +82,7 @@ public function testSuccessful(): void $profile = Profile::create('1'); $repository->save($profile); - $result = $this->connection->fetchAssociative('SELECT * FROM projection_profile WHERE id = "1"'); + $result = $this->connection->fetchAssociative('SELECT * FROM projection_profile WHERE id = ?', ['1']); self::assertIsArray($result); self::assertArrayHasKey('id', $result); @@ -162,7 +162,7 @@ public function testMultiTableSuccessful(): void $profile = Profile::create('1'); $repository->save($profile); - $result = $this->connection->fetchAssociative('SELECT * FROM projection_profile WHERE id = "1"'); + $result = $this->connection->fetchAssociative('SELECT * FROM projection_profile WHERE id = ?', ['1']); self::assertIsArray($result); self::assertArrayHasKey('id', $result); @@ -204,7 +204,7 @@ public function testSnapshot(): void $profile = Profile::create('1'); $repository->save($profile); - $result = $this->connection->fetchAssociative('SELECT * FROM projection_profile WHERE id = "1"'); + $result = $this->connection->fetchAssociative('SELECT * FROM projection_profile WHERE id = ?', ['1']); self::assertIsArray($result); self::assertArrayHasKey('id', $result); From 95fc582fb377948ce8e98301268745e14d3a5809 Mon Sep 17 00:00:00 2001 From: David Badura Date: Wed, 12 Jan 2022 17:52:02 +0100 Subject: [PATCH 13/25] add mariadb --- .github/workflows/integration.yml | 53 +++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 8647cd1b..40383c87 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -62,6 +62,59 @@ jobs: - name: "Tests" run: "vendor/bin/phpunit --testsuite=integration" + mariadb: + name: "mariadb" + + runs-on: ${{ matrix.operating-system }} + + services: + mariadb: + image: "mariadb:${{ matrix.mariadb-version }}" + env: + MYSQL_ALLOW_EMPTY_PASSWORD: yes + MYSQL_DATABASE: "db" + + options: >- + --health-cmd "mysqladmin ping --silent" + ports: + - "3306:3306" + + strategy: + matrix: + dependencies: + - "locked" + php-version: + - "8.0" + operating-system: + - "ubuntu-latest" + mariadb-version: + - "10.0" + - "10.2" + - "10.5" + + env: + DB_URL: 'mysql://root@localhost:3306/db?charset=utf8' + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "pcov" + php-version: "${{ matrix.php-version }}" + ini-values: memory_limit=-1 + extensions: pdo_sqlite + + - uses: "ramsey/composer-install@v2" + with: + dependency-versions: ${{ matrix.dependencies }} + + - name: "Tests" + run: "vendor/bin/phpunit --testsuite=integration" + + sqlite: name: "Sqlite" From 7443a37c08a778de7af10e56220cd739a30e3883 Mon Sep 17 00:00:00 2001 From: David Badura Date: Wed, 12 Jan 2022 17:57:57 +0100 Subject: [PATCH 14/25] add mysql --- .github/workflows/integration.yml | 51 ++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 40383c87..cb305ecc 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -105,7 +105,7 @@ jobs: coverage: "pcov" php-version: "${{ matrix.php-version }}" ini-values: memory_limit=-1 - extensions: pdo_sqlite + extensions: pdo_mysql - uses: "ramsey/composer-install@v2" with: @@ -114,6 +114,55 @@ jobs: - name: "Tests" run: "vendor/bin/phpunit --testsuite=integration" + mysql: + name: "mysql" + + runs-on: ${{ matrix.operating-system }} + + services: + mysql: + image: "mysql:${{ matrix.mysql-version }}" + + options: >- + --health-cmd "mysqladmin ping --silent" + -e MYSQL_ALLOW_EMPTY_PASSWORD=yes + -e MYSQL_DATABASE=db + ports: + - "3306:3306" + + strategy: + matrix: + dependencies: + - "locked" + php-version: + - "8.0" + operating-system: + - "ubuntu-latest" + mysql-version: + - "5.7" + - "8.0" + + env: + DB_URL: 'mysql://root@localhost:3306/db?charset=utf8' + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "pcov" + php-version: "${{ matrix.php-version }}" + ini-values: memory_limit=-1 + extensions: pdo_mysql + + - uses: "ramsey/composer-install@v2" + with: + dependency-versions: ${{ matrix.dependencies }} + + - name: "Tests" + run: "vendor/bin/phpunit --testsuite=integration" sqlite: name: "Sqlite" From d687029c651eca557f99f23166b608c283f45690 Mon Sep 17 00:00:00 2001 From: David Badura Date: Wed, 12 Jan 2022 18:02:12 +0100 Subject: [PATCH 15/25] fix playhead casting --- src/Store/DoctrineStore.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Store/DoctrineStore.php b/src/Store/DoctrineStore.php index 88aee822..35559a08 100644 --- a/src/Store/DoctrineStore.php +++ b/src/Store/DoctrineStore.php @@ -63,7 +63,10 @@ private static function normalizeRecordedOn(string $recordedOnAsString, Abstract return $recordedOn; } - private static function normalizePlayhead(string $playheadAsString, AbstractPlatform $platform): int + /** + * @param string|int $playheadAsString + */ + private static function normalizePlayhead($playheadAsString, AbstractPlatform $platform): int { $playhead = Type::getType(Types::INTEGER)->convertToPHPValue($playheadAsString, $platform); From c29602cdc4243793bbcf3f2ebe5cc503d6d3a10d Mon Sep 17 00:00:00 2001 From: David Badura Date: Wed, 12 Jan 2022 18:04:59 +0100 Subject: [PATCH 16/25] missing prepare statement --- .github/workflows/integration.yml | 6 ++++-- .../BasicImplementation/BasicIntegrationTest.php | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index cb305ecc..7cc92151 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -123,10 +123,12 @@ jobs: mysql: image: "mysql:${{ matrix.mysql-version }}" + env: + MYSQL_ALLOW_EMPTY_PASSWORD: yes + MYSQL_DATABASE: "db" + options: >- --health-cmd "mysqladmin ping --silent" - -e MYSQL_ALLOW_EMPTY_PASSWORD=yes - -e MYSQL_DATABASE=db ports: - "3306:3306" diff --git a/tests/Integration/BasicImplementation/BasicIntegrationTest.php b/tests/Integration/BasicImplementation/BasicIntegrationTest.php index 209fa023..724938f0 100644 --- a/tests/Integration/BasicImplementation/BasicIntegrationTest.php +++ b/tests/Integration/BasicImplementation/BasicIntegrationTest.php @@ -123,7 +123,7 @@ public function testWithSymfonySuccessful(): void $profile = Profile::create('1'); $repository->save($profile); - $result = $this->connection->fetchAssociative('SELECT * FROM projection_profile WHERE id = "1"'); + $result = $this->connection->fetchAssociative('SELECT * FROM projection_profile WHERE id = ?', ['1']); self::assertIsArray($result); self::assertArrayHasKey('id', $result); From 9f3965e081d456f24308e19e993463451ab199c0 Mon Sep 17 00:00:00 2001 From: David Badura Date: Wed, 12 Jan 2022 22:25:51 +0100 Subject: [PATCH 17/25] use 127.0.0.1 instead of localhost in ci --- .github/workflows/integration.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 7cc92151..ef6ca15b 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -93,7 +93,7 @@ jobs: - "10.5" env: - DB_URL: 'mysql://root@localhost:3306/db?charset=utf8' + DB_URL: 'mysql://root@127.0.0.1:3306/db?charset=utf8' steps: - name: "Checkout" @@ -145,7 +145,7 @@ jobs: - "8.0" env: - DB_URL: 'mysql://root@localhost:3306/db?charset=utf8' + DB_URL: 'mysql://root@127.0.0.1:3306/db?charset=utf8' steps: - name: "Checkout" From 0c4e3d7e843d008dafb7a24be844ff91817fea5c Mon Sep 17 00:00:00 2001 From: David Badura Date: Wed, 12 Jan 2022 22:33:37 +0100 Subject: [PATCH 18/25] use schema manager to create projections --- .../BasicImplementation/Projection/ProfileProjection.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/Integration/BasicImplementation/Projection/ProfileProjection.php b/tests/Integration/BasicImplementation/Projection/ProfileProjection.php index 246bc935..bd12584f 100644 --- a/tests/Integration/BasicImplementation/Projection/ProfileProjection.php +++ b/tests/Integration/BasicImplementation/Projection/ProfileProjection.php @@ -5,6 +5,7 @@ namespace Patchlevel\EventSourcing\Tests\Integration\BasicImplementation\Projection; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Schema\Table; use Patchlevel\EventSourcing\Projection\Projection; use Patchlevel\EventSourcing\Tests\Integration\BasicImplementation\Events\ProfileCreated; @@ -24,12 +25,16 @@ public function handledEvents(): iterable public function create(): void { - $this->connection->executeStatement('CREATE TABLE IF NOT EXISTS projection_profile (id VARCHAR PRIMARY KEY);'); + $table = new Table('projection_profile'); + $table->addColumn('id', 'string'); + $table->setPrimaryKey(['id']); + + $this->connection->createSchemaManager()->createTable($table); } public function drop(): void { - $this->connection->executeStatement('DROP TABLE IF EXISTS projection_profile;'); + $this->connection->createSchemaManager()->dropTable('projection_profile'); } public function applyProfileCreated(ProfileCreated $profileCreated): void From 65ec62f8eb14e2f3f1cc26e2fd0f45997e09182a Mon Sep 17 00:00:00 2001 From: David Badura Date: Wed, 12 Jan 2022 22:51:26 +0100 Subject: [PATCH 19/25] use database service in pipeline integration tests --- .github/workflows/integration.yml | 12 +++--- .../BasicIntegrationTest.php | 4 +- .../Pipeline/PipelineChangeStoreTest.php | 40 +++++++++---------- 3 files changed, 27 insertions(+), 29 deletions(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index ef6ca15b..528549dd 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -21,7 +21,7 @@ jobs: # Provide the password for postgres env: POSTGRES_PASSWORD: postgres - POSTGRES_DB: db + POSTGRES_DB: eventstore options: >- --health-cmd "pg_isready" ports: @@ -41,7 +41,7 @@ jobs: - "14" env: - DB_URL: 'postgresql://postgres:postgres@localhost:5432/db?charset=utf8' + DB_URL: 'postgresql://postgres:postgres@localhost:5432/eventstore?charset=utf8' steps: - name: "Checkout" @@ -72,7 +72,7 @@ jobs: image: "mariadb:${{ matrix.mariadb-version }}" env: MYSQL_ALLOW_EMPTY_PASSWORD: yes - MYSQL_DATABASE: "db" + MYSQL_DATABASE: "eventstore" options: >- --health-cmd "mysqladmin ping --silent" @@ -93,7 +93,7 @@ jobs: - "10.5" env: - DB_URL: 'mysql://root@127.0.0.1:3306/db?charset=utf8' + DB_URL: 'mysql://root@127.0.0.1:3306/eventstore?charset=utf8' steps: - name: "Checkout" @@ -125,7 +125,7 @@ jobs: env: MYSQL_ALLOW_EMPTY_PASSWORD: yes - MYSQL_DATABASE: "db" + MYSQL_DATABASE: "eventstore" options: >- --health-cmd "mysqladmin ping --silent" @@ -145,7 +145,7 @@ jobs: - "8.0" env: - DB_URL: 'mysql://root@127.0.0.1:3306/db?charset=utf8' + DB_URL: 'mysql://root@127.0.0.1:3306/eventstore?charset=utf8' steps: - name: "Checkout" diff --git a/tests/Integration/BasicImplementation/BasicIntegrationTest.php b/tests/Integration/BasicImplementation/BasicIntegrationTest.php index 724938f0..a9e5ac50 100644 --- a/tests/Integration/BasicImplementation/BasicIntegrationTest.php +++ b/tests/Integration/BasicImplementation/BasicIntegrationTest.php @@ -44,8 +44,8 @@ public function setUp(): void $newConnection = (new DoctrineHelper())->copyConnectionWithoutDatabase($this->connection); - $newConnection->createSchemaManager()->dropDatabase('db'); - $newConnection->createSchemaManager()->createDatabase('db'); + $newConnection->createSchemaManager()->dropDatabase('eventstore'); + $newConnection->createSchemaManager()->createDatabase('eventstore'); $newConnection->close(); } diff --git a/tests/Integration/Pipeline/PipelineChangeStoreTest.php b/tests/Integration/Pipeline/PipelineChangeStoreTest.php index a223fd60..fd5d79dc 100644 --- a/tests/Integration/Pipeline/PipelineChangeStoreTest.php +++ b/tests/Integration/Pipeline/PipelineChangeStoreTest.php @@ -5,8 +5,9 @@ namespace Patchlevel\EventSourcing\Tests\Integration\Pipeline; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Driver\PDO\SQLite\Driver; +use Doctrine\DBAL\Driver\AbstractSQLiteDriver; use Doctrine\DBAL\DriverManager; +use Patchlevel\EventSourcing\Console\DoctrineHelper; use Patchlevel\EventSourcing\EventBus\DefaultEventBus; use Patchlevel\EventSourcing\Pipeline\Middleware\ExcludeEventMiddleware; use Patchlevel\EventSourcing\Pipeline\Middleware\RecalculatePlayheadMiddleware; @@ -24,9 +25,6 @@ use Patchlevel\EventSourcing\Tests\Integration\Pipeline\Events\PrivacyAdded; use PHPUnit\Framework\TestCase; -use function file_exists; -use function unlink; - /** * @coversNothing */ @@ -35,37 +33,37 @@ final class PipelineChangeStoreTest extends TestCase private Connection $connectionOld; private Connection $connectionNew; - private const DB_PATH_OLD = __DIR__ . '/data/old.sqlite3'; - private const DB_PATH_NEW = __DIR__ . '/data/new.sqlite3'; - public function setUp(): void { - if (file_exists(self::DB_PATH_OLD)) { - unlink(self::DB_PATH_OLD); - } - - if (file_exists(self::DB_PATH_NEW)) { - unlink(self::DB_PATH_NEW); - } + $url = getenv('DB_URL'); $this->connectionOld = DriverManager::getConnection([ - 'driverClass' => Driver::class, - 'path' => self::DB_PATH_OLD, + 'url' => $url, ]); $this->connectionNew = DriverManager::getConnection([ - 'driverClass' => Driver::class, - 'path' => self::DB_PATH_NEW, + 'url' => str_replace('eventstore', 'eventstore_new', $url), ]); + + if ($this->connectionNew->getDriver() instanceof AbstractSQLiteDriver) { + return; + } + + $tempConnection = (new DoctrineHelper())->copyConnectionWithoutDatabase($this->connectionNew); + + $tempConnection->createSchemaManager()->dropDatabase('eventstore'); + $tempConnection->createSchemaManager()->createDatabase('eventstore'); + + $tempConnection->createSchemaManager()->dropDatabase('eventstore_new'); + $tempConnection->createSchemaManager()->createDatabase('eventstore_new'); + + $tempConnection->close(); } public function tearDown(): void { $this->connectionOld->close(); $this->connectionNew->close(); - - unlink(self::DB_PATH_OLD); - unlink(self::DB_PATH_NEW); } public function testSuccessful(): void From c047838c4fccfdf49db6c8488c15388caa9bd80a Mon Sep 17 00:00:00 2001 From: David Badura Date: Wed, 12 Jan 2022 23:05:25 +0100 Subject: [PATCH 20/25] add dbal manager for better connection handling in tests --- .../BasicIntegrationTest.php | 21 +------- .../BasicImplementation/data/.gitignore | 1 - tests/Integration/DbalManager.php | 54 +++++++++++++++++++ .../Pipeline/PipelineChangeStoreTest.php | 29 ++-------- tests/Integration/Pipeline/data/.gitignore | 2 - 5 files changed, 59 insertions(+), 48 deletions(-) delete mode 100644 tests/Integration/BasicImplementation/data/.gitignore create mode 100644 tests/Integration/DbalManager.php delete mode 100644 tests/Integration/Pipeline/data/.gitignore diff --git a/tests/Integration/BasicImplementation/BasicIntegrationTest.php b/tests/Integration/BasicImplementation/BasicIntegrationTest.php index a9e5ac50..16265930 100644 --- a/tests/Integration/BasicImplementation/BasicIntegrationTest.php +++ b/tests/Integration/BasicImplementation/BasicIntegrationTest.php @@ -5,9 +5,6 @@ namespace Patchlevel\EventSourcing\Tests\Integration\BasicImplementation; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Driver\AbstractSQLiteDriver; -use Doctrine\DBAL\DriverManager; -use Patchlevel\EventSourcing\Console\DoctrineHelper; use Patchlevel\EventSourcing\EventBus\DefaultEventBus; use Patchlevel\EventSourcing\EventBus\SymfonyEventBus; use Patchlevel\EventSourcing\Projection\DefaultProjectionRepository; @@ -21,10 +18,9 @@ use Patchlevel\EventSourcing\Tests\Integration\BasicImplementation\Aggregate\Profile; use Patchlevel\EventSourcing\Tests\Integration\BasicImplementation\Processor\SendEmailProcessor; use Patchlevel\EventSourcing\Tests\Integration\BasicImplementation\Projection\ProfileProjection; +use Patchlevel\EventSourcing\Tests\Integration\DbalManager; use PHPUnit\Framework\TestCase; -use function getenv; - /** * @coversNothing */ @@ -34,20 +30,7 @@ final class BasicIntegrationTest extends TestCase public function setUp(): void { - $this->connection = DriverManager::getConnection([ - 'url' => getenv('DB_URL'), - ]); - - if ($this->connection->getDriver() instanceof AbstractSQLiteDriver) { - return; - } - - $newConnection = (new DoctrineHelper())->copyConnectionWithoutDatabase($this->connection); - - $newConnection->createSchemaManager()->dropDatabase('eventstore'); - $newConnection->createSchemaManager()->createDatabase('eventstore'); - - $newConnection->close(); + $this->connection = DbalManager::createConnection(); } public function tearDown(): void diff --git a/tests/Integration/BasicImplementation/data/.gitignore b/tests/Integration/BasicImplementation/data/.gitignore deleted file mode 100644 index 49ef2557..00000000 --- a/tests/Integration/BasicImplementation/data/.gitignore +++ /dev/null @@ -1 +0,0 @@ -db.sqlite3 diff --git a/tests/Integration/DbalManager.php b/tests/Integration/DbalManager.php new file mode 100644 index 00000000..d87ecbb1 --- /dev/null +++ b/tests/Integration/DbalManager.php @@ -0,0 +1,54 @@ + $dbUrl]); + + if ($connection->getDriver() instanceof AbstractSQLiteDriver) { + return $connection; + } + + $tempConnection = (new DoctrineHelper())->copyConnectionWithoutDatabase($connection); + + $schemaManager = $tempConnection->createSchemaManager(); + $databases = $schemaManager->listDatabases(); + + if (in_array($dbName, $databases, true)) { + $schemaManager->dropDatabase($dbName); + $schemaManager->createDatabase($dbName); + } + + $tempConnection->close(); + + return $connection; + } +} diff --git a/tests/Integration/Pipeline/PipelineChangeStoreTest.php b/tests/Integration/Pipeline/PipelineChangeStoreTest.php index fd5d79dc..0d7af60a 100644 --- a/tests/Integration/Pipeline/PipelineChangeStoreTest.php +++ b/tests/Integration/Pipeline/PipelineChangeStoreTest.php @@ -5,9 +5,6 @@ namespace Patchlevel\EventSourcing\Tests\Integration\Pipeline; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Driver\AbstractSQLiteDriver; -use Doctrine\DBAL\DriverManager; -use Patchlevel\EventSourcing\Console\DoctrineHelper; use Patchlevel\EventSourcing\EventBus\DefaultEventBus; use Patchlevel\EventSourcing\Pipeline\Middleware\ExcludeEventMiddleware; use Patchlevel\EventSourcing\Pipeline\Middleware\RecalculatePlayheadMiddleware; @@ -19,6 +16,7 @@ use Patchlevel\EventSourcing\Schema\DoctrineSchemaManager; use Patchlevel\EventSourcing\Store\MultiTableStore; use Patchlevel\EventSourcing\Store\SingleTableStore; +use Patchlevel\EventSourcing\Tests\Integration\DbalManager; use Patchlevel\EventSourcing\Tests\Integration\Pipeline\Aggregate\Profile; use Patchlevel\EventSourcing\Tests\Integration\Pipeline\Events\NewVisited; use Patchlevel\EventSourcing\Tests\Integration\Pipeline\Events\OldVisited; @@ -35,29 +33,8 @@ final class PipelineChangeStoreTest extends TestCase public function setUp(): void { - $url = getenv('DB_URL'); - - $this->connectionOld = DriverManager::getConnection([ - 'url' => $url, - ]); - - $this->connectionNew = DriverManager::getConnection([ - 'url' => str_replace('eventstore', 'eventstore_new', $url), - ]); - - if ($this->connectionNew->getDriver() instanceof AbstractSQLiteDriver) { - return; - } - - $tempConnection = (new DoctrineHelper())->copyConnectionWithoutDatabase($this->connectionNew); - - $tempConnection->createSchemaManager()->dropDatabase('eventstore'); - $tempConnection->createSchemaManager()->createDatabase('eventstore'); - - $tempConnection->createSchemaManager()->dropDatabase('eventstore_new'); - $tempConnection->createSchemaManager()->createDatabase('eventstore_new'); - - $tempConnection->close(); + $this->connectionOld = DbalManager::createConnection(); + $this->connectionNew = DbalManager::createConnection('eventstore_new'); } public function tearDown(): void diff --git a/tests/Integration/Pipeline/data/.gitignore b/tests/Integration/Pipeline/data/.gitignore deleted file mode 100644 index f9fda0b8..00000000 --- a/tests/Integration/Pipeline/data/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -old.sqlite3 -new.sqlite3 From b70f8e4337c975376c0c5da2ce51356b5810804f Mon Sep 17 00:00:00 2001 From: David Badura Date: Wed, 12 Jan 2022 23:07:31 +0100 Subject: [PATCH 21/25] create always the database --- tests/Integration/DbalManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Integration/DbalManager.php b/tests/Integration/DbalManager.php index d87ecbb1..9fa166a1 100644 --- a/tests/Integration/DbalManager.php +++ b/tests/Integration/DbalManager.php @@ -44,9 +44,9 @@ public static function createConnection(string $dbName = self::DEFAULT_DB_NAME): if (in_array($dbName, $databases, true)) { $schemaManager->dropDatabase($dbName); - $schemaManager->createDatabase($dbName); } + $schemaManager->createDatabase($dbName); $tempConnection->close(); return $connection; From 55c31b9c8aeac517316b304eac6f0298f71b0e90 Mon Sep 17 00:00:00 2001 From: David Badura Date: Wed, 19 Jan 2022 10:17:20 +0100 Subject: [PATCH 22/25] fix type in normalizeResult --- src/Store/DoctrineStore.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Store/DoctrineStore.php b/src/Store/DoctrineStore.php index 35559a08..8f283be1 100644 --- a/src/Store/DoctrineStore.php +++ b/src/Store/DoctrineStore.php @@ -31,7 +31,7 @@ public function connection(): Connection abstract public function schema(): Schema; /** - * @param array{aggregateId: string, playhead: string, event: class-string, payload: string, recordedOn: string, recordedon?: string, aggregateid?: string} $result + * @param array{aggregateId: string, playhead: string|int, event: class-string, payload: string, recordedOn: string, recordedon?: string, aggregateid?: string} $result * * @return array{aggregateId: string, playhead: int, event: class-string, payload: string, recordedOn: DateTimeImmutable} * From 9adba1aad86d30a39dfa0ac2013383b86099077f Mon Sep 17 00:00:00 2001 From: David Badura Date: Wed, 19 Jan 2022 10:34:02 +0100 Subject: [PATCH 23/25] bump php version to 8.1 in integration tests --- .github/workflows/integration.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 7d33a452..a1ab5028 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -84,7 +84,7 @@ jobs: dependencies: - "locked" php-version: - - "8.0" + - "8.1" operating-system: - "ubuntu-latest" mariadb-version: @@ -137,7 +137,7 @@ jobs: dependencies: - "locked" php-version: - - "8.0" + - "8.1" operating-system: - "ubuntu-latest" mysql-version: @@ -176,7 +176,7 @@ jobs: dependencies: - "locked" php-version: - - "8.0" + - "8.1" operating-system: - "ubuntu-latest" From 4ef2d4b2ea0cb6a8cc1778d69aa759259870ed5d Mon Sep 17 00:00:00 2001 From: David Badura Date: Wed, 19 Jan 2022 10:35:50 +0100 Subject: [PATCH 24/25] use 8.0 for integration tests again to be compatible with composer lock --- .github/workflows/integration.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index a1ab5028..528549dd 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -32,7 +32,7 @@ jobs: dependencies: - "locked" php-version: - - "8.1" + - "8.0" operating-system: - "ubuntu-latest" postgres-version: @@ -84,7 +84,7 @@ jobs: dependencies: - "locked" php-version: - - "8.1" + - "8.0" operating-system: - "ubuntu-latest" mariadb-version: @@ -137,7 +137,7 @@ jobs: dependencies: - "locked" php-version: - - "8.1" + - "8.0" operating-system: - "ubuntu-latest" mysql-version: @@ -176,7 +176,7 @@ jobs: dependencies: - "locked" php-version: - - "8.1" + - "8.0" operating-system: - "ubuntu-latest" From 4b69f9818ab722e6ac02b418291c8764d2d84d98 Mon Sep 17 00:00:00 2001 From: David Badura Date: Wed, 19 Jan 2022 10:38:30 +0100 Subject: [PATCH 25/25] use composer.lock in unit tests only with compatible php version --- .github/workflows/unit.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml index 2fb96f8e..23bd4a0e 100644 --- a/.github/workflows/unit.yml +++ b/.github/workflows/unit.yml @@ -19,13 +19,19 @@ jobs: dependencies: - "lowest" - "highest" - - "locked" php-version: - "8.0" - "8.1" operating-system: - "ubuntu-latest" - "windows-latest" + include: + - dependencies: "locked" + php-version: "8.0" + operating-system: "ubuntu-latest" + - dependencies: "locked" + php-version: "8.0" + operating-system: "windows-latest" steps: - name: "Checkout"