From 914d0dced1408f3f537f2adcca588b8f5490975d Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Mon, 7 Jul 2025 11:07:58 -0400 Subject: [PATCH 1/9] feat: Update mutation workflow to support `PostgreSQL` with docker setup. --- .github/workflows/mutation.yml | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index 6d35498..5f8c555 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -21,7 +21,33 @@ jobs: mutation: uses: php-forge/actions/.github/workflows/infection.yml@main with: + extensions: pdo, pdo_pgsql + framework-options: --test-framework-options="--group=pgsql" + hook: | + # Configurar PostgreSQL con Docker + docker run -d \ + --name postgres-test \ + -e POSTGRES_DB=yiitest \ + -e POSTGRES_USER=root \ + -e POSTGRES_PASSWORD=root \ + -p 5432:5432 \ + --health-cmd="pg_isready -U postgres" \ + --health-interval=10s \ + --health-timeout=5s \ + --health-retries=3 \ + postgres:16 + + # Esperar a que PostgreSQL esté listo + echo "Waiting for PostgreSQL to be ready..." + timeout 60s bash -c 'until docker exec postgres-test pg_isready -U postgres; do sleep 2; done' + + # Verificar que está funcionando + docker exec postgres-test psql -U root -d yiitest -c "SELECT version();" + + # Configurar variables de entorno para los tests + echo "DB_DSN=pgsql:host=localhost;port=5432;dbname=yiitest" >> $GITHUB_ENV + echo "DB_USERNAME=root" >> $GITHUB_ENV + echo "DB_PASSWORD=root" >> $GITHUB_ENV phpstan: true - framework-options: --test-framework-options="--group=sqlite" secrets: STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} From dae4dfbbbcb18017940ff0e8b4dc2b891cddd3b3 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Mon, 7 Jul 2025 11:14:30 -0400 Subject: [PATCH 2/9] feat: add coverage option to mutation workflow for improved testing. --- .github/workflows/mutation.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index 5f8c555..3abb456 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -21,6 +21,7 @@ jobs: mutation: uses: php-forge/actions/.github/workflows/infection.yml@main with: + coverage: pcov extensions: pdo, pdo_pgsql framework-options: --test-framework-options="--group=pgsql" hook: | From 260e9e07331fa6e1e7a6963f1f44e1f9e560c252 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Mon, 7 Jul 2025 11:18:41 -0400 Subject: [PATCH 3/9] feat: remove `coverage` option from mutation workflow and ensure `timeout` is set in infection configuration. --- .github/workflows/mutation.yml | 1 - infection.json5 | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index 3abb456..5f8c555 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -21,7 +21,6 @@ jobs: mutation: uses: php-forge/actions/.github/workflows/infection.yml@main with: - coverage: pcov extensions: pdo, pdo_pgsql framework-options: --test-framework-options="--group=pgsql" hook: | diff --git a/infection.json5 b/infection.json5 index d6406fa..c9970db 100644 --- a/infection.json5 +++ b/infection.json5 @@ -10,5 +10,6 @@ "directories": [ "src" ] - } + }, + "timeout": 10 } From 12014cc03888a9e680c933d357640a0e13d39fbf Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Mon, 7 Jul 2025 11:20:54 -0400 Subject: [PATCH 4/9] feat: update mutation workflow to include `SQLite` support and remove timeout setting from infection configuration. --- .github/workflows/mutation.yml | 4 ++-- infection.json5 | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index 5f8c555..f1d25a1 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -21,8 +21,8 @@ jobs: mutation: uses: php-forge/actions/.github/workflows/infection.yml@main with: - extensions: pdo, pdo_pgsql - framework-options: --test-framework-options="--group=pgsql" + extensions: pdo, pdo_pgsql, pdo_sqlite + framework-options: --test-framework-options="--group=pgsql,sqlite" hook: | # Configurar PostgreSQL con Docker docker run -d \ diff --git a/infection.json5 b/infection.json5 index c9970db..d6406fa 100644 --- a/infection.json5 +++ b/infection.json5 @@ -10,6 +10,5 @@ "directories": [ "src" ] - }, - "timeout": 10 + } } From c977ca528d04f9b976fae481f85edce96dd6d1cf Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Mon, 7 Jul 2025 11:23:19 -0400 Subject: [PATCH 5/9] fix: reorder test framework options for mutation workflow to ensure proper execution. --- .github/workflows/mutation.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index f1d25a1..121eefd 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -22,7 +22,7 @@ jobs: uses: php-forge/actions/.github/workflows/infection.yml@main with: extensions: pdo, pdo_pgsql, pdo_sqlite - framework-options: --test-framework-options="--group=pgsql,sqlite" + framework-options: --test-framework-options="--group=sqlite,pgsql" hook: | # Configurar PostgreSQL con Docker docker run -d \ From 1ff5ed8d06acd9ed2394c767df24a1b18e470fd0 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Mon, 7 Jul 2025 11:25:02 -0400 Subject: [PATCH 6/9] fix: update mutation workflow to remove `pgsql` group from test framework options. --- .github/workflows/mutation.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index 121eefd..d2f383a 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -22,7 +22,7 @@ jobs: uses: php-forge/actions/.github/workflows/infection.yml@main with: extensions: pdo, pdo_pgsql, pdo_sqlite - framework-options: --test-framework-options="--group=sqlite,pgsql" + framework-options: --test-framework-options="--group=sqlite" hook: | # Configurar PostgreSQL con Docker docker run -d \ From 07956d2630c3799b793acdedeba1db0e3447946e Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Mon, 7 Jul 2025 11:34:27 -0400 Subject: [PATCH 7/9] feat: update mutation workflow to include 'mutation' group in test framework options and add MutationTest for tree traversal validation. --- .github/workflows/mutation.yml | 2 +- tests/pgsql/MutationTest.php | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 tests/pgsql/MutationTest.php diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index d2f383a..82de3a7 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -22,7 +22,7 @@ jobs: uses: php-forge/actions/.github/workflows/infection.yml@main with: extensions: pdo, pdo_pgsql, pdo_sqlite - framework-options: --test-framework-options="--group=sqlite" + framework-options: --test-framework-options="--group=sqlite,mutation" hook: | # Configurar PostgreSQL con Docker docker run -d \ diff --git a/tests/pgsql/MutationTest.php b/tests/pgsql/MutationTest.php new file mode 100644 index 0000000..2e14b63 --- /dev/null +++ b/tests/pgsql/MutationTest.php @@ -0,0 +1,33 @@ + 'Root', 'children' => ['Child B', 'Child C', 'Child A']], + ]; + + $updates = [ + ['name' => 'Child B', 'lft' => 4, 'rgt' => 5], + ['name' => 'Child C', 'lft' => 6, 'rgt' => 7], + ['name' => 'Child A', 'lft' => 2, 'rgt' => 3], + ['name' => 'Root', 'rgt' => 8], + ]; + + $tree = $this->createTreeStructure($treeStructure, $updates); + $nodeList = $tree->children()->all(); + + $this->assertNodesInCorrectOrder($nodeList, $expectedOrder, 'Child'); + } +} From 0a98741d2659c9671adda0a61c4a2b61cfdbe19c Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Mon, 7 Jul 2025 11:39:35 -0400 Subject: [PATCH 8/9] fix: add missing driver configuration for `PostgreSQL` in `MutationTest`. --- tests/pgsql/MutationTest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/pgsql/MutationTest.php b/tests/pgsql/MutationTest.php index 2e14b63..a6ded69 100644 --- a/tests/pgsql/MutationTest.php +++ b/tests/pgsql/MutationTest.php @@ -10,6 +10,11 @@ #[Group('mutation')] final class MutationTest extends TestCase { + protected string $driverName = 'pgsql'; + protected string|null $dsn = 'pgsql:host=localhost;dbname=yiitest;port=5432;'; + protected string $password = 'root'; + protected string $username = 'root'; + public function testChildrenMethodRequiresOrderByForCorrectTreeTraversal(): void { $expectedOrder = ['Child A', 'Child B', 'Child C']; From 5521b8b747be3d25cafe78b055154109c18712f6 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Mon, 7 Jul 2025 11:51:40 -0400 Subject: [PATCH 9/9] feat: add `MySQL` configuration and connection tests to mutation workflow. --- .github/workflows/mutation.yml | 40 +++++++++++++--- tests/mysql/MutationTest.php | 84 ++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+), 7 deletions(-) create mode 100644 tests/mysql/MutationTest.php diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index 82de3a7..aa68e8a 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -24,7 +24,21 @@ jobs: extensions: pdo, pdo_pgsql, pdo_sqlite framework-options: --test-framework-options="--group=sqlite,mutation" hook: | - # Configurar PostgreSQL con Docker + # Config MySQL with Docker + docker run -d \ + --name mysql-test \ + -e MYSQL_ROOT_PASSWORD=root \ + -e MYSQL_DATABASE=yiitest \ + -e MYSQL_USER=test \ + -e MYSQL_PASSWORD=test \ + -p 3306:3306 \ + --health-cmd="mysqladmin ping -h localhost" \ + --health-interval=10s \ + --health-timeout=5s \ + --health-retries=5 \ + mysql:8.0 + + # Config PostgreSQL with Docker docker run -d \ --name postgres-test \ -e POSTGRES_DB=yiitest \ @@ -37,17 +51,29 @@ jobs: --health-retries=3 \ postgres:16 - # Esperar a que PostgreSQL esté listo + # Wait for MySQL to be ready + echo "Waiting for MySQL to be ready..." + timeout 120s bash -c 'until docker exec mysql-test mysqladmin ping -h localhost --silent; do sleep 3; done' + + # Wait for PostgreSQL to be ready echo "Waiting for PostgreSQL to be ready..." timeout 60s bash -c 'until docker exec postgres-test pg_isready -U postgres; do sleep 2; done' - # Verificar que está funcionando + # Check if MySQL is running + echo "Testing MySQL connection..." + docker exec mysql-test mysql -u root -proot -e "SELECT VERSION();" + + # Check if PostgreSQL is running + echo "Testing PostgreSQL connection..." docker exec postgres-test psql -U root -d yiitest -c "SELECT version();" - # Configurar variables de entorno para los tests - echo "DB_DSN=pgsql:host=localhost;port=5432;dbname=yiitest" >> $GITHUB_ENV - echo "DB_USERNAME=root" >> $GITHUB_ENV - echo "DB_PASSWORD=root" >> $GITHUB_ENV + # Set environment variables for MySQL and PostgreSQL + echo "MYSQL_DSN=mysql:host=localhost;port=3306;dbname=yiitest" >> $GITHUB_ENV + echo "MYSQL_USERNAME=root" >> $GITHUB_ENV + echo "MYSQL_PASSWORD=root" >> $GITHUB_ENV + echo "PGSQL_DSN=pgsql:host=localhost;port=5432;dbname=yiitest" >> $GITHUB_ENV + echo "PGSQL_USERNAME=root" >> $GITHUB_ENV + echo "PGSQL_PASSWORD=root" >> $GITHUB_ENV phpstan: true secrets: STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} diff --git a/tests/mysql/MutationTest.php b/tests/mysql/MutationTest.php new file mode 100644 index 0000000..53eac97 --- /dev/null +++ b/tests/mysql/MutationTest.php @@ -0,0 +1,84 @@ +createDatabase(); + + $root = new MultipleTree(['name' => 'Root']); + + $root->makeRoot(); + + $leaf1 = new MultipleTree(['name' => 'Leaf A']); + + $leaf1->appendTo($root); + + $leaf2 = new MultipleTree(['name' => 'Leaf B']); + + $leaf2->appendTo($root); + + $initialLeaves = MultipleTree::find()->leaves()->all(); + + self::assertCount( + 2, + $initialLeaves, + "Should have exactly '2' initial leaf nodes.", + ); + + $command = $this->getDb()->createCommand(); + + $command->update('multiple_tree', ['lft' => 3, 'rgt' => 4], ['name' => 'Leaf B'])->execute(); + $command->update('multiple_tree', ['lft' => 5, 'rgt' => 6], ['name' => 'Leaf A'])->execute(); + $command->update('multiple_tree', ['lft' => 1, 'rgt' => 7], ['name' => 'Root'])->execute(); + + $leaves = MultipleTree::find()->leaves()->all(); + + /** @phpstan-var array */ + $expectedLeaves = [ + ['name' => 'Leaf B', 'lft' => 3], + ['name' => 'Leaf A', 'lft' => 5], + ]; + + self::assertCount( + 2, + $leaves, + "Should return exactly '2' leaf nodes.", + ); + + foreach ($leaves as $index => $leaf) { + self::assertInstanceOf( + MultipleTree::class, + $leaf, + "Leaf at index {$index} should be an instance of 'MultipleTree'.", + ); + + if (isset($expectedLeaves[$index])) { + self::assertEquals( + $expectedLeaves[$index]['name'], + $leaf->getAttribute('name'), + "Leaf at index {$index} should be {$expectedLeaves[$index]['name']} in correct order.", + ); + self::assertEquals( + $expectedLeaves[$index]['lft'], + $leaf->getAttribute('lft'), + "Leaf at index {$index} should have left value {$expectedLeaves[$index]['lft']}.", + ); + } + } + } +}