/**
  * Parses an expression.
  *
  * @param Expression|string $expression The expression to parse
  * @param array             $names      An array of valid names
  *
  * @return ParsedExpression A ParsedExpression instance
  */
 public function parse($expression, $names)
 {
     if (!$expression instanceof ParsedExpression) {
         $expression = parent::parse($this->prepare($expression), $this->getUppercaseNames($names));
     }
     return $expression;
 }
 public function testCachedParse()
 {
     $cacheMock = $this->getMock('Profideo\\Component\\ExpressionLanguage\\ParserCache\\ParserCacheInterface');
     $savedParsedExpression = null;
     $expressionLanguage = new ExpressionLanguage($cacheMock);
     $cacheMock->expects($this->exactly(2))->method('fetch')->with('1 + 1//')->will($this->returnCallback(function () use(&$savedParsedExpression) {
         return $savedParsedExpression;
     }));
     $cacheMock->expects($this->exactly(1))->method('save')->with('1 + 1//', $this->isInstanceOf('Profideo\\Component\\ExpressionLanguage\\ParsedExpression'))->will($this->returnCallback(function ($key, $expression) use(&$savedParsedExpression) {
         $savedParsedExpression = $expression;
     }));
     $parsedExpression = $expressionLanguage->parse('1 + 1', array());
     $this->assertSame($savedParsedExpression, $parsedExpression);
     $parsedExpression = $expressionLanguage->parse('1 + 1', array());
     $this->assertSame($savedParsedExpression, $parsedExpression);
 }