示例#1
0
 /**
  * Test for proper handling of the length property
  **/
 public function testArrayLengthEmulation()
 {
     $data = array("numbers" => array(1, 2, 3, 4), "object" => (object) array("prop1" => "val1", "prop2" => "val2"), "object_with_length_property" => (object) array("length" => "15cm"));
     $context = new \Handlebars\Context($data);
     // make sure we are getting the array length when given an array
     $this->assertEquals($context->get("numbers.length"), 4);
     // make sure we are not getting a length when given an object
     $this->assertEmpty($context->get("object.length"));
     // make sure we can still get the length property when given an object
     $this->assertEquals($context->get("object_with_length_property.length"), "15cm");
 }
示例#2
0
 /**
  * @expectedException \InvalidArgumentException
  * @dataProvider getInvalidData
  */
 public function testInvalidAccessContext($invalid)
 {
     $context = new \Handlebars\Context(array());
     $this->assertEmpty($context->get($invalid));
     $context->get($invalid, true);
 }