shuntParentClassCalls() public method

コード例 #1
0
ファイル: generator.php プロジェクト: ivannis/atoum
 public function testGenerate()
 {
     $this->if($generator = new testedClass())->then->exception(function () use($generator) {
         $generator->generate('');
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\runtime')->hasMessage('Class name \'\' is invalid')->exception(function () use($generator) {
         $generator->generate('\\');
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\runtime')->hasMessage('Class name \'\\\' is invalid')->exception(function () use($generator, &$class) {
         $generator->generate($class = '\\' . uniqid() . '\\');
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\runtime')->hasMessage('Class name \'' . $class . '\' is invalid')->if($adapter = new atoum\test\adapter())->and($adapter->class_exists = false)->and($adapter->interface_exists = false)->and($generator->setAdapter($adapter))->and($class = uniqid('unknownClass'))->then->object($generator->generate($class))->isIdenticalTo($generator)->class('\\mock\\' . $class)->hasNoParent()->hasInterface('mageekguy\\atoum\\mock\\aggregator')->if($class = '\\' . uniqid('unknownClass'))->then->object($generator->generate($class))->isIdenticalTo($generator)->class('\\mock' . $class)->hasNoParent()->hasInterface('mageekguy\\atoum\\mock\\aggregator')->if($adapter->class_exists = true)->and($class = uniqid())->then->exception(function () use($generator, $class) {
         $generator->generate($class);
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Class \'\\mock\\' . $class . '\' already exists')->if($class = '\\' . uniqid())->then->exception(function () use($generator, $class) {
         $generator->generate($class);
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Class \'\\mock' . $class . '\' already exists')->if($class = uniqid())->and($adapter->class_exists = function ($arg) use($class) {
         return $arg === '\\' . $class;
     })->and($reflectionClassController = new mock\controller())->and($reflectionClassController->__construct = function () {
     })->and($reflectionClassController->isFinal = true)->and($reflectionClassController->isInterface = false)->and($reflectionClass = new \mock\reflectionClass(uniqid(), $reflectionClassController))->and($generator->setReflectionClassFactory(function () use($reflectionClass) {
         return $reflectionClass;
     }))->then->exception(function () use($generator, $class) {
         $generator->generate($class);
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Class \'\\' . $class . '\' is final, unable to mock it')->if($class = '\\' . uniqid())->and($adapter->class_exists = function ($arg) use($class) {
         return $arg === $class;
     })->then->exception(function () use($generator, $class) {
         $generator->generate($class);
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Class \'' . $class . '\' is final, unable to mock it')->if($reflectionClassController->isFinal = false)->and($generator = new testedClass())->then->object($generator->generate(__CLASS__))->isIdenticalTo($generator)->class('\\mock\\' . __CLASS__)->hasParent(__CLASS__)->hasInterface('mageekguy\\atoum\\mock\\aggregator')->if($generator = new testedClass())->and($generator->shunt('__construct'))->then->boolean($generator->isShunted('__construct'))->isTrue()->object($generator->generate('reflectionMethod'))->isIdenticalTo($generator)->boolean($generator->isShunted('__construct'))->isFalse()->if($generator = new testedClass())->and($generator->shuntParentClassCalls())->then->object($generator->generate('reflectionParameter'))->isIdenticalTo($generator)->boolean($generator->callsToParentClassAreShunted())->isFalse();
 }
コード例 #2
0
ファイル: generator.php プロジェクト: ronan-gloo/atoum
 public function testGetMockedClassCodeForRealClassWithCallsToParentClassShunted()
 {
     $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->isStatic = false)->and($reflectionMethodController->isAbstract = false)->and($reflectionMethodController->returnsReference = false)->and($reflectionMethod = new \mock\reflectionMethod(null, null))->and($otherReflectionMethodController = new mock\controller())->and($otherReflectionMethodController->__construct = function () {
     })->and($otherReflectionMethodController->getName = $otherMethod = uniqid())->and($otherReflectionMethodController->isConstructor = false)->and($otherReflectionMethodController->getParameters = array())->and($otherReflectionMethodController->isPublic = true)->and($otherReflectionMethodController->isProtected = false)->and($otherReflectionMethodController->isFinal = false)->and($otherReflectionMethodController->isStatic = false)->and($otherReflectionMethodController->isAbstract = false)->and($otherReflectionMethodController->returnsReference = false)->and($otherReflectionMethod = 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, $otherReflectionMethod))->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($generator->shuntParentClassCalls())->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" . '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) === 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" . '}' . PHP_EOL . "\t" . '}' . PHP_EOL . "\t" . 'public function ' . $otherMethod . '()' . 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()->' . $otherMethod . ') === true)' . PHP_EOL . "\t\t" . '{' . PHP_EOL . "\t\t\t" . 'return $this->mockController->invoke(\'' . $otherMethod . '\', $arguments);' . PHP_EOL . "\t\t" . '}' . PHP_EOL . "\t\t" . 'else' . PHP_EOL . "\t\t" . '{' . PHP_EOL . "\t\t\t" . '$this->getMockController()->addCall(\'' . $otherMethod . '\', $arguments);' . PHP_EOL . "\t\t" . '}' . PHP_EOL . "\t" . '}' . PHP_EOL . '}' . PHP_EOL . '}');
 }