Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for ranning tests in db package #278

Merged
merged 5 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/mssql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/mutation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/oracle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/pgsql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/sqlite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@
"autoload-dev": {
"psr-4": {
"Yiisoft\\Db\\Migration\\Tests\\": "tests",
"Yiisoft\\Db\\Migration\\Tests\\Support\\": "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"
Expand Down
4 changes: 4 additions & 0 deletions src/Service/MigrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
[$sourcePath, $namespace] = $item;

if (!is_dir($sourcePath)) {
continue;

Check warning on line 141 in src/Service/MigrationService.php

View workflow job for this annotation

GitHub Actions / PHP 8.3

Escaped Mutant for Mutator "Continue_": --- Original +++ New @@ @@ foreach ($migrationPaths as $item) { [$sourcePath, $namespace] = $item; if (!is_dir($sourcePath)) { - continue; + break; } $handle = opendir($sourcePath); while (($file = readdir($handle)) !== false) {
}

$handle = opendir($sourcePath);
Expand Down Expand Up @@ -455,6 +455,10 @@

foreach ($map as $namespace => $directories) {
foreach ($directories as $directory) {
if (!is_dir($directory)) {
continue;

Check warning on line 459 in src/Service/MigrationService.php

View check run for this annotation

Codecov / codecov/patch

src/Service/MigrationService.php#L458-L459

Added lines #L458 - L459 were not covered by tests
}

$directory = realpath($directory) . DIRECTORY_SEPARATOR;

if (str_starts_with($path, $directory)) {
Expand Down
13 changes: 13 additions & 0 deletions tests/Common/Service/AbstractMigrationServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading