diff --git a/.github/workflows/qa.yaml b/.github/workflows/qa.yaml index 1535374..53665d9 100644 --- a/.github/workflows/qa.yaml +++ b/.github/workflows/qa.yaml @@ -24,11 +24,14 @@ jobs: php-version: 8.2 - name: Validate composer.json - run: composer validate --strict + run: composer validate --ansi --strict - name: Install dependencies uses: ramsey/composer-install@v2 + - name: Run ergebnis/composer-normalize + run: composer normalize --ansi --dry-run + - name: Check CS-Fixer run: composer cs:check diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 7aba257..d87cd2f 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -27,6 +27,27 @@ jobs: dependencies: "highest" phpunit-flags: "--fail-on-risky" + env: + MYSQL_HOST: 127.0.0.1 + MYSQL_PORT: 3306 + MYSQL_USER: root + MYSQL_PASSWORD: pimcore + MYSQL_DATABASE: pimcore + MYSQL_SERVER_VERSION: "10.11.5-MariaDB" + + services: + mariadb: + image: mariadb:10.11.5 + env: + MYSQL_ROOT_PASSWORD: pimcore + options: >- + --health-cmd="healthcheck.sh --connect --innodb_initialized" + --health-interval=10s + --health-timeout=5s + --health-retries=5 + ports: + - 3306:3306 + steps: - name: Git Checkout uses: actions/checkout@v4 @@ -37,7 +58,7 @@ jobs: php-version: ${{ matrix.php-version }} - name: Install dependencies - uses: ramsey/composer-install@v2 + uses: ramsey/composer-install@v3 with: dependency-versions: ${{ matrix.dependencies }} diff --git a/composer.json b/composer.json index 6da2ffd..dbb1352 100644 --- a/composer.json +++ b/composer.json @@ -56,8 +56,8 @@ }, "config": { "allow-plugins": { - "ergebnis/composer-normalize": true, "endroid/installer": true, + "ergebnis/composer-normalize": true, "phpstan/extension-installer": true }, "preferred-install": "dist", diff --git a/tests/Functional/ResetDatabaseTest.php b/tests/Functional/ResetDatabaseTest.php new file mode 100644 index 0000000..51df3c9 --- /dev/null +++ b/tests/Functional/ResetDatabaseTest.php @@ -0,0 +1,54 @@ +setAutoExit(false); + + /** @var ManagerRegistry $registry */ + $registry = self::getContainer()->get('doctrine'); + + /** @var Connection $connection */ + $connection = $registry->getConnection(); + + $resetter = new PimcoreDatabaseResetter($application, $registry); + $resetter->resetDatabase(); + + self::assertCount(1, $connection->fetchAllNumeric('SELECT * FROM assets')); + self::assertCount(1, $connection->fetchAllNumeric('SELECT * FROM documents')); + self::assertCount(1, $connection->fetchAllNumeric('SELECT * FROM objects')); + self::assertCount(2, $users = $connection->fetchAllAssociative('SELECT * FROM users')); + self::assertSame('system', $users[0]['name']); + self::assertSame('admin', $users[1]['name']); + } + + public function databaseResetModeProvider(): iterable + { + yield 'Default mode' => ['']; + yield 'Dump mode' => [self::isPimcore10() ? 'dump-10' : 'dump']; + } + + private static function isPimcore10(): bool + { + return !method_exists(Version::class, 'getMajorVersion') || 10 === Version::getMajorVersion(); + } +} diff --git a/tests/app/dump-10/setup.sql b/tests/app/dump-10/setup.sql new file mode 100644 index 0000000..d7abba1 --- /dev/null +++ b/tests/app/dump-10/setup.sql @@ -0,0 +1,14 @@ +INSERT INTO `assets` +VALUES (1, 0, 'folder', '', '/', NULL, 1710529075, 1710529075, 1, 1, NULL, 0, 0); + +INSERT INTO `documents` +VALUES (1, 0, 'page', '', '/', 999999, 1, 1710529075, 1710529075, 1, 1, 0); + +INSERT INTO `documents_page` +VALUES (1, 'App\\Controller\\DefaultController::defaultAction', '', '', '', '', NULL, NULL, '', NULL, NULL, NULL); + +INSERT INTO `objects` +VALUES (1, 0, 'folder', '', '/', 999999, 1, 1710529075, 1710529075, 1, 1, NULL, NULL, NULL, NULL, 0); + +INSERT INTO `users` (id, parentId, type, name, admin, active) +VALUES (0, 0, 'user', 'system', 1, 1); diff --git a/tests/app/dump/setup.sql b/tests/app/dump/setup.sql new file mode 100644 index 0000000..e20d84f --- /dev/null +++ b/tests/app/dump/setup.sql @@ -0,0 +1,11 @@ +INSERT INTO `assets` +VALUES (1, 0, 'folder', '', '/', NULL, 1710529075, 1710529075, NULL, 1, 1, NULL, 0, 0); + +INSERT INTO `documents` +VALUES (1, 0, 'page', '', '/', 999999, 1, 1710529075, 1710529075, 1, 1, 0); + +INSERT INTO `documents_page` +VALUES (1, 'App\\Controller\\DefaultController::defaultAction', '', '', '', NULL, NULL, '', NULL, NULL, NULL); + +INSERT INTO `objects` +VALUES (1, 0, 'folder', '', '/', 999999, 1, 1710529075, 1710529075, 1, 1, NULL, NULL, NULL, NULL, 0);