From 3a392ece0f3afb53fbef8de669b5f19f96839e39 Mon Sep 17 00:00:00 2001 From: Uladzimir Tsykun Date: Sat, 2 Dec 2023 21:01:20 +0100 Subject: [PATCH 01/14] Allow to run tests for different versions of symfony and database --- .github/workflows/run_tests.yml | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 4ca92d59..a8130d79 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -23,12 +23,15 @@ jobs: strategy: fail-fast: false matrix: + redis: 6 include: - php: '8.1' - redis: '6' +# - php: '8.2' +# redis: '7' - php: '8.3' redis: '7' - name: PHP ${{ matrix.php }} + symfony: '7.0.*' + name: PHP ${{ matrix.php }} SYMFONY ${{ matrix.symfony }} runs-on: ubuntu-20.04 steps: @@ -39,13 +42,19 @@ jobs: uses: "shivammathur/setup-php@v2" with: coverage: "none" - extensions: "curl, mbstring, pdo, pdo_sqlite, sqlite, zip, redis" + extensions: "curl, pdo, pdo_sqlite, sqlite, zip, redis" php-version: ${{ matrix.php }} tools: composer - name: "Install dependencies" - run: composer update --ansi --no-interaction - + run: | + if [[ ! -z "${{ matrix.symfony }}" ]]; then + export SYMFONY_REQUIRE="${{ matrix.symfony }}" + echo "Install for $SYMFONY_REQUIRE" + composer update --ansi --no-interaction + else + composer install --ansi --no-interaction + fi - name: Start Redis uses: "supercharge/redis-github-action@1.6.0" with: From 9ba3e5c10e0b2dd47bf0ddc158430132fbf15c87 Mon Sep 17 00:00:00 2001 From: Uladzimir Tsykun Date: Sat, 2 Dec 2023 21:03:20 +0100 Subject: [PATCH 02/14] Fix github action --- .github/workflows/run_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index a8130d79..dd69875c 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -23,7 +23,7 @@ jobs: strategy: fail-fast: false matrix: - redis: 6 + redis: '6' include: - php: '8.1' # - php: '8.2' From b38233ab66a7b829c78fdd00003309bfbea66015 Mon Sep 17 00:00:00 2001 From: Uladzimir Tsykun Date: Sat, 2 Dec 2023 21:04:53 +0100 Subject: [PATCH 03/14] Fix github action --- .github/workflows/run_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index dd69875c..60d9b420 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -23,7 +23,7 @@ jobs: strategy: fail-fast: false matrix: - redis: '6' + redis: ['6'] include: - php: '8.1' # - php: '8.2' From 37969f32517541f5aa59a335180cca0a9532c144 Mon Sep 17 00:00:00 2001 From: Uladzimir Tsykun Date: Sat, 2 Dec 2023 21:30:26 +0100 Subject: [PATCH 04/14] Support Symfony 7.0 in tests --- .github/workflows/run_tests.yml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 60d9b420..bbe82208 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -24,14 +24,15 @@ jobs: fail-fast: false matrix: redis: ['6'] + driver: ['sqlite'] include: - php: '8.1' # - php: '8.2' -# redis: '7' +# driver: 'mysql' - php: '8.3' redis: '7' symfony: '7.0.*' - name: PHP ${{ matrix.php }} SYMFONY ${{ matrix.symfony }} + name: PHP ${{ matrix.php }} SYMFONY ${{ matrix.symfony }} - ${{ matrix.driver }} runs-on: ubuntu-20.04 steps: @@ -42,15 +43,20 @@ jobs: uses: "shivammathur/setup-php@v2" with: coverage: "none" - extensions: "curl, pdo, pdo_sqlite, sqlite, zip, redis" + extensions: "curl, pdo, pdo_sqlite, pdo_mysql, pdo_pgsql, sqlite, zip, redis" php-version: ${{ matrix.php }} tools: composer - name: "Install dependencies" run: | + set -x if [[ ! -z "${{ matrix.symfony }}" ]]; then export SYMFONY_REQUIRE="${{ matrix.symfony }}" - echo "Install for $SYMFONY_REQUIRE" + +# temporary workaround to support Symfony 7.0 in tests. + composer config --global --auth http-basic.demo.packeton.org token ${{ secrets.PACKETON_TOKEN }} + composer config repositories.sf7 composer https://demo.packeton.org/sf7 + composer update --ansi --no-interaction else composer install --ansi --no-interaction From 1c44a4b7b9e96d2ad80ac712ccf8be36194d8873 Mon Sep 17 00:00:00 2001 From: Uladzimir Tsykun Date: Sat, 2 Dec 2023 21:32:17 +0100 Subject: [PATCH 05/14] Support Symfony 7.0 in tests --- .github/workflows/run_tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index bbe82208..0983c272 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -48,12 +48,12 @@ jobs: tools: composer - name: "Install dependencies" +# temporary workaround to support Symfony 7.0 in tests. run: | set -x if [[ ! -z "${{ matrix.symfony }}" ]]; then export SYMFONY_REQUIRE="${{ matrix.symfony }}" - -# temporary workaround to support Symfony 7.0 in tests. + composer config --global --auth http-basic.demo.packeton.org token ${{ secrets.PACKETON_TOKEN }} composer config repositories.sf7 composer https://demo.packeton.org/sf7 From 2ff42e262ecc4f55bb5fb878d5b8fa6c05fbcafa Mon Sep 17 00:00:00 2001 From: Uladzimir Tsykun Date: Sat, 2 Dec 2023 21:54:28 +0100 Subject: [PATCH 06/14] Test on postgres sql --- .github/workflows/run_tests.yml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 0983c272..d8fa8267 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -23,16 +23,15 @@ jobs: strategy: fail-fast: false matrix: - redis: ['6'] - driver: ['sqlite'] include: - php: '8.1' -# - php: '8.2' -# driver: 'mysql' + driver: 'sqlite' + redis: 6 - php: '8.3' - redis: '7' + driver: 'pgsql' + redis: 7 symfony: '7.0.*' - name: PHP ${{ matrix.php }} SYMFONY ${{ matrix.symfony }} - ${{ matrix.driver }} + name: PHP ${{ matrix.php }} - ${{ matrix.driver }} SF ${{ matrix.symfony }} runs-on: ubuntu-20.04 steps: @@ -47,6 +46,12 @@ jobs: php-version: ${{ matrix.php }} tools: composer + - name: "Install Postgres" + if: ${{ matrix.driver=='pgsql' }} + uses: harmon758/postgresql-action@v1 + with: + postgresql version: '14' + - name: "Install dependencies" # temporary workaround to support Symfony 7.0 in tests. run: | From 5cf968a2fec7f12ba9c34ebc58b08b365857f93d Mon Sep 17 00:00:00 2001 From: Uladzimir Tsykun Date: Sun, 3 Dec 2023 17:20:39 +0100 Subject: [PATCH 07/14] Run test against SF 7.0 --- composer.json | 2 +- composer.lock | 109 +++++++++++++++++++++++++++----------------------- 2 files changed, 60 insertions(+), 51 deletions(-) diff --git a/composer.json b/composer.json index 3541892f..6e95b0ed 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "require": { "php": ">=8.1", "ext-redis": "*", - "babdev/pagerfanta-bundle": "^4.0", + "babdev/pagerfanta-bundle": "^4.0 || dev-symfony-7 as 4.9.99", "cebe/markdown": "^1.1", "composer/composer": "^2.5", "doctrine/annotations": "^1.0", diff --git a/composer.lock b/composer.lock index 1fbb52f4..fa511c00 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "e2f29747e664bada9406ce065bc7fe43", + "content-hash": "b66de5f55c27f180549d89c112a28064", "packages": [ { "name": "async-aws/core", @@ -136,55 +136,55 @@ }, { "name": "babdev/pagerfanta-bundle", - "version": "v4.2.1", + "version": "dev-symfony-7", "source": { "type": "git", "url": "https://github.com/BabDev/PagerfantaBundle.git", - "reference": "86e8fee90d49afb2aef86e8a92f494d1041105f2" + "reference": "adc4d6bfcc7e963f4b7c0481768617880b537d5d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/BabDev/PagerfantaBundle/zipball/86e8fee90d49afb2aef86e8a92f494d1041105f2", - "reference": "86e8fee90d49afb2aef86e8a92f494d1041105f2", + "url": "https://api.github.com/repos/BabDev/PagerfantaBundle/zipball/adc4d6bfcc7e963f4b7c0481768617880b537d5d", + "reference": "adc4d6bfcc7e963f4b7c0481768617880b537d5d", "shasum": "" }, "require": { "pagerfanta/core": "^3.7 || ^4.0", "php": "^8.1", "psr/container": "^1.0 || ^2.0", - "symfony/config": "^5.4 || ^6.2", - "symfony/dependency-injection": "^5.4 || ^6.2", - "symfony/http-foundation": "^5.4 || ^6.2", - "symfony/http-kernel": "^5.4 || ^6.2", - "symfony/property-access": "^5.4 || ^6.2", - "symfony/routing": "^5.4 || ^6.2" + "symfony/config": "^5.4 || ^6.3 || ^7.0", + "symfony/dependency-injection": "^5.4 || ^6.3 || ^7.0", + "symfony/http-foundation": "^5.4 || ^6.3 || ^7.0", + "symfony/http-kernel": "^5.4 || ^6.3 || ^7.0", + "symfony/property-access": "^5.4 || ^6.3 || ^7.0", + "symfony/routing": "^5.4 || ^6.3 || ^7.0" }, "conflict": { "jms/serializer": "<3.18", "jms/serializer-bundle": "<4.2", "pagerfanta/twig": "<3.7", - "symfony/serializer": "<5.4 || >=6.0,<6.2", - "symfony/translation": "<5.4 || >=6.0,<6.2", - "symfony/twig-bridge": "<5.4 || >=6.0,<6.2", - "symfony/twig-bundle": "<5.4 || >=6.0,<6.2", + "symfony/serializer": "<5.4 || >=6.0,<6.3", + "symfony/translation": "<5.4 || >=6.0,<6.3", + "symfony/twig-bridge": "<5.4 || >=6.0,<6.3", + "symfony/twig-bundle": "<5.4 || >=6.0,<6.3", "twig/twig": "<2.13", "white-october/pagerfanta-bundle": "*" }, "require-dev": { "jms/serializer": "^3.18", "jms/serializer-bundle": "^4.2 || ^5.0", - "matthiasnoback/symfony-dependency-injection-test": "^4.3.1", + "matthiasnoback/symfony-dependency-injection-test": "^5.0@dev", "pagerfanta/twig": "^3.7 || ^4.0", "phpstan/extension-installer": "^1.2", - "phpstan/phpstan": "1.10.15", - "phpstan/phpstan-phpunit": "1.3.13", + "phpstan/phpstan": "1.10.34", + "phpstan/phpstan-phpunit": "1.3.14", "phpstan/phpstan-symfony": "1.3.2", - "phpunit/phpunit": "9.6.8", - "symfony/phpunit-bridge": "^5.4 || ^6.2", - "symfony/serializer": "^5.4 || ^6.2", - "symfony/translation": "^5.4 || ^6.2", - "symfony/twig-bridge": "^5.4 || ^6.2", - "symfony/twig-bundle": "^5.4 || ^6.2", + "phpunit/phpunit": "9.6.12", + "symfony/phpunit-bridge": "^5.4 || ^6.3 || ^7.0", + "symfony/serializer": "^5.4 || ^6.3 || ^7.0", + "symfony/translation": "^5.4 || ^6.3 || ^7.0", + "symfony/twig-bridge": "^5.4 || ^6.3 || ^7.0", + "symfony/twig-bundle": "^5.4 || ^6.3 || ^7.0", "twig/twig": "^2.13 || ^3.0" }, "suggest": { @@ -211,7 +211,7 @@ ], "support": { "issues": "https://github.com/BabDev/PagerfantaBundle/issues", - "source": "https://github.com/BabDev/PagerfantaBundle/tree/v4.2.1" + "source": "https://github.com/BabDev/PagerfantaBundle/tree/symfony-7" }, "funding": [ { @@ -219,7 +219,7 @@ "type": "github" } ], - "time": "2023-06-29T21:45:49+00:00" + "time": "2023-11-16T23:16:18+00:00" }, { "name": "cebe/markdown", @@ -3095,16 +3095,16 @@ }, { "name": "league/flysystem-bundle", - "version": "3.3.1", + "version": "3.3.2", "source": { "type": "git", "url": "https://github.com/thephpleague/flysystem-bundle.git", - "reference": "956c039258e3ed44747c8d97f5132e3e9a6d6765" + "reference": "ad6ef9c0a8d918269ae5cf47da2f0a4a995bfbd8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/flysystem-bundle/zipball/956c039258e3ed44747c8d97f5132e3e9a6d6765", - "reference": "956c039258e3ed44747c8d97f5132e3e9a6d6765", + "url": "https://api.github.com/repos/thephpleague/flysystem-bundle/zipball/ad6ef9c0a8d918269ae5cf47da2f0a4a995bfbd8", + "reference": "ad6ef9c0a8d918269ae5cf47da2f0a4a995bfbd8", "shasum": "" }, "require": { @@ -3150,9 +3150,9 @@ "description": "Symfony bundle integrating Flysystem into Symfony 5.4+ applications", "support": { "issues": "https://github.com/thephpleague/flysystem-bundle/issues", - "source": "https://github.com/thephpleague/flysystem-bundle/tree/3.3.1" + "source": "https://github.com/thephpleague/flysystem-bundle/tree/3.3.2" }, - "time": "2023-11-02T12:55:29+00:00" + "time": "2023-12-02T17:27:51+00:00" }, { "name": "league/flysystem-local", @@ -3435,26 +3435,26 @@ }, { "name": "nelmio/security-bundle", - "version": "v3.0.0", + "version": "v3.1.0", "source": { "type": "git", "url": "https://github.com/nelmio/NelmioSecurityBundle.git", - "reference": "34699d40d81b58b6bd256e34489c799620dff2a4" + "reference": "da7cc88ae338c6b8370c45c2e5fec88d24f5595d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nelmio/NelmioSecurityBundle/zipball/34699d40d81b58b6bd256e34489c799620dff2a4", - "reference": "34699d40d81b58b6bd256e34489c799620dff2a4", + "url": "https://api.github.com/repos/nelmio/NelmioSecurityBundle/zipball/da7cc88ae338c6b8370c45c2e5fec88d24f5595d", + "reference": "da7cc88ae338c6b8370c45c2e5fec88d24f5595d", "shasum": "" }, "require": { "php": "^7.4 || ^8.0", - "symfony/framework-bundle": "^4.4 || ^5.4 || ^6.0", - "symfony/http-kernel": "^4.4 || ^5.4 || ^6.0", - "symfony/security-core": "^4.4 || ^5.4 || ^6.0", - "symfony/security-csrf": "^4.4 || ^5.4 || ^6.0", - "symfony/security-http": "^4.4 || ^5.4 || ^6.0", - "symfony/yaml": "^4.4 || ^5.4 || ^6.0", + "symfony/framework-bundle": "^5.4 || ^6.3 || ^7.0", + "symfony/http-kernel": "^5.4 || ^6.3 || ^7.0", + "symfony/security-core": "^5.4 || ^6.3 || ^7.0", + "symfony/security-csrf": "^5.4 || ^6.3 || ^7.0", + "symfony/security-http": "^5.4 || ^6.3 || ^7.0", + "symfony/yaml": "^5.4 || ^6.3 || ^7.0", "ua-parser/uap-php": "^3.4.4" }, "require-dev": { @@ -3465,10 +3465,10 @@ "phpstan/phpstan-symfony": "^1.1", "phpunit/phpunit": "^9.5", "psr/cache": "^1.0 || ^2.0 || ^3.0", - "symfony/browser-kit": "^4.4 || ^5.4 || ^6.0", - "symfony/cache": "^4.4 || ^5.4 || ^6.0", - "symfony/phpunit-bridge": "^6.0", - "symfony/twig-bundle": "^4.4 || ^5.4 || ^6.0", + "symfony/browser-kit": "^5.4 || ^6.3 || ^7.0", + "symfony/cache": "^5.4 || ^6.3 || ^7.0", + "symfony/phpunit-bridge": "^6.3 || ^7.0", + "symfony/twig-bundle": "^5.4 || ^6.3 || ^7.0", "twig/twig": "^2.10 || ^3.0" }, "type": "symfony-bundle", @@ -3502,9 +3502,9 @@ ], "support": { "issues": "https://github.com/nelmio/NelmioSecurityBundle/issues", - "source": "https://github.com/nelmio/NelmioSecurityBundle/tree/v3.0.0" + "source": "https://github.com/nelmio/NelmioSecurityBundle/tree/v3.1.0" }, - "time": "2022-03-17T07:30:15+00:00" + "time": "2023-12-03T08:44:55+00:00" }, { "name": "okvpn/cron-bundle", @@ -11802,9 +11802,18 @@ "time": "2023-11-20T00:12:19+00:00" } ], - "aliases": [], + "aliases": [ + { + "package": "babdev/pagerfanta-bundle", + "version": "dev-symfony-7", + "alias": "4.9.99", + "alias_normalized": "4.9.99.0" + } + ], "minimum-stability": "dev", - "stability-flags": [], + "stability-flags": { + "babdev/pagerfanta-bundle": 20 + }, "prefer-stable": true, "prefer-lowest": false, "platform": { From 8b76c934c774b8b4f199bee39b60cff98285055c Mon Sep 17 00:00:00 2001 From: Uladzimir Tsykun Date: Sun, 3 Dec 2023 17:21:15 +0100 Subject: [PATCH 08/14] Support PostgresSQL in tests --- .github/workflows/run_tests.yml | 32 ++++++++---- tests/import_db.php | 90 +++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 11 deletions(-) create mode 100644 tests/import_db.php diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index d8fa8267..f6ddbf3c 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -25,14 +25,15 @@ jobs: matrix: include: - php: '8.1' - driver: 'sqlite' + driver: 'SQLITE' redis: 6 + symfony: '6.4.*' - php: '8.3' - driver: 'pgsql' + driver: 'PGSQL' redis: 7 symfony: '7.0.*' - name: PHP ${{ matrix.php }} - ${{ matrix.driver }} SF ${{ matrix.symfony }} - runs-on: ubuntu-20.04 + name: PHP ${{ matrix.php }} SYMFONY ${{ matrix.symfony }} - ${{ matrix.driver }} + runs-on: ubuntu-22.04 steps: - name: "Checkout" @@ -47,21 +48,19 @@ jobs: tools: composer - name: "Install Postgres" - if: ${{ matrix.driver=='pgsql' }} + if: ${{ matrix.driver=='PGSQL' }} uses: harmon758/postgresql-action@v1 with: postgresql version: '14' + postgresql password: '123456' + postgresql db: 'packeton' - name: "Install dependencies" -# temporary workaround to support Symfony 7.0 in tests. run: | set -x - if [[ ! -z "${{ matrix.symfony }}" ]]; then + echo $DATABASE_URL + if [[ "${{ matrix.symfony }}" != "6.4.*" ]]; then export SYMFONY_REQUIRE="${{ matrix.symfony }}" - - composer config --global --auth http-basic.demo.packeton.org token ${{ secrets.PACKETON_TOKEN }} - composer config repositories.sf7 composer https://demo.packeton.org/sf7 - composer update --ansi --no-interaction else composer install --ansi --no-interaction @@ -71,5 +70,16 @@ jobs: with: redis-version: ${{ matrix.redis }} + - name: "Prepare Postgres" + if: ${{ matrix.driver=='PGSQL' }} + run: | + set -x + echo 'DATABASE_URL="postgresql://postgres:123456@127.0.0.1/packeton?serverVersion=14.0&charset=utf8"' >> .env.test; + bin/console doctrine:schema:update --force --complete + + sudo apt install pgloader + gunzip -c tests/dump/test.db.gz > tests/dump/test.db + pgloader sqlite:////${PWD}/tests/dump/test.db pgsql://postgres:123456@127.0.0.1/packeton + - name: "Run tests" run: "composer tests" diff --git a/tests/import_db.php b/tests/import_db.php new file mode 100644 index 00000000..15c8dd3a --- /dev/null +++ b/tests/import_db.php @@ -0,0 +1,90 @@ + $class) { + if (!DBALType::hasType($type)) { + DBALType::addType($type, $class); + } +} + +$conn0 = DriverManager::getConnection(['url' => 'sqlite:///'.$initDb]); +$sm0 = $conn0->createSchemaManager(); +$tab0 = $sm0->listTables(); + +if (!$url = getenv('DATABASE_URL')) { + echo "DATABASE_URL is empty"; + exit(1); +} + +$conn1 = DriverManager::getConnection(['url' => $url]); +$sm1 = $conn1->createSchemaManager(); +$tab1 = $sm1->listTables(); + +$dependMap = []; +foreach ($tab1 as $table) { + $depends = array_map(fn(ForeignKeyConstraint $fk) => $fk->getForeignTableName(), $table->getForeignKeys()); + $dependMap[$table->getName()] = array_flip($depends); +} + +$commitOfOrders = []; +$proc1 = static function($dependMap) use (&$commitOfOrders, &$proc1) { + $resolved = false; + foreach ($dependMap as $table => $deps) { + $deps = $dependMap[$table]; + if (isset($deps[$table])) { + unset($deps[$table]); + $dependMap[$table] = $deps; + } + + if (empty($deps)) { + $commitOfOrders[] = $table; + unset($dependMap[$table]); + + foreach ($dependMap as $t1 => $deps1) { + if (isset($deps1[$table])) { + $resolved = true; + unset($deps1[$table]); + $dependMap[$t1] = $deps1; + } + } + } + } + + if ($resolved) { + return $proc1($dependMap); + } + + return $dependMap; +}; + +$proc1($dependMap); + +$tableMap0 = []; +$tableMapColumn1 = []; +foreach ($tab0 as $table) { + $tableMap0[$table->getName()] = $table; +} + +foreach ($tab1 as $table) { + $table->getColumns(); + $tableMap0[$table->getName()] = $table; +} + +print_r($commitOfOrders); From a3ed4bb44b5d0e80f47bf1eac178d837a092eaa7 Mon Sep 17 00:00:00 2001 From: Uladzimir Tsykun Date: Sun, 3 Dec 2023 17:33:11 +0100 Subject: [PATCH 09/14] Support PostgresSQL in tests --- .github/workflows/run_tests.yml | 3 +-- config/packages/doctrine.yaml | 6 ------ 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index f6ddbf3c..865677df 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -32,7 +32,7 @@ jobs: driver: 'PGSQL' redis: 7 symfony: '7.0.*' - name: PHP ${{ matrix.php }} SYMFONY ${{ matrix.symfony }} - ${{ matrix.driver }} + name: PHP ${{ matrix.php }} ${{ matrix.driver }} SF ${{ matrix.symfony }} runs-on: ubuntu-22.04 steps: @@ -80,6 +80,5 @@ jobs: sudo apt install pgloader gunzip -c tests/dump/test.db.gz > tests/dump/test.db pgloader sqlite:////${PWD}/tests/dump/test.db pgsql://postgres:123456@127.0.0.1/packeton - - name: "Run tests" run: "composer tests" diff --git a/config/packages/doctrine.yaml b/config/packages/doctrine.yaml index 86c173e4..21f28800 100644 --- a/config/packages/doctrine.yaml +++ b/config/packages/doctrine.yaml @@ -55,12 +55,6 @@ doctrine: replace: Oro\ORM\Query\AST\Functions\String\Replace date_format: Oro\ORM\Query\AST\Functions\String\DateFormat -when@test: - doctrine: - dbal: - # "TEST_TOKEN" is typically set by ParaTest - dbname_suffix: '_test%env(default::TEST_TOKEN)%' - when@prod: doctrine: orm: From 50fd946c16aaaff13b9f5fde512b7f6cab268e41 Mon Sep 17 00:00:00 2001 From: Uladzimir Tsykun Date: Sun, 3 Dec 2023 19:06:16 +0100 Subject: [PATCH 10/14] Support PostgresSQL in tests --- .github/workflows/run_tests.yml | 3 +- tests/import_db.php | 67 +++++++++++++++++++++++++-------- 2 files changed, 52 insertions(+), 18 deletions(-) diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 865677df..748bf932 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -77,8 +77,7 @@ jobs: echo 'DATABASE_URL="postgresql://postgres:123456@127.0.0.1/packeton?serverVersion=14.0&charset=utf8"' >> .env.test; bin/console doctrine:schema:update --force --complete - sudo apt install pgloader gunzip -c tests/dump/test.db.gz > tests/dump/test.db - pgloader sqlite:////${PWD}/tests/dump/test.db pgsql://postgres:123456@127.0.0.1/packeton + php tests/import_db.php sqlite:////${PWD}/tests/dump/test.db postgresql://postgres:123456@127.0.0.1/packeton - name: "Run tests" run: "composer tests" diff --git a/tests/import_db.php b/tests/import_db.php index 15c8dd3a..f3ef45fa 100644 --- a/tests/import_db.php +++ b/tests/import_db.php @@ -3,37 +3,40 @@ namespace Packeton\Tests; use Doctrine\DBAL\DriverManager; +use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\ForeignKeyConstraint; use Symfony\Component\Yaml\Yaml; use Doctrine\DBAL\Types\Type as DBALType; require_once __DIR__ . '/../vendor/autoload.php'; -$projectDir = dirname(__DIR__); +$in = $argv[1] ?? null; +$out = $argv[2] ?? null; -$initDb = __DIR__ . '/dump/test.db'; -if (!file_exists($initDb)) { - $db = gzdecode(file_get_contents($projectDir.'/tests/dump/test.db.gz')); - file_put_contents($initDb, $db); +if (empty($in) || empty($out)) { + echo "Usage:\n"; + echo " php import_db.php 'sqlite:////var/www/app/test.db' 'postgresql://postgres:pass123@127.0.0.1:5433/py1'\n"; + return 0; +} + +$dbalTypes = []; +if (file_exists($conf_file = __DIR__.'/config/packages/doctrine.yaml') + || file_exists($conf_file = dirname(__DIR__).'/config/packages/doctrine.yaml') +) { + $dbalTypes = Yaml::parse(file_get_contents($conf_file))['doctrine']['dbal']['types'] ?? []; } -$dbalTypes = Yaml::parse(file_get_contents($projectDir.'/config/packages/doctrine.yaml'))['doctrine']['dbal']['types'] ?? []; foreach ($dbalTypes as $type => $class) { if (!DBALType::hasType($type)) { DBALType::addType($type, $class); } } -$conn0 = DriverManager::getConnection(['url' => 'sqlite:///'.$initDb]); +$conn0 = DriverManager::getConnection(['url' => $in]); $sm0 = $conn0->createSchemaManager(); $tab0 = $sm0->listTables(); -if (!$url = getenv('DATABASE_URL')) { - echo "DATABASE_URL is empty"; - exit(1); -} - -$conn1 = DriverManager::getConnection(['url' => $url]); +$conn1 = DriverManager::getConnection(['url' => $out]); $sm1 = $conn1->createSchemaManager(); $tab1 = $sm1->listTables(); @@ -83,8 +86,40 @@ } foreach ($tab1 as $table) { - $table->getColumns(); - $tableMap0[$table->getName()] = $table; + $columns = array_map(fn(Column $column) => $column->getName(), $table->getColumns()); + $tableMapColumn1[$table->getName()] = $columns; } -print_r($commitOfOrders); +$persister = static function(string $table) use ($conn0, $conn1, $tableMapColumn1, $tableMap0) { + $data = $conn0->executeQuery("SELECT * FROM $table")->fetchAllAssociative(); + $columns = $tableMapColumn1[$table]; + foreach ($data as $item) { + foreach ($item as $key => $value) { + if (!isset($columns[$key])) { + unset($item[$key]); + } + } + $conn1->insert($table, $item); + } + return count($data); +}; + +foreach ($commitOfOrders as $table) { + if (!isset($tableMap0[$table])) { + continue; + } + + $result = $persister($table); + echo "Import $table. Rows $result\n"; + if (str_starts_with($out, 'postgresql')) { + try { + $max = $conn1->executeQuery("SELECT max(id) FROM $table")->fetchOne(); + if ($max > 0) { + $max = $max+1; + $conn1->executeQuery("ALTER SEQUENCE {$table}_id_seq RESTART WITH $max")->fetchOne(); + echo "ALTER SEQUENCE {$table}_id_seq RESTART WITH $max\n"; + } + } catch (\Throwable $e) { + } + } +} From a8dcaa406c223e97925f044045de73952029fed8 Mon Sep 17 00:00:00 2001 From: Uladzimir Tsykun Date: Sun, 3 Dec 2023 19:17:34 +0100 Subject: [PATCH 11/14] Support mysql in tests --- .github/workflows/run_tests.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 748bf932..1de4f425 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -55,6 +55,14 @@ jobs: postgresql password: '123456' postgresql db: 'packeton' + - name: "Install MySql" + if: ${{ matrix.driver=='MYSQL' }} + uses: mirromutth/mysql-action@v1.1 + with: + mysql version: '8.0' + mysql database: 'packeton' + mysql root password: '123456' + - name: "Install dependencies" run: | set -x @@ -79,5 +87,16 @@ jobs: gunzip -c tests/dump/test.db.gz > tests/dump/test.db php tests/import_db.php sqlite:////${PWD}/tests/dump/test.db postgresql://postgres:123456@127.0.0.1/packeton + + - name: "Prepare MySql" + if: ${{ matrix.driver=='MYSQL' }} + run: | + set -x + echo 'DATABASE_URL="mysql://root:123456@127.0.0.1/packeton?serverVersion=8.0&charset=utf8mb4"' >> .env.test; + bin/console doctrine:schema:update --force --complete + + gunzip -c tests/dump/test.db.gz > tests/dump/test.db + php tests/import_db.php 'sqlite:////${PWD}/tests/dump/test.db' 'mysql://root:123456@127.0.0.1/packeton?serverVersion=8.0&charset=utf8mb4' + - name: "Run tests" run: "composer tests" From d0132be5700629f005dcc10091f369b00375aff0 Mon Sep 17 00:00:00 2001 From: Uladzimir Tsykun Date: Sun, 3 Dec 2023 19:19:01 +0100 Subject: [PATCH 12/14] Support mysql in tests --- .github/workflows/run_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 1de4f425..2af3740d 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -29,7 +29,7 @@ jobs: redis: 6 symfony: '6.4.*' - php: '8.3' - driver: 'PGSQL' + driver: 'MYSQL' redis: 7 symfony: '7.0.*' name: PHP ${{ matrix.php }} ${{ matrix.driver }} SF ${{ matrix.symfony }} From 33a852f26d799d26a9d46c99ea18e002b4912e75 Mon Sep 17 00:00:00 2001 From: Uladzimir Tsykun Date: Sun, 3 Dec 2023 19:23:03 +0100 Subject: [PATCH 13/14] Support mysql in tests --- .github/workflows/run_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 2af3740d..db72a8f6 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -96,7 +96,7 @@ jobs: bin/console doctrine:schema:update --force --complete gunzip -c tests/dump/test.db.gz > tests/dump/test.db - php tests/import_db.php 'sqlite:////${PWD}/tests/dump/test.db' 'mysql://root:123456@127.0.0.1/packeton?serverVersion=8.0&charset=utf8mb4' + php tests/import_db.php sqlite:////${PWD}/tests/dump/test.db mysql://root:123456@127.0.0.1:3306/packeton - name: "Run tests" run: "composer tests" From ed7e9c81a77f5590b29d71c9e75cec4a7e2f62b4 Mon Sep 17 00:00:00 2001 From: Uladzimir Tsykun Date: Sun, 3 Dec 2023 19:25:41 +0100 Subject: [PATCH 14/14] Support mysql in tests --- .github/workflows/run_tests.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index db72a8f6..4af172bd 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -28,8 +28,16 @@ jobs: driver: 'SQLITE' redis: 6 symfony: '6.4.*' + - php: '8.2' + driver: 'PGSQL' + redis: 6 + symfony: '6.4.*' - php: '8.3' driver: 'MYSQL' + redis: 6 + symfony: '6.4.*' + - php: '8.3' + driver: 'SQLITE' redis: 7 symfony: '7.0.*' name: PHP ${{ matrix.php }} ${{ matrix.driver }} SF ${{ matrix.symfony }}