예제 #1
0
 /**
  * {@inheritdoc}
  * @return string
  * @throws \InvalidArgumentException
  */
 public function evaluate(array $data)
 {
     if (!isset($data['path'])) {
         throw new \InvalidArgumentException('URL path is missing.');
     }
     $urlPath = $data['path'];
     $urlParams = $this->paramsInterpreter->evaluate($data);
     return $this->urlResolver->getUrl($urlPath, $urlParams);
 }
예제 #2
0
 public function testEvaluate()
 {
     $input = array('path' => 'some/path');
     $expected = 'http://some.domain.com/some/path/';
     $urlParams = array('param');
     $this->_interpreter->expects($this->once())->method('evaluate')->with($input)->will($this->returnValue($urlParams));
     $this->_urlResolver->expects($this->once())->method('getUrl')->with('some/path', $urlParams)->will($this->returnValue($expected));
     $actual = $this->_model->evaluate($input);
     $this->assertSame($expected, $actual);
 }
예제 #3
0
 public function testEvaluate()
 {
     $input = ['value' => 'some text', 'helper' => __CLASS__ . '::help'];
     $evaluatedValue = ['value' => 'some text (evaluated)'];
     $this->_interpreter->expects($this->once())->method('evaluate')->with($input)->will($this->returnValue($evaluatedValue));
     $this->_objectManager->expects($this->once())->method('get')->with(__CLASS__)->will($this->returnValue($this));
     $expected = 'some text (evaluated) (updated)';
     $actual = $this->_model->evaluate($input);
     $this->assertSame($expected, $actual);
 }
예제 #4
0
 /**
  * {@inheritdoc}
  * @throws \InvalidArgumentException
  */
 public function evaluate(array $data)
 {
     if (!isset($data['helper']) || substr_count($data['helper'], '::') != 1) {
         throw new \InvalidArgumentException('Helper method name in format "\\Class\\Name::methodName" is expected.');
     }
     $helperMethod = $data['helper'];
     list($helperClass, $methodName) = explode('::', $helperMethod, 2);
     if (!method_exists($helperClass, $methodName)) {
         throw new \InvalidArgumentException("Helper method '{$helperMethod}' does not exist.");
     }
     $methodParams = $this->paramsInterpreter->evaluate($data);
     $methodParams = array_values($methodParams);
     // Use positional argument binding instead of named binding
     $helperInstance = $this->objectManager->get($helperClass);
     return call_user_func_array(array($helperInstance, $methodName), $methodParams);
 }
예제 #5
0
 /**
  * @dataProvider evaluateWrongParamDataProvider
  */
 public function testEvaluateWrongParam($input, $expectedExceptionMessage)
 {
     $this->setExpectedException('\\InvalidArgumentException', $expectedExceptionMessage);
     $this->_model->evaluate($input);
 }