예제 #1
0
 /**
  * Create a new object of the given type.
  *
  * This method exists to be overwritten in child classes,
  * so you can do dependency injection or so.
  *
  * @param string  $class        Class name to instantiate
  * @param boolean $useParameter Pass $parameter to the constructor or not
  * @param mixed   $parameter    Constructor parameter
  *
  * @return object Freshly created object
  */
 public function createInstance($class, $useParameter = false, $parameter = null)
 {
     $object = parent::createInstance($class, $useParameter, $parameter);
     //dummy dependency injection
     $object->db = 'database';
     return $object;
 }
예제 #2
0
 /**
  * Test a setter method with a namespaced type hint that
  * is within another namespace than the object itself.
  */
 public function testSetterNamespacedTypeHint()
 {
     $mapper = new JsonMapper();
     $json = '{"namespacedTypeHint":"Foo"}';
     $res = $mapper->map(json_decode($json), new UnitData());
     $this->assertInstanceOf('\\namespacetest\\UnitData', $res);
     $this->assertInstanceOf('\\othernamespace\\Foo', $res->internalData['namespacedTypeHint']);
     $this->assertEquals('Foo', $res->internalData['namespacedTypeHint']->name);
 }
예제 #3
0
 public function testCaseInsensitivePropertyMatching()
 {
     $jm = new JsonMapper();
     $sn = $jm->map((object) array('PINT' => 2), new JsonMapperTest_Simple());
     $this->assertSame(2, $sn->pint);
 }