Example #1
0
 public function setTest(test $test)
 {
     $test->getAssertionManager()->setHandler('invoke', function ($target) use($test) {
         if (is_string($target)) {
             $invoker = new invokers\klass();
         } else {
             $invoker = new invokers\instance();
         }
         return $invoker->setTarget($target);
     });
     $test->setMockGenerator(new mock\generator($test));
     return $this;
 }
Example #2
0
 public function testInvoke()
 {
     $this->given($this->mockGenerator->orphanize('__construct')->orphanize('invoke')->generate('reflectionMethod'), $factory = function ($object) use(&$reflectionClass, &$reflectionMethod, &$method, &$return) {
         $reflectionClass = new \mock\reflectionClass($object);
         $reflectionMethod = new \mock\reflectionMethod();
         $reflectionClass->getMockController()->hasMethod = true;
         $reflectionClass->getMockController()->getMethod = $reflectionMethod;
         $reflectionMethod->getMockController()->isStatic = false;
         $reflectionMethod->getMockController()->isPublic = false;
         $reflectionMethod->getMockController()->invoke = $return = uniqid();
         $reflectionMethod->getMockController()->invokeArgs = $return;
         return $reflectionClass;
     })->if($invoker = new testedClass($factory))->then->exception(function () use($invoker, $method) {
         $invoker->getInvokable($method);
     })->isInstanceOf('mageekguy\\atoum\\visibility\\invoker\\exception')->hasMessage('Invoker\'s target is not set')->and($invoker->setTarget($object = new \stdClass()))->and($method = uniqid())->then->variable($invoker->invoke($method))->isEqualTo($return)->mock($reflectionMethod)->call('invoke')->withArguments($object, array())->once()->variable($invoker->invoke($method, $arguments = array(uniqid())))->isEqualTo($return)->mock($reflectionMethod)->call('invokeArgs')->withArguments($object, $arguments)->once()->variable($invoker->invoke($method, $arguments = array(uniqid(), $otherArgument = uniqid())))->isEqualTo($return)->mock($reflectionMethod)->call('invokeArgs')->withArguments($object, $arguments)->once();
 }