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 testDateProperty() { $repo = new MetaRepository(); $meta = $repo->fromClass('LRezek\\Arachnid\\Tests\\Entity\\UserDifferentPropertyFormats'); $usr = new Entity\UserDifferentPropertyFormats(); $currentDate = new \DateTime('now', new \DateTimeZone('UTC')); $usr->setDate($currentDate); foreach ($meta->getProperties() as $prop) { if ($prop->getFormat() == "date") { //Test the get with something if ($prop->getValue($usr) != $currentDate->format('Y-m-d H:i:s')) { $this->fail(); } //Test the set with something $d2 = new \DateTime('now', new \DateTimeZone('UTC')); $prop->setValue($usr, $d2->format('Y-m-d H:i:s')); if ($usr->getDate() != $d2) { $this->fail(); } //Test the get with null $usr->setDate(null); if ($prop->getValue($usr) != null) { $this->fail(); } //Test the set with null $usr->setDate($currentDate); $prop->setValue($usr, null); if ($usr->getDate() != null) { $this->fail(); } return; } } $this->fail(); }