Commit db71f830 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

- Renforcement du système de tests automatisés.

- [Fix] Meilleure gestion de la méthode exists, lorsqu'on traite sur le schéma public en Postgresql
parent db2ee2f5
Loading
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ use Unicaen\BddAdmin\Ddl\DdlFilters;
use Unicaen\BddAdmin\Driver\DriverInterface;
use Unicaen\BddAdmin\Event\EventManagerAwareTrait;
use Unicaen\BddAdmin\Exception\BddCompileException;
use Unicaen\BddAdmin\Exception\BddException;
use Unicaen\BddAdmin\Logger\DefaultLogger;
use Unicaen\BddAdmin\Logger\LoggerAwareTrait;
use Unicaen\BddAdmin\Manager\CompilableInterface;
@@ -498,6 +499,23 @@ class Bdd



    public function normalizeObjectName(string|array $object): string
    {
        if (is_string($object)) {
            [$schema, $name] = Util::explodedFullObjectName($object);
        }else{
            if (isset($object['name'])){
                throw new BddException('Propriété d\'objet "name" non fournie');
            }
            $schema = $object['schema'] ?? null;
            $name = $object['name'];
        }

        return Util::fullObjectName($schema, $name);
    }



    public function data(): DataManager
    {
        if (!isset($this->data)) {
+3 −0
Original line number Diff line number Diff line
@@ -4,6 +4,8 @@ namespace Unicaen\BddAdmin\Manager;

use Unicaen\BddAdmin\Bdd;
use Unicaen\BddAdmin\Event\EventManagerAwareTrait;
use Unicaen\BddAdmin\Exception\BddException;
use Unicaen\BddAdmin\Util;


abstract class AbstractManager implements ManagerInterface
@@ -75,6 +77,7 @@ abstract class AbstractManager implements ManagerInterface

    public function exists(string $name): bool
    {
        $name = $this->bdd->normalizeObjectName($name);
        $list = $this->getList($name);

        return count($list) == 1 && in_array($name, $list);
+17 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ abstract class AbstractBddProtocoleTestCase extends AbstractBddTestCase
                $tested = true;
            }
            if (isset($action['expected'])) {
                $action['expected'] = $this->normalizeExpected($action['expected']);
                if (is_array($action['expected'])) {
                    $this->assertArrayEquals($action['expected'], $result);
                } else {
@@ -56,6 +57,22 @@ abstract class AbstractBddProtocoleTestCase extends AbstractBddTestCase



    protected function normalizeExpected(array $expected): array
    {

        $res = [];
        foreach( $expected as $k => $v ){
            if (is_int($k) && is_string($v)){
                $res[$k] = $this->bdd->normalizeObjectName($v);
            }elseif(is_string($k)){
               $res[$this->bdd->normalizeObjectName($k)] = $v;
            }
        }
        return $res;
    }



    public function testProtocole()
    {
        foreach ($this->protocole as $action) {
+1 −3
Original line number Diff line number Diff line
@@ -8,8 +8,6 @@ final class PostgresqlTest extends AbstractBddProtocoleTestCase
    {
        parent::setUp();

        $sql = "DROP SCHEMA IF EXISTS bddadmintests CASCADE";

        $this->bdd->exec($sql);
        $this->bdd->drop();
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ class BddAdminTest
        // 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);
        //var_dump($filename);
        if (file_exists($filename)) {
            return require $filename;
        }
Loading