public function testComplexExpression() { $expression = 'requests[0].attributes.get(name, "default")'; $evaluator = eval($this->compiler->compileExpression(new Expression($expression))); $context = array('requests' => array(new Request()), 'name' => 'Adrien'); $expected = array('Adrien', 'default'); $this->assertEquals($expected, $evaluator($context)); }
public function testCompileArrayWithMixedElements() { $evaluator = eval($source = $this->compiler->compileExpression(new Expression('[#someObject.foo, #str, #int, #someArray]'))); $object = new ParameterAccessTest(); $reflection = new \ReflectionMethod($object, 'complexMethod'); $someObject = new \stdClass(); $someObject->foo = 'bar'; $invocation = new MethodInvocation($reflection, $object, array($someObject, 'string', 1, array('anArrayElement', 1 => 'foo', 'bar', 'key' => 'value')), array()); $expected = array('bar', 'string', 1, array('anArrayElement', 1 => 'foo', 'bar', 'key' => 'value')); $this->assertSame($expected, $evaluator(array('object' => $invocation))); }