getMockedClassCode() public method

public getMockedClassCode ( $class, $mockNamespace = null, $mockClass = null )
Beispiel #1
0
 /** @php 5.4 */
 public function testGetMockedClassCodeForClassWithCallableTypeHint()
 {
     $this->if($generator = new testedClass())->and($reflectionParameterController = new mock\controller())->and($reflectionParameterController->__construct = function () {
     })->and($reflectionParameterController->isArray = false)->and($reflectionParameterController->isCallable = true)->and($reflectionParameterController->getName = 'callback')->and($reflectionParameterController->isPassedByReference = false)->and($reflectionParameterController->isDefaultValueAvailable = false)->and($reflectionParameterController->isOptional = false)->and($reflectionParameter = new \mock\reflectionParameter(null, null))->and($reflectionMethodController = new mock\controller())->and($reflectionMethodController->__construct = function () {
     })->and($reflectionMethodController->getName = '__construct')->and($reflectionMethodController->isConstructor = true)->and($reflectionMethodController->getParameters = array($reflectionParameter))->and($reflectionMethodController->isPublic = true)->and($reflectionMethodController->isProtected = false)->and($reflectionMethodController->isPrivate = false)->and($reflectionMethodController->isFinal = false)->and($reflectionMethodController->isStatic = false)->and($reflectionMethodController->isAbstract = 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($reflectionClassController->getConstructor = $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))->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 . $this->getMockControllerMethods() . "\t" . 'public function __construct(callable $callback, \\mageekguy\\atoum\\mock\\controller $mockController = null)' . PHP_EOL . "\t" . '{' . PHP_EOL . "\t\t" . '$arguments = array_merge(array($callback), 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->getMockController()->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 . "\t" . 'public static function getMockedMethods()' . PHP_EOL . "\t" . '{' . PHP_EOL . "\t\t" . 'return ' . var_export(array('__construct'), true) . ';' . PHP_EOL . "\t" . '}' . PHP_EOL . '}' . PHP_EOL . '}');
 }
Beispiel #2
0
 /** @php >= 7.0 */
 public function testGetMockedClassCodeForMethodWithReservedWord()
 {
     $this->if($generator = new testedClass())->and($reflectionMethodController = new mock\controller())->and($reflectionMethodController->__construct = function () {
     })->and($reflectionMethodController->getName = $methodName = 'list')->and($reflectionMethodController->isConstructor = false)->and($reflectionMethodController->getParameters = array())->and($reflectionMethodController->isPublic = true)->and($reflectionMethodController->isProtected = false)->and($reflectionMethodController->isPrivate = false)->and($reflectionMethodController->isFinal = false)->and($reflectionMethodController->isStatic = false)->and($reflectionMethodController->isAbstract = false)->and($reflectionMethodController->returnsReference = false)->and($reflectionMethodController->hasReturnType = 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($reflectionClassController->getConstructor = null)->and($reflectionClassController->isAbstract = false)->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))->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 . $this->getMockControllerMethods() . "\t" . 'public function __construct(\\mageekguy\\atoum\\mock\\controller $mockController = null)' . PHP_EOL . "\t" . '{' . 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->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL . "\t\t" . '}' . PHP_EOL . "\t" . '}' . PHP_EOL . "\t" . 'public function ' . $methodName . '()' . PHP_EOL . "\t" . '{' . PHP_EOL . "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL . "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL . "\t\t" . '{' . PHP_EOL . "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL . "\t\t\t" . 'return $return;' . PHP_EOL . "\t\t" . '}' . PHP_EOL . "\t\t" . 'else' . PHP_EOL . "\t\t" . '{' . PHP_EOL . "\t\t\t" . '$this->getMockController()->addCall(\'' . $methodName . '\', $arguments);' . PHP_EOL . "\t\t\t" . '$return = call_user_func_array(\'parent::' . $methodName . '\', $arguments);' . PHP_EOL . "\t\t\t" . 'return $return;' . PHP_EOL . "\t\t" . '}' . PHP_EOL . "\t" . '}' . PHP_EOL . "\t" . 'public static function getMockedMethods()' . PHP_EOL . "\t" . '{' . PHP_EOL . "\t\t" . 'return ' . var_export(array('__construct', $methodName), true) . ';' . PHP_EOL . "\t" . '}' . PHP_EOL . '}' . PHP_EOL . '}');
 }
Beispiel #3
0
 public function testGetMockedClassCodeForAbstractClassWithConstructorInInterface()
 {
     $this->if($generator = new testedClass())->and($publicMethodController = new mock\controller())->and($publicMethodController->__construct = function () {
     })->and($publicMethodController->getName = '__construct')->and($publicMethodController->isConstructor = false)->and($publicMethodController->getParameters = array())->and($publicMethodController->isPublic = true)->and($publicMethodController->isProtected = false)->and($publicMethodController->isFinal = false)->and($publicMethodController->isStatic = false)->and($publicMethodController->isAbstract = true)->and($publicMethodController->returnsReference = false)->and($publicMethod = new \mock\reflectionMethod(null, null))->and($classController = new mock\controller())->and($classController->__construct = function () {
     })->and($classController->getName = $className = uniqid())->and($classController->isFinal = false)->and($classController->isInterface = false)->and($classController->isAbstract = true)->and($classController->getMethods = array($publicMethod))->and($class = new \mock\reflectionClass(null))->and($generator->setReflectionClassFactory(function () use($class) {
         return $class;
     }))->and($adapter = new atoum\test\adapter())->and($adapter->class_exists = function ($class) use($className) {
         return $class == '\\' . $className;
     })->and($generator->setAdapter($adapter))->then->string($generator->getMockedClassCode($className))->isEqualTo('namespace mock {' . PHP_EOL . 'final class ' . $className . ' extends \\' . $className . ' 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" . 'public function __construct(\\mageekguy\\atoum\\mock\\controller $mockController = null)' . PHP_EOL . "\t" . '{' . PHP_EOL . "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -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) === false)' . PHP_EOL . "\t\t" . '{' . PHP_EOL . "\t\t\t" . '$this->mockController->__construct = function() {};' . PHP_EOL . "\t\t" . '}' . PHP_EOL . "\t\t" . '$this->mockController->invoke(\'__construct\', $arguments);' . PHP_EOL . "\t" . '}' . PHP_EOL . '}' . PHP_EOL . '}');
 }