/** * @expectedException \Mokka\VerificationException */ public function testCallThrowsExceptionIfArgumentDoesNotMatchExpectedValue() { $arguments = new ArgumentCollection(); $arguments->addArgument(new Argument('foo')); $method = new MockedMethod('foo', $arguments, new Any()); $method->call(new ArgumentCollection(array('bar'))); $method->verify(); }
/** * @param ArgumentCollection $actualArgs * @throws VerificationException * @return null */ public function call(ArgumentCollection $actualArgs) { $this->_invokationCounter++; $i = 0; foreach ($this->_expectedArgs->getArguments() as $index => $expectedArgument) { if (!$actualArgs->hasArgumentAtPosition($index)) { throw new VerificationException($this, sprintf('Argument %s should be %s, is missing', $i, $expectedArgument->__mokka_getValue())); } $actualArgument = $actualArgs->getArgumentAtPosition($i); if (!$this->_argumentComparator->isEqual($expectedArgument, $actualArgument)) { throw new VerificationException($this, sprintf('Argument %s should be %s, is %s', $i, $expectedArgument->__mokka_getValue(), $actualArgument->__mokka_getValue())); } $i++; } return null; }
/** * @param int $index * @param mixed $expectedArgument * @param ArgumentCollection $actualArguments * @return bool * @throws NotFoundException */ private function _doArgumentsMatch($index, $expectedArgument, ArgumentCollection $actualArguments) { return $actualArguments->hasArgumentAtPosition($index) && $this->_argumentComparator->isEqual($expectedArgument, $actualArguments->getArgumentAtPosition($index)); }
public function testGetArguments() { $expectedArguments = array(new Argument('foo'), new Argument('bar')); $collection = new ArgumentCollection(array('foo', 'bar')); $this->assertEquals($expectedArguments, $collection->getArguments()); }
/** * @param string $methodName * @param array $args * @return NULL */ private function _call($methodName, array $args) { $arguments = new ArgumentCollection(); foreach ($args as $arg) { if ($arg instanceof AnythingArgument) { $arguments->addArgument($arg); continue; } $arguments->addArgument(new Argument($arg)); } if ($this->_listeningForVerification || $this->_listeningForStub) { $this->_lastMethod = $methodName; $this->_lastArgs = $arguments; if ($this->_listeningForVerification) { $this->__mokka_addMockedMethod(new MockedMethod($methodName, $arguments, $this->_invokationRule)); } return $this; } if ($this->__mokka_getMethods()->hasMethod($methodName, $arguments)) { $this->__mokka_getMethods()->getMethod($methodName, $arguments)->call($arguments); } if ($this->__mokka_getStubs()->hasMethod($methodName, $arguments)) { return $this->__mokka_getStubs()->getMethod($methodName, $arguments)->call($arguments); } return null; }