overload() public method

public overload ( method $method )
$method mageekguy\atoum\mock\php\method
示例#1
0
 public function testMethodIsMockable()
 {
     $this->if($generator = new testedClass())->and($this->mockGenerator->orphanize('__construct'))->and($method = new \mock\reflectionMethod($this, $methodName = uniqid()))->and($this->calling($method)->getName = $methodName)->and($this->calling($method)->isFinal = false)->and($this->calling($method)->isStatic = false)->and($this->calling($method)->isAbstract = false)->and($this->calling($method)->isPrivate = false)->and($this->calling($method)->isProtected = false)->then->boolean($generator->methodIsMockable($method))->isTrue()->if($this->calling($method)->isFinal = true)->then->boolean($generator->methodIsMockable($method))->isFalse()->if($this->calling($method)->isFinal = false)->and($this->calling($method)->isStatic = true)->then->boolean($generator->methodIsMockable($method))->isFalse()->if($this->calling($method)->isStatic = false)->and($this->calling($method)->isPrivate = true)->then->boolean($generator->methodIsMockable($method))->isFalse()->if($this->calling($method)->isPrivate = false)->and($this->calling($method)->isProtected = true)->then->boolean($generator->methodIsMockable($method))->isFalse()->if($generator->overload(new mock\php\method($methodName)))->then->boolean($generator->methodIsMockable($method))->isTrue();
 }
示例#2
0
 public function testGetMockedClassCodeWithOverloadMethod()
 {
     $this->if($generator = new testedClass())->and($reflectionMethodController = new mock\controller())->and($reflectionMethodController->__construct = function () {
     })->and($reflectionMethodController->getName = '__construct')->and($reflectionMethodController->isConstructor = true)->and($reflectionMethodController->getParameters = array())->and($reflectionMethodController->isPublic = true)->and($reflectionMethodController->isProtected = false)->and($reflectionMethodController->isFinal = false)->and($reflectionMethodController->isAbstract = false)->and($reflectionMethodController->isStatic = false)->and($reflectionMethodController->returnsReference = false)->and($reflectionMethod = new \mock\reflectionMethod(null, null))->and($reflectionClassController = new mock\controller())->and($reflectionClassController->__construct = function () {
     })->and($reflectionClassController->getName = function () use(&$realClass) {
         return $realClass;
     })->and($reflectionClassController->isFinal = false)->and($reflectionClassController->isInterface = false)->and($reflectionClassController->getMethods = array($reflectionMethod))->and($reflectionClass = new \mock\reflectionClass(null))->and($generator->setReflectionClassFactory(function () use($reflectionClass) {
         return $reflectionClass;
     }))->and($adapter = new atoum\test\adapter())->and($adapter->class_exists = function ($class) use(&$realClass) {
         return $class == '\\' . $realClass;
     })->and($generator->setAdapter($adapter))->and($overloadedMethod = new mock\php\method('__construct'))->and($overloadedMethod->addArgument($argument = new mock\php\method\argument(uniqid())))->and($generator->overload($overloadedMethod))->then->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo('namespace mock {' . PHP_EOL . 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \\mageekguy\\atoum\\mock\\aggregator' . PHP_EOL . '{' . PHP_EOL . "\t" . 'private $mockController = null;' . PHP_EOL . "\t" . 'public function getMockController()' . PHP_EOL . "\t" . '{' . PHP_EOL . "\t\t" . 'if ($this->mockController === null)' . PHP_EOL . "\t\t" . '{' . PHP_EOL . "\t\t\t" . '$this->setMockController(new \\mageekguy\\atoum\\mock\\controller());' . PHP_EOL . "\t\t" . '}' . PHP_EOL . "\t\t" . 'return $this->mockController;' . PHP_EOL . "\t" . '}' . PHP_EOL . "\t" . 'public function setMockController(\\mageekguy\\atoum\\mock\\controller $controller)' . PHP_EOL . "\t" . '{' . PHP_EOL . "\t\t" . 'if ($this->mockController !== $controller)' . PHP_EOL . "\t\t" . '{' . PHP_EOL . "\t\t\t" . '$this->mockController = $controller;' . PHP_EOL . "\t\t\t" . '$controller->control($this);' . PHP_EOL . "\t\t" . '}' . PHP_EOL . "\t\t" . 'return $this->mockController;' . PHP_EOL . "\t" . '}' . PHP_EOL . "\t" . 'public function resetMockController()' . PHP_EOL . "\t" . '{' . PHP_EOL . "\t\t" . 'if ($this->mockController !== null)' . PHP_EOL . "\t\t" . '{' . PHP_EOL . "\t\t\t" . '$mockController = $this->mockController;' . PHP_EOL . "\t\t\t" . '$this->mockController = null;' . PHP_EOL . "\t\t\t" . '$mockController->reset();' . PHP_EOL . "\t\t" . '}' . PHP_EOL . "\t\t" . 'return $this;' . PHP_EOL . "\t" . '}' . PHP_EOL . "\t" . '' . $overloadedMethod . PHP_EOL . "\t" . '{' . PHP_EOL . "\t\t" . '$arguments = array_merge(array(' . $argument . '), array_slice(func_get_args(), 1, -1));' . PHP_EOL . "\t\t" . 'if ($mockController === null)' . PHP_EOL . "\t\t" . '{' . PHP_EOL . "\t\t\t" . '$mockController = \\mageekguy\\atoum\\mock\\controller::get();' . PHP_EOL . "\t\t" . '}' . PHP_EOL . "\t\t" . 'if ($mockController !== null)' . PHP_EOL . "\t\t" . '{' . PHP_EOL . "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL . "\t\t" . '}' . PHP_EOL . "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL . "\t\t" . '{' . PHP_EOL . "\t\t\t" . '$this->mockController->invoke(\'__construct\', $arguments);' . PHP_EOL . "\t\t" . '}' . PHP_EOL . "\t\t" . 'else' . PHP_EOL . "\t\t" . '{' . PHP_EOL . "\t\t\t" . '$this->getMockController()->addCall(\'__construct\', $arguments);' . PHP_EOL . "\t\t\t" . 'call_user_func_array(\'parent::__construct\', $arguments);' . PHP_EOL . "\t\t" . '}' . PHP_EOL . "\t" . '}' . PHP_EOL . '}' . PHP_EOL . '}');
 }