diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index fab5eba..e6e477e 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -5,7 +5,6 @@ on: push: branches: - master - - test-driver jobs: tests: diff --git a/src/Driver/Test/TestDriver.php b/src/Driver/Test/TestDriver.php index 77c5c83..fd68f23 100644 --- a/src/Driver/Test/TestDriver.php +++ b/src/Driver/Test/TestDriver.php @@ -6,6 +6,7 @@ use Aternos\Model\Driver\Features\CRUDAbleInterface; use Aternos\Model\Driver\Features\CRUDQueryableInterface; use Aternos\Model\ModelInterface; +use Aternos\Model\ModelRegistry; use Aternos\Model\Query\Query; use Aternos\Model\Query\QueryResult; use Exception; @@ -73,6 +74,7 @@ public function addEntry(string $tableName, array $entry): static */ public function clearTables(): static { + ModelRegistry::getInstance()->clearAll(); $this->tables = []; return $this; } diff --git a/src/Driver/Test/TestTable.php b/src/Driver/Test/TestTable.php index d6e6c75..a60bbb6 100644 --- a/src/Driver/Test/TestTable.php +++ b/src/Driver/Test/TestTable.php @@ -3,6 +3,7 @@ namespace Aternos\Model\Driver\Test; use Aternos\Model\ModelInterface; +use Aternos\Model\ModelRegistry; use Aternos\Model\Query\DeleteQuery; use Aternos\Model\Query\GroupField; use Aternos\Model\Query\OrderField; @@ -194,6 +195,7 @@ protected function orderEntries(array $entries, array $order): array public function clear(): static { $this->entries = []; + ModelRegistry::getInstance()->clearModel($this->name); return $this; } diff --git a/src/GenericModel.php b/src/GenericModel.php index 4a81167..7e7ea91 100644 --- a/src/GenericModel.php +++ b/src/GenericModel.php @@ -304,6 +304,22 @@ public static function getModelFromData(array $rawData): ?static return $model->applyData($rawData); } + /** + * Disable the registry temporarily + */ + public static function disableRegistry(): void + { + static::$registry = false; + } + + /** + * Enable the registry again/temporarily + */ + public static function enableRegistry(): void + { + static::$registry = true; + } + /** * * diff --git a/src/ModelRegistry.php b/src/ModelRegistry.php index 5abc652..ae9764a 100644 --- a/src/ModelRegistry.php +++ b/src/ModelRegistry.php @@ -60,6 +60,26 @@ public function delete(ModelInterface $model): void unset($this->registry[$model::getName()][$model->getId()]); } + /** + * @param string $modelName + * @return void + */ + public function clearModel(string $modelName): void + { + if (!isset($this->registry[$modelName])) { + return; + } + unset($this->registry[$modelName]); + } + + /** + * @return void + */ + public function clearAll(): void + { + $this->registry = []; + } + /** * @var ModelRegistry|null */ diff --git a/test/src/TestModel.php b/test/src/TestModel.php index 340c776..54ef7aa 100644 --- a/test/src/TestModel.php +++ b/test/src/TestModel.php @@ -4,7 +4,6 @@ class TestModel extends \Aternos\Model\GenericModel { - protected static bool $registry = false; public mixed $id; public ?string $text = null; public ?int $number = null; diff --git a/test/tests/TestDriverTest.php b/test/tests/TestDriverTest.php index c0c58a6..d3712ab 100644 --- a/test/tests/TestDriverTest.php +++ b/test/tests/TestDriverTest.php @@ -14,7 +14,6 @@ use Aternos\Model\Test\Src\TestModel; use Exception; use PHPUnit\Framework\TestCase; -use PHPUnit\Util\Test; class TestDriverTest extends TestCase { @@ -503,6 +502,7 @@ public function testSelectGroupAverage(): void */ public function testUpdate(): void { + TestModel::disableRegistry(); $model = TestModel::get("1B"); $this->assertEquals("B", $model->text); @@ -528,6 +528,7 @@ public function testUpdate(): void */ public function testDeleteQuery(): void { + TestModel::disableRegistry(); $this->assertNotNull(TestModel::get("1B")); $model = new TestModel();