From bee991e3001a21aa34a2e9645512e94cf269ee42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Fri, 26 Jun 2020 00:22:58 +0200 Subject: [PATCH] MAPG-177 add test for Model --- tests/PersistentData/Model/ModelTest.php | 89 ++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 tests/PersistentData/Model/ModelTest.php diff --git a/tests/PersistentData/Model/ModelTest.php b/tests/PersistentData/Model/ModelTest.php new file mode 100644 index 0000000..6e0b042 --- /dev/null +++ b/tests/PersistentData/Model/ModelTest.php @@ -0,0 +1,89 @@ + OtherModel::class]; + + private string $name; + + private bool $valid; + + public function setName(string $name): void + { + $this->name = $name; + } + + public function setValid(bool $valid): void + { + $this->valid = $valid; + } + + public function getName(): string + { + return $this->name; + } + + public function getValid(): bool + { + return $this->valid; + } +} + +final class ModelTest extends TestCase +{ + public function testCanReturnTable(): void + { + $this->assertEquals('test_table', DummyModel::getTable()); + } + + public function testCanReturnFields(): void + { + $this->assertEquals(['id', 'name', 'valid'], DummyModel::getFields()); + } + + public function testCanReturnRelations(): void + { + $this->assertEquals(['other_model' => OtherModel::class], DummyModel::getRelations()); + } + + public function testCanBeConvertedToArray(): void + { + $model = new DummyModel(); + $model->setId(123); + $model->setName('John'); + $model->setValid(true); + + $this->assertEquals([ + 'id' => 123, + 'name' => 'John', + 'valid' => true + ], $model->toArray()); + } + + public function testCanSaveAndResetSnapshot(): void + { + $model = new DummyModel(); + $model->setId(123); + $model->setName('John'); + $model->setValid(true); + + $model->saveSnapshot(); + + $this->assertEquals([ + 'id' => 123, + 'name' => 'John', + 'valid' => true + ], $model->getSnapshot()); + + $model->resetSnapshot(); + + $this->assertEquals([], $model->getSnapshot()); + } +}