Beispiel #1
0
 /**
  * @param array  $rule
  * @param int    $actualTimes
  * @param string $method
  * @return null
  */
 protected function validateSingleWith(array $rule, $actualTimes, $method)
 {
     if ($rule['times'] == $actualTimes) {
         return null;
     }
     $args = $this->renderArguments($rule['with']);
     $converter = new NumberToTimesConverter();
     $msg = sprintf("Expected {$method}(%s) to be called %s, but it was called %s.%s", $args, $converter->convert($rule['times']), $converter->convert($actualTimes), $this->didReceive());
     throw new \PHPUnit_Framework_AssertionFailedError($msg);
 }
 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage Expected integer, but got string for argument 1
  */
 public function testNumberMustBeAnInteger()
 {
     $this->converter->convertToMethod('foo');
 }
Beispiel #3
0
 /**
  * Expected arguments when invoking the mock.
  *
  * @throws \Exception
  * @return MockBuilder
  */
 public function with()
 {
     $methodArguments = new MethodArguments();
     $this->currentWith = $methodArguments->getMethodArgumentValues(func_get_args(), $this->getClassName() . "::" . $this->currentRules[0]);
     foreach ($this->currentRules as $rule) {
         if ($this->rules[$rule][md5('null')]['hasSetTimes']) {
             $renderer = new ValueRenderer();
             $converter = new NumberToTimesConverter();
             $args = $renderer->renderAll($this->currentWith);
             $times = $this->rules[$rule][md5('null')]['times'];
             $convertToMethod = $converter->convertToMethod($times);
             throw new Exception(sprintf("%s:\n  ->expects('%s')->with(%s)->%s", "When using with you must specify expectations for each with()", $rule, $args, $convertToMethod));
         }
         $this->rules[$rule][md5('null')]['times'] = -1;
     }
     $this->setupWith(new Action\ReturnValueAction(array(null)), $this->isExpecting ? 1 : -1);
     return $this;
 }