Example #1
0
 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());
 }
Example #2
0
 function testObjectProperty()
 {
     $repo = new MetaRepository();
     $meta = $repo->fromClass('LRezek\\Arachnid\\Tests\\Entity\\UserDifferentPropertyFormats');
     $usr = new Entity\UserDifferentPropertyFormats();
     $testClass = new ClassParamTestClass(1);
     $usr->setClass($testClass);
     $encoded = serialize($testClass);
     foreach ($meta->getProperties() as $prop) {
         if ($prop->getFormat() == "object") {
             //Test the get
             if ($prop->getValue($usr) != $encoded) {
                 $this->fail();
             }
             //Test the set
             $tc = serialize(new ClassParamTestClass(2));
             $prop->setValue($usr, $tc);
             if ($usr->getClass() != unserialize($tc)) {
                 $this->fail();
             }
             return;
         }
     }
     $this->fail();
 }