diff --git a/CHANGELOG.md b/CHANGELOG.md index dff6d80c0701dfc7eb4ba25cd6a5005e769f724e..76e7e9f90d7e37b3598deb701ff0048a98e2f5f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ branche modernisation-gestion-donnees - Dans le Table->merge, possibilité de définir une requête personnalisée pour les cas complexes +0.9.9 (12/09/2024) +------------------ + +- [Fix] Correction des tests unitaires qui doivent passer +- Possibilité de configurer les tests unitaires via un fichier dnas config/autoload de l'appli pour éviter qu'il soit supprimé à chaque MAJ composer +- [Fix] Correction d'un bug lors du changement de nombre de caractères sur des character varying lors d'un update de DDL + + 0.9.8 (22/08/2024) ------------------ diff --git a/src/Driver/Postgresql/TableManager.php b/src/Driver/Postgresql/TableManager.php index abd34f176218a74fee18bde789de580e45328a8b..73f437ba0e917b756faa76dfff52a71922fef53a 100644 --- a/src/Driver/Postgresql/TableManager.php +++ b/src/Driver/Postgresql/TableManager.php @@ -671,16 +671,10 @@ class TableManager extends AbstractManager implements TableManagerInterface if ($this->sendEvent()->getReturn('no-exec')) return; $column = $new['name']; - if ($this->isColDiffType($old, $new)) { + if ($this->isColDiffType($old, $new) || $this->isColDiffPrecision($old, $new)) { $sql = "ALTER TABLE $table ALTER COLUMN $column TYPE " . $this->makeColumnType($new); $this->addQuery($sql, 'Changement du type de la colonne ' . $column . ' de la table ' . $table); } - if ($this->isColDiffPrecision($old, $new)) { - $length = (int)$new['length']; - $precision = (int)$new['precision']; - $sql = "ALTER TABLE $table ALTER COLUMN $column TYPE " . $this->makeColumnType($new)."($length,$precision);"; - $this->addQuery($sql, 'Changement de la précision de la colonne ' . $column . ' de la table ' . $table); - } } diff --git a/tests/AbstractBddProtocoleTestCase.php b/tests/AbstractBddProtocoleTestCase.php index 63094994a455a366c7b7ac2dd4c8a7c244304625..1c4c6e41ebd0d2c4056cb873870ed4c67506dba5 100644 --- a/tests/AbstractBddProtocoleTestCase.php +++ b/tests/AbstractBddProtocoleTestCase.php @@ -34,7 +34,7 @@ abstract class AbstractBddProtocoleTestCase extends AbstractBddTestCase } if (isset($action['expected'])) { if (is_array($action['expected'])) { - $this->assertArrayEquals($result, $action['expected']); + $this->assertArrayEquals($action['expected'], $result); } else { $this->assertEquals($action['expected'], $result); } diff --git a/tests/AbstractBddTestCase.php b/tests/AbstractBddTestCase.php index 9fb1e630749b72b4e44063c6fa5a52837e947dd3..0ab3082ba7a12218610ff615f721be71181c6afb 100644 --- a/tests/AbstractBddTestCase.php +++ b/tests/AbstractBddTestCase.php @@ -20,16 +20,16 @@ abstract class AbstractBddTestCase extends TestCase - public function assertArrayEquals(array $a1, array $a2, bool $strict = false, string $path = ''): bool + public function assertArrayEquals(array $expected, array $actual, bool $strict = false, string $path = ''): bool { if ('' === $path) { - $this->calc = $a1; + $this->calc = $actual; } - $k1 = array_keys($a1); - $k2 = array_keys($a2); + $k1 = array_keys($actual); + $k2 = array_keys($expected); - $diff = array_diff($k1, $k2); + $diff = array_diff($k1, $k2); $hasInt = false; foreach ($diff as $d) { if (is_int($d)) { @@ -47,21 +47,28 @@ abstract class AbstractBddTestCase extends TestCase } foreach ($k1 as $k) { - if (!isset($a2[$k])) continue; + if (!isset($expected[$k])) continue; + + $p = $path . '/' . $k; + $a1Type = getType($actual[$k]); + $a2Type = getType($expected[$k]); - $p = $path . '/' . $k; - $a1Type = getType($a1[$k]); - $a2Type = getType($a2[$k]); if ($a1Type != $a2Type) { return $this->error('Des valeurs ne sont pas du même type (' . $p . ') : ' . $a2Type . ' attendu pour ' . $a1Type . ' calculé'); } - if (is_array($a1[$k])) { - if (!$this->assertArrayEquals($a1[$k], $a2[$k], $strict, $p)) { + if (is_array($actual[$k])) { + if (!$this->assertArrayEquals($expected[$k], $actual[$k], $strict, $p)) { return $this->error('Des sous-tableaux sont différentes (' . $p . ')'); } } else { - if ($a1[$k] !== $a2[$k]) { - return $this->error('Des valeurs sont différentes (' . $p . ') : ' . $a2[$k] . ' attendu pour ' . $a1[$k] . ' calculé'); + if (('float' == $a1Type || 'double' == $a1Type) && ('float' == $a1Type || 'double' == $a1Type)) { + $diff = abs($actual[$k] - $expected[$k]) > 0.000001; + } else { + $diff = $actual[$k] !== $expected[$k]; + } + + if ($diff) { + return $this->error('Des valeurs sont différentes (' . $p . ') : ' . $expected[$k] . ' attendu pour ' . $actual[$k] . ' calculé'); } } } @@ -87,11 +94,11 @@ abstract class AbstractBddTestCase extends TestCase { switch (gettype($var)) { case "array": - $indexed = array_keys($var) === range(0, count($var) - 1); - $r = []; + $indexed = array_keys($var) === range(0, count($var) - 1); + $r = []; $maxKeyLen = 0; foreach ($var as $key => $value) { - $key = $this->arrayExport($key); + $key = $this->arrayExport($key); $keyLen = strlen($key); if ($keyLen > $maxKeyLen) $maxKeyLen = $keyLen; } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 97414b6d10f0d47280f578ffec350f844bd48370..77b0a53f1db09e94bcc3b3a782902ff94192a630 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -34,13 +34,22 @@ class BddAdminTest public function config(): array { - return require __DIR__ . '/config/config.local.php'; - } - - - + // Fichier présent dans le répertoire de config du module + $filename = __DIR__ . '/config/config.local.php'; + if (file_exists($filename)) { + return require $filename; + } + // Fichier présent dans le répertoire de config de l'application + $filename = dirname(dirname(dirname(dirname(__DIR__)))) + . '/config/autoload/bddadmin-tests.local.php'; + var_dump($filename); + if (file_exists($filename)) { + return require $filename; + } + throw new \Exception('BddAdmin a besoin de configuration pour les tests unitaires. CF. tests/config/config.local.php.dist'); + } diff --git a/tests/config/config.local.php.dist b/tests/config/config.local.php.dist index 2a78712781e22ffc0477ec2c579f78f88e931bae..a309156387bd4eaf3be2ee186d0f2defc664bd3e 100644 --- a/tests/config/config.local.php.dist +++ b/tests/config/config.local.php.dist @@ -1,5 +1,16 @@ <?php +/* + +Fichier de config à copier et à compléter. +A placer dans le même répertoire sous le nom config.local.php + +Autre option : le placer dans le répertoire de votre application. +Cela présuppose que bddAdmin est situé dans le répertoire vendor/unicaen/bddadmin +et que le fichier de configuration soit appelé bddadmin-tests.local.php et placé dans config/autoload de votre application + +*/ + return [ 'bdds' => [ 'Postgresql' => [ @@ -18,13 +29,13 @@ return [ 'username' => '', 'password' => '', ], - 'Mysql' => [ + /*'Mysql' => [ 'driver' => 'Mysql', 'host' => '', 'port' => '', 'dbname' => '', 'username' => '', 'password' => '', - ], + ],*/ ], ];