Exemple #1
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();
 }
Exemple #2
0
 public function testHasMethod()
 {
     $this->if($asserter = new sut($generator = new asserter\generator()))->then->exception(function () use($asserter) {
         $asserter->hasMethod(uniqid());
     })->isInstanceOf('logicException')->hasMessage('Class is undefined')->if($class = uniqid())->and($method = uniqid())->and($reflectionClass = new \mock\reflectionClass($class = uniqid()))->and($reflectionClassController = $reflectionClass->getMockController())->and($reflectionClassController->getName = $class)->and($reflectionClassController->hasMethod = false)->and($asserter->setReflectionClassInjector(function ($class) use($reflectionClass) {
         return $reflectionClass;
     })->setWith($class))->then->exception(function () use($asserter, $method) {
         $asserter->hasMethod($method);
     })->isInstanceOf('mageekguy\\atoum\\asserter\\exception')->hasMessage(sprintf($generator->getLocale()->_('Method %s::%s() does not exist'), $class, $method))->if($reflectionClassController->hasMethod = true)->then->object($asserter->hasMethod(uniqid()))->isIdenticalTo($asserter);
 }