function testPropertyFormats() { $user = new UserDifferentPropertyFormats(); $user->setTestId($this->id); //Set a scalar $user->setScalar(5); //Set an array $user->setArray(array(1, 2, 3)); //Set a to-Json property $user->setJson(array("type" => "json", "desc" => "this is json in the db")); //Set a date property $date = new \DateTime('now', new \DateTimeZone('UTC')); $user->setDate($date); //Set a garbage property $user->setGarbage(5); //Set an object property $obj = new ClassParamTestClass(1); $user->setClass($obj); //Flush ArachnidTest::$arachnid->persist($user); ArachnidTest::$arachnid->flush(); $user = ArachnidTest::$arachnid->reload($user); //Do assertions $this->assertEquals(5, $user->getScalar()); $this->assertEquals(array(1, 2, 3), $user->getArray()); $this->assertEquals(array("type" => "json", "desc" => "this is json in the db"), $user->getJson()); $this->assertEquals($date, $user->getDate()); $this->assertEquals(null, $user->getGarbage()); $this->assertEquals($obj, $user->getClass()); }
function testScalarProperty() { $repo = new MetaRepository(); $meta = $repo->fromClass('LRezek\\Arachnid\\Tests\\Entity\\UserDifferentPropertyFormats'); $usr = new Entity\UserDifferentPropertyFormats(); $usr->setScalar(3); foreach ($meta->getProperties() as $prop) { if ($prop->getFormat() == "scalar" && !$prop->isIndexed()) { //Test the get if ($prop->getValue($usr) != 3) { $this->fail(); } //Test the set $prop->setValue($usr, 5); if ($usr->getScalar() != 5) { $this->fail(); } return; } } $this->fail(); }