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 testJsonProperty()
 {
     $repo = new MetaRepository();
     $meta = $repo->fromClass('LRezek\\Arachnid\\Tests\\Entity\\UserDifferentPropertyFormats');
     $usr = new Entity\UserDifferentPropertyFormats();
     $json = "JSON_STRING";
     $usr->setJson($json);
     foreach ($meta->getProperties() as $prop) {
         if ($prop->getFormat() == "json") {
             //Test the get
             if ($prop->getValue($usr) != json_encode($json)) {
                 $this->fail();
             }
             //Test the set
             $prop->setValue($usr, json_encode("JSON_STRING THE SECOND"));
             if ($usr->getJson() != "JSON_STRING THE SECOND") {
                 $this->fail();
             }
             return;
         }
     }
     $this->fail();
 }