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 testArrayProperty() { $repo = new MetaRepository(); $meta = $repo->fromClass('LRezek\\Arachnid\\Tests\\Entity\\UserDifferentPropertyFormats'); $usr = new Entity\UserDifferentPropertyFormats(); $array = array(3, 5); $usr->setArray($array); foreach ($meta->getProperties() as $prop) { if ($prop->getFormat() == "array") { //Test the get if ($prop->getValue($usr) != serialize($array)) { $this->fail(); } //Test the set $prop->setValue($usr, serialize(array(5, 3))); if ($usr->getArray() != array(5, 3)) { $this->fail(); } return; } } $this->fail(); }