/** * Test the `addOperand` and `getOperandTable` accessors. */ public function testOperandTableAccessors() { /* @var \PHPUnit_Framework_MockObject_MockObject $operand */ $operand = $this->getMock('com\\mohiva\\pyramid\\Operand'); $operand->expects($this->any())->method('getIdentifiers')->will($this->returnValue(array(1))); /* @var \com\mohiva\pyramid\Operand $operand */ $token = new Token(1, 1, 1); $grammar = new Grammar(); $grammar->addOperand($operand); $this->assertSame($operand, $grammar->getOperandTable()->getOperand($token)); }
/** * Test if the `parse` method throws an exception if the closing parentheses is missing * and the end of the stream is reached. * * @expectedException \com\mohiva\common\exceptions\SyntaxErrorException */ public function testParseThrowsExceptionIfEndOfStreamIsReached() { $tokenStream = new TokenStream(); $tokenStream->push(new Token(Lexer::T_OPEN_PARENTHESIS, '(', 1)); $tokenStream->push(new Token(Lexer::T_NUMBER, 100, 1)); $tokenStream->rewind(); $grammar = new Grammar(); $grammar->addOperand(new NumberOperand()); $operand = new ParenthesesOperand(); $operand->parse($grammar, $tokenStream); }