diff --git a/lib/GaletteAuto/AbstractObject.php b/lib/GaletteAuto/AbstractObject.php index 79c2e98..ad4f879 100644 --- a/lib/GaletteAuto/AbstractObject.php +++ b/lib/GaletteAuto/AbstractObject.php @@ -364,7 +364,7 @@ private function buildSelect(): Select return $select; } catch (\Exception $e) { Analog::log( - 'Cannot build SELECT clause for models | ' . $e->getMessage(), + 'Cannot build SELECT clause | ' . $e->getMessage(), Analog::WARNING ); throw $e; diff --git a/tests/GaletteAuto/tests/units/Body.php b/tests/GaletteAuto/tests/units/Body.php new file mode 100644 index 0000000..53a5105 --- /dev/null +++ b/tests/GaletteAuto/tests/units/Body.php @@ -0,0 +1,117 @@ +. + */ + +namespace GaletteAuto\tests\units; + +use Galette\GaletteTestCase; + +/** + * Body tests + * + * @author Johan Cwiklinski + */ +class Body extends GaletteTestCase +{ + protected int $seed = 20240130141727; + + /** + * Test empty + * + * @return void + */ + public function testEmpty(): void + { + $body = new \GaletteAuto\Body($this->zdb); + $this->assertSame('Body', $body->getFieldLabel()); + + $this->assertCount(0, $body->getList()); + $this->assertSame('0 body', $body->displayCount()); + } + + /** + * Test add and update + * + * @return void + */ + public function testCrud(): void + { + $body = new \GaletteAuto\Body($this->zdb); + //ensure the table is empty + $this->assertCount(0, $body->getList()); + + //Add new body + $body->value = 'Coupe'; + $this->assertTrue($body->store(true)); + $first_id = $body->id; + + $this->assertCount(1, $body->getList()); + $listed_body = $body->getList()[0]; + $this->assertInstanceOf(\ArrayObject::class, $listed_body); + $this->assertGreaterThan(0, $listed_body->id_body); + $this->assertSame('Coupe', $listed_body->body); + $this->assertSame('1 body', $body->displayCount()); + + //add another one + $body = new \GaletteAuto\Body($this->zdb); + $body->value = 'Brea'; + $this->assertTrue($body->store(true)); + $id = $body->id; + + $this->assertCount(2, $body->getList()); + $this->assertSame('2 bodies', $body->displayCount()); + + $body = new \GaletteAuto\Body($this->zdb); + $this->assertTrue($body->load($id)); + $body->value = 'Break'; + $this->assertTrue($body->store()); + + $this->assertCount(2, $body->getList()); + $this->assertSame('2 bodies', $body->displayCount()); + + $body = new \GaletteAuto\Body($this->zdb); + $this->assertTrue($body->delete([$first_id])); + $list = $body->getList(); + $this->assertCount(1, $list); + $last_body = $list[0]; + $this->assertSame($id, $last_body->id_body); + } + + /** + * Test load error + * + * @return void + */ + public function testLoadError(): void + { + $body = new \GaletteAuto\Body($this->zdb); + $this->assertFalse($body->load(999)); + } + + /** + * Test getClassName + * + * @return void + */ + public function testGetClassName(): void + { + $this->assertSame(\GaletteAuto\Body::class, \GaletteAuto\Body::getClassForPropName('body')); + } +} diff --git a/tests/GaletteAuto/tests/units/Color.php b/tests/GaletteAuto/tests/units/Color.php index 12fbe89..56c9803 100644 --- a/tests/GaletteAuto/tests/units/Color.php +++ b/tests/GaletteAuto/tests/units/Color.php @@ -99,9 +99,19 @@ public function testCrud(): void * * @return void */ - public function testLoadError() + public function testLoadError(): void { $color = new \GaletteAuto\Color($this->zdb); $this->assertFalse($color->load(999)); } + + /** + * Test getClassName + * + * @return void + */ + public function testGetClassName(): void + { + $this->assertSame(\GaletteAuto\Color::class, \GaletteAuto\Color::getClassForPropName('color')); + } }