/** @test */ public function registeredOperatorParser() { $operatorParserMock = $this->getMockBuilder('Superruzafa\\Rules\\Loader\\Xml\\OperatorParser')->setMethods(array('getElementName'))->getMockForAbstractClass(); $operatorParserMock->expects($this->exactly(2))->method('getElementName')->will($this->returnValue('JARL')); OperatorParserFactoryMethod::registerParser($operatorParserMock); $this->assertSame($operatorParserMock, OperatorParserFactoryMethod::create('JARL')); OperatorParserFactoryMethod::unregisterParser($operatorParserMock); }
/** @test */ public function parseElementOperands() { $operand = $this->getMockForAbstractClass('Superruzafa\\Rules\\Expression'); $operatorParser = $this->getMockBuilder('Superruzafa\\Rules\\Loader\\Xml\\OperatorParser')->setMethods(array('getElementName', 'parse'))->getMockForAbstractClass(); $operatorParser->expects($this->once())->method('getElementName')->will($this->returnValue('operator-element-name')); $operatorParser->expects($this->exactly(2))->method('parse')->will($this->returnValue($operand)); OperatorParserFactoryMethod::registerParser($operatorParser); $doc = new \DOMDocument(); $operatorElement = $doc->createElement('operator-element-name'); $xpath = $this->getMockBuilder('DOMXPath')->disableOriginalConstructor()->setMethods(array('query'))->getMock(); $xpath->expects($this->once())->method('query')->will($this->returnValue(array($operatorElement, $operatorElement))); $operator = $this->getMockBuilder('Superruzafa\\Rules\\Expression\\Operator')->setMethods(array('addOperand'))->getMockForAbstractClass(); $operator->expects($this->exactly(2))->method('addOperand')->with($operand); $class = new \ReflectionObject($this->operator); $method = $class->getMethod('parseOperands'); $method->setAccessible(true); $this->assertSame($operator, $method->invoke($this->operator, $operator, $operatorElement, $xpath)); }