Skip to content

Commit 5521b8b

Browse files
committed
feat: add MySQL configuration and connection tests to mutation workflow.
1 parent 0a98741 commit 5521b8b

File tree

2 files changed

+117
-7
lines changed

2 files changed

+117
-7
lines changed

.github/workflows/mutation.yml

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,21 @@ jobs:
2424
extensions: pdo, pdo_pgsql, pdo_sqlite
2525
framework-options: --test-framework-options="--group=sqlite,mutation"
2626
hook: |
27-
# Configurar PostgreSQL con Docker
27+
# Config MySQL with Docker
28+
docker run -d \
29+
--name mysql-test \
30+
-e MYSQL_ROOT_PASSWORD=root \
31+
-e MYSQL_DATABASE=yiitest \
32+
-e MYSQL_USER=test \
33+
-e MYSQL_PASSWORD=test \
34+
-p 3306:3306 \
35+
--health-cmd="mysqladmin ping -h localhost" \
36+
--health-interval=10s \
37+
--health-timeout=5s \
38+
--health-retries=5 \
39+
mysql:8.0
40+
41+
# Config PostgreSQL with Docker
2842
docker run -d \
2943
--name postgres-test \
3044
-e POSTGRES_DB=yiitest \
@@ -37,17 +51,29 @@ jobs:
3751
--health-retries=3 \
3852
postgres:16
3953
40-
# Esperar a que PostgreSQL esté listo
54+
# Wait for MySQL to be ready
55+
echo "Waiting for MySQL to be ready..."
56+
timeout 120s bash -c 'until docker exec mysql-test mysqladmin ping -h localhost --silent; do sleep 3; done'
57+
58+
# Wait for PostgreSQL to be ready
4159
echo "Waiting for PostgreSQL to be ready..."
4260
timeout 60s bash -c 'until docker exec postgres-test pg_isready -U postgres; do sleep 2; done'
4361
44-
# Verificar que está funcionando
62+
# Check if MySQL is running
63+
echo "Testing MySQL connection..."
64+
docker exec mysql-test mysql -u root -proot -e "SELECT VERSION();"
65+
66+
# Check if PostgreSQL is running
67+
echo "Testing PostgreSQL connection..."
4568
docker exec postgres-test psql -U root -d yiitest -c "SELECT version();"
4669
47-
# Configurar variables de entorno para los tests
48-
echo "DB_DSN=pgsql:host=localhost;port=5432;dbname=yiitest" >> $GITHUB_ENV
49-
echo "DB_USERNAME=root" >> $GITHUB_ENV
50-
echo "DB_PASSWORD=root" >> $GITHUB_ENV
70+
# Set environment variables for MySQL and PostgreSQL
71+
echo "MYSQL_DSN=mysql:host=localhost;port=3306;dbname=yiitest" >> $GITHUB_ENV
72+
echo "MYSQL_USERNAME=root" >> $GITHUB_ENV
73+
echo "MYSQL_PASSWORD=root" >> $GITHUB_ENV
74+
echo "PGSQL_DSN=pgsql:host=localhost;port=5432;dbname=yiitest" >> $GITHUB_ENV
75+
echo "PGSQL_USERNAME=root" >> $GITHUB_ENV
76+
echo "PGSQL_PASSWORD=root" >> $GITHUB_ENV
5177
phpstan: true
5278
secrets:
5379
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}

tests/mysql/MutationTest.php

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace yii2\extensions\nestedsets\tests\mysql;
6+
7+
use PHPUnit\Framework\Attributes\Group;
8+
use yii2\extensions\nestedsets\tests\support\model\MultipleTree;
9+
use yii2\extensions\nestedsets\tests\TestCase;
10+
11+
#[Group('mutation')]
12+
final class MutationTest extends TestCase
13+
{
14+
protected string $driverName = 'mysql';
15+
protected string|null $dsn = 'mysql:host=127.0.0.1;dbname=yiitest;charset=utf8mb4';
16+
protected string $password = 'root';
17+
protected string $username = 'root';
18+
19+
public function testLeavesMethodRequiresLeftAttributeOrderingForConsistentResults(): void
20+
{
21+
$this->createDatabase();
22+
23+
$root = new MultipleTree(['name' => 'Root']);
24+
25+
$root->makeRoot();
26+
27+
$leaf1 = new MultipleTree(['name' => 'Leaf A']);
28+
29+
$leaf1->appendTo($root);
30+
31+
$leaf2 = new MultipleTree(['name' => 'Leaf B']);
32+
33+
$leaf2->appendTo($root);
34+
35+
$initialLeaves = MultipleTree::find()->leaves()->all();
36+
37+
self::assertCount(
38+
2,
39+
$initialLeaves,
40+
"Should have exactly '2' initial leaf nodes.",
41+
);
42+
43+
$command = $this->getDb()->createCommand();
44+
45+
$command->update('multiple_tree', ['lft' => 3, 'rgt' => 4], ['name' => 'Leaf B'])->execute();
46+
$command->update('multiple_tree', ['lft' => 5, 'rgt' => 6], ['name' => 'Leaf A'])->execute();
47+
$command->update('multiple_tree', ['lft' => 1, 'rgt' => 7], ['name' => 'Root'])->execute();
48+
49+
$leaves = MultipleTree::find()->leaves()->all();
50+
51+
/** @phpstan-var array<array{name: string, lft: int}> */
52+
$expectedLeaves = [
53+
['name' => 'Leaf B', 'lft' => 3],
54+
['name' => 'Leaf A', 'lft' => 5],
55+
];
56+
57+
self::assertCount(
58+
2,
59+
$leaves,
60+
"Should return exactly '2' leaf nodes.",
61+
);
62+
63+
foreach ($leaves as $index => $leaf) {
64+
self::assertInstanceOf(
65+
MultipleTree::class,
66+
$leaf,
67+
"Leaf at index {$index} should be an instance of 'MultipleTree'.",
68+
);
69+
70+
if (isset($expectedLeaves[$index])) {
71+
self::assertEquals(
72+
$expectedLeaves[$index]['name'],
73+
$leaf->getAttribute('name'),
74+
"Leaf at index {$index} should be {$expectedLeaves[$index]['name']} in correct order.",
75+
);
76+
self::assertEquals(
77+
$expectedLeaves[$index]['lft'],
78+
$leaf->getAttribute('lft'),
79+
"Leaf at index {$index} should have left value {$expectedLeaves[$index]['lft']}.",
80+
);
81+
}
82+
}
83+
}
84+
}

0 commit comments

Comments
 (0)