From 2c7d5ff396dcfb0a7be103fcb2c0447e2c9b5577 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Thu, 28 Nov 2024 10:46:41 +0700 Subject: [PATCH 1/4] Remove tests from export-ignore --- .gitattributes | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitattributes b/.gitattributes index ac71bc6..7f473c9 100644 --- a/.gitattributes +++ b/.gitattributes @@ -33,7 +33,6 @@ /docker-compose.yml export-ignore /psalm.xml export-ignore /rector.php export-ignore -/tests export-ignore /docs export-ignore # Avoid merge conflicts in CHANGELOG From 9c2f07c91b32d595cfc3e835afa7af7ff5441cc8 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Thu, 28 Nov 2024 11:13:52 +0700 Subject: [PATCH 2/4] Update workflows --- .github/workflows/mssql.yml | 3 --- .github/workflows/mutation.yml | 3 --- .github/workflows/mysql.yml | 3 --- .github/workflows/oracle.yml | 3 --- .github/workflows/pgsql.yml | 3 --- .github/workflows/sqlite.yml | 3 --- 6 files changed, 18 deletions(-) diff --git a/.github/workflows/mssql.yml b/.github/workflows/mssql.yml index c529c53..9ca11cd 100644 --- a/.github/workflows/mssql.yml +++ b/.github/workflows/mssql.yml @@ -87,9 +87,6 @@ jobs: FULL_BRANCH_NAME: ${{ env.FULL_BRANCH_NAME }} WORK_PACKAGE_URL: ${{ env.WORK_PACKAGE_URL }} - - name: Install dependencies with composer. - run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi - - name: Run tests with phpunit. run: vendor/bin/phpunit --testsuite=Mssql --coverage-clover=coverage.xml --colors=always diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index d5d4707..d001505 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -72,9 +72,6 @@ jobs: FULL_BRANCH_NAME: ${{ env.FULL_BRANCH_NAME }} WORK_PACKAGE_URL: ${{ env.WORK_PACKAGE_URL }} - - name: Install dependencies with composer. - run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi - - name: Run infection. run: | vendor/bin/roave-infection-static-analysis-plugin --threads=2 --ignore-msi-with-no-mutations --only-covered --test-framework-options="--testsuite=Pgsql" diff --git a/.github/workflows/mysql.yml b/.github/workflows/mysql.yml index 98ab01d..8945494 100644 --- a/.github/workflows/mysql.yml +++ b/.github/workflows/mysql.yml @@ -79,9 +79,6 @@ jobs: FULL_BRANCH_NAME: ${{ env.FULL_BRANCH_NAME }} WORK_PACKAGE_URL: ${{ env.WORK_PACKAGE_URL }} - - name: Install dependencies with composer. - run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi - - name: Run tests with phpunit. run: vendor/bin/phpunit --testsuite=Mysql --coverage-clover=coverage.xml --colors=always diff --git a/.github/workflows/oracle.yml b/.github/workflows/oracle.yml index 8c1c10d..754ec1d 100644 --- a/.github/workflows/oracle.yml +++ b/.github/workflows/oracle.yml @@ -83,9 +83,6 @@ jobs: FULL_BRANCH_NAME: ${{ env.FULL_BRANCH_NAME }} WORK_PACKAGE_URL: ${{ env.WORK_PACKAGE_URL }} - - name: Install dependencies with composer. - run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi - - name: Run tests with phpunit. run: vendor/bin/phpunit --testsuite=Oracle --coverage-clover=coverage.xml --colors=always diff --git a/.github/workflows/pgsql.yml b/.github/workflows/pgsql.yml index 723576e..efc9808 100644 --- a/.github/workflows/pgsql.yml +++ b/.github/workflows/pgsql.yml @@ -79,9 +79,6 @@ jobs: FULL_BRANCH_NAME: ${{ env.FULL_BRANCH_NAME }} WORK_PACKAGE_URL: ${{ env.WORK_PACKAGE_URL }} - - name: Install dependencies with composer. - run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi - - name: Run tests with phpunit. run: vendor/bin/phpunit --testsuite=Pgsql --coverage-clover=coverage.xml --colors=always diff --git a/.github/workflows/sqlite.yml b/.github/workflows/sqlite.yml index 8244423..da69d08 100644 --- a/.github/workflows/sqlite.yml +++ b/.github/workflows/sqlite.yml @@ -77,9 +77,6 @@ jobs: FULL_BRANCH_NAME: ${{ env.FULL_BRANCH_NAME }} WORK_PACKAGE_URL: ${{ env.WORK_PACKAGE_URL }} - - name: Install dependencies with composer. - run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi - - name: Run tests with phpunit. run: vendor/bin/phpunit --testsuite=Sqlite --coverage-clover=coverage.xml --colors=always From fb356dc8189d1dc6908e9d473ab5be795bc19dc0 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Thu, 28 Nov 2024 11:56:04 +0700 Subject: [PATCH 3/4] Fix when there is a namespace but the directory does not exist --- composer.json | 1 + src/Service/MigrationService.php | 4 ++++ .../Common/Service/AbstractMigrationServiceTest.php | 13 +++++++++++++ 3 files changed, 18 insertions(+) diff --git a/composer.json b/composer.json index 2ab2a1b..890bd60 100644 --- a/composer.json +++ b/composer.json @@ -60,6 +60,7 @@ "Yiisoft\\Db\\Migration\\Tests\\": "tests", "Yiisoft\\Db\\Migration\\Tests\\Support\\": "tests/Support", "Yiisoft\\Db\\Migration\\Tests\\ForTest\\": "tests/Support", + "Yiisoft\\Db\\Migration\\Tests\\NonExistsDirectory\\": "tests/non-exists-directory", "Yiisoft\\Db\\Migration\\Tests\\Support\\MigrationsExtra\\": [ "tests/Support/MigrationsExtra", "tests/Support/MigrationsExtra2" diff --git a/src/Service/MigrationService.php b/src/Service/MigrationService.php index 909488f..a6d5805 100644 --- a/src/Service/MigrationService.php +++ b/src/Service/MigrationService.php @@ -455,6 +455,10 @@ private function getNamespacesFromPath(string $path): array foreach ($map as $namespace => $directories) { foreach ($directories as $directory) { + if (!is_dir($directory)) { + continue; + } + $directory = realpath($directory) . DIRECTORY_SEPARATOR; if (str_starts_with($path, $directory)) { diff --git a/tests/Common/Service/AbstractMigrationServiceTest.php b/tests/Common/Service/AbstractMigrationServiceTest.php index 6e0460a..a3de74d 100644 --- a/tests/Common/Service/AbstractMigrationServiceTest.php +++ b/tests/Common/Service/AbstractMigrationServiceTest.php @@ -70,6 +70,19 @@ public function testGetNamespacesFromPathForNoHavingNamespacePath(): void $this->assertSame([], $getNamespaceFromPath->invoke($migrationService, $path)); } + public function testGetNamespacesFromPathForNoExistsDirectory(): void + { + $migrationService = $this->container->get(MigrationService::class); + + $getNamespaceFromPath = new ReflectionMethod($migrationService, 'getNamespacesFromPath'); + $getNamespaceFromPath->setAccessible(true); + + // There is a path to the namespace, but the directory does not exist + $path = dirname(__DIR__, 3) . '/non-exists-directory'; + + $this->assertSame([], $getNamespaceFromPath->invoke($migrationService, $path)); + } + /** * Test MigrationService::getNamespacesFromPath() returns namespaces corresponding to the longest subdirectory of a path. * One path can match to several namespaces. From 80c90810bc02302f25c4fdedfc44a4cc6cf384f8 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Thu, 28 Nov 2024 11:57:42 +0700 Subject: [PATCH 4/4] Update --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 890bd60..36fc064 100644 --- a/composer.json +++ b/composer.json @@ -58,9 +58,9 @@ "autoload-dev": { "psr-4": { "Yiisoft\\Db\\Migration\\Tests\\": "tests", - "Yiisoft\\Db\\Migration\\Tests\\Support\\": "tests/Support", - "Yiisoft\\Db\\Migration\\Tests\\ForTest\\": "tests/Support", "Yiisoft\\Db\\Migration\\Tests\\NonExistsDirectory\\": "tests/non-exists-directory", + "Yiisoft\\Db\\Migration\\Tests\\ForTest\\": "tests/Support", + "Yiisoft\\Db\\Migration\\Tests\\Support\\": "tests/Support", "Yiisoft\\Db\\Migration\\Tests\\Support\\MigrationsExtra\\": [ "tests/Support/MigrationsExtra", "tests/Support/MigrationsExtra2"