How to use resetMockController method of generator class

Best Atoum code snippet using generator.resetMockController

generator.php

Source:generator.php Github

copy

Full Screen

...180 "\t\t\t" . '$controller->control($this);' . PHP_EOL .181 "\t\t" . '}' . PHP_EOL .182 "\t\t" . 'return $this->mockController;' . PHP_EOL .183 "\t" . '}' . PHP_EOL .184 "\t" . 'public function resetMockController()' . PHP_EOL .185 "\t" . '{' . PHP_EOL .186 "\t\t" . 'if ($this->mockController !== null)' . PHP_EOL .187 "\t\t" . '{' . PHP_EOL .188 "\t\t\t" . '$mockController = $this->mockController;' . PHP_EOL .189 "\t\t\t" . '$this->mockController = null;' . PHP_EOL .190 "\t\t\t" . '$mockController->reset();' . PHP_EOL .191 "\t\t" . '}' . PHP_EOL .192 "\t\t" . 'return $this;' . PHP_EOL .193 "\t" . '}' . PHP_EOL .194 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .195 "\t" . '{' . PHP_EOL .196 "\t\t" . 'if ($mockController === null)' . PHP_EOL .197 "\t\t" . '{' . PHP_EOL .198 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .199 "\t\t" . '}' . PHP_EOL .200 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .201 "\t\t" . '{' . PHP_EOL .202 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .203 "\t\t" . '}' . PHP_EOL .204 "\t\t" . '$this->getMockController()->disableMethodChecking();' . PHP_EOL .205 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .206 "\t\t" . '{' . PHP_EOL .207 "\t\t\t" . '$this->mockController->invoke(\'__construct\', array());' . PHP_EOL .208 "\t\t" . '}' . PHP_EOL .209 "\t" . '}' . PHP_EOL .210 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .211 "\t" . '{' . PHP_EOL .212 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .213 "\t\t" . '{' . PHP_EOL .214 "\t\t\t" . 'return $this->mockController->invoke($methodName, $arguments);' . PHP_EOL .215 "\t\t" . '}' . PHP_EOL .216 "\t\t" . 'else' . PHP_EOL .217 "\t\t" . '{' . PHP_EOL .218 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .219 "\t\t" . '}' . PHP_EOL .220 "\t" . '}' . PHP_EOL .221 "\t" . 'public static function getMockedMethods()' . PHP_EOL .222 "\t" . '{' . PHP_EOL .223 "\t\t" . 'return ' . var_export(array('__call'), true) . ';' . PHP_EOL .224 "\t" . '}' . PHP_EOL .225 '}' . PHP_EOL .226 '}'227 )228 ->if($unknownClass = __NAMESPACE__ . '\dummy')229 ->and($generator->generate($unknownClass))230 ->and($mockedUnknownClass = '\mock\\' . $unknownClass)231 ->and($dummy = new $mockedUnknownClass())232 ->then233 ->when(function() use ($dummy) { $dummy->bar(); })234 ->array($dummy->getMockController()->getCalls('bar'))->hasSize(1)235 ->when(function() use ($dummy) { $dummy->bar(); })236 ->array($dummy->getMockController()->getCalls('bar'))->hasSize(2)237 ;238 }239 public function testGetMockedClassCodeForRealClass()240 {241 $this242 ->if($generator = new testedClass())243 ->and($reflectionMethodController = new mock\controller())244 ->and($reflectionMethodController->__construct = function() {})245 ->and($reflectionMethodController->getName = '__construct')246 ->and($reflectionMethodController->isConstructor = true)247 ->and($reflectionMethodController->getParameters = array())248 ->and($reflectionMethodController->isPublic = true)249 ->and($reflectionMethodController->isProtected = false)250 ->and($reflectionMethodController->isFinal = false)251 ->and($reflectionMethodController->isStatic = false)252 ->and($reflectionMethodController->isAbstract = false)253 ->and($reflectionMethodController->returnsReference = false)254 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))255 ->and($reflectionClassController = new mock\controller())256 ->and($reflectionClassController->__construct = function() {})257 ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })258 ->and($reflectionClassController->isFinal = false)259 ->and($reflectionClassController->isInterface = false)260 ->and($reflectionClassController->getMethods = array($reflectionMethod))261 ->and($reflectionClass = new \mock\reflectionClass(null))262 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))263 ->and($adapter = new atoum\test\adapter())264 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })265 ->and($generator->setAdapter($adapter))266 ->then267 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(268 'namespace mock {' . PHP_EOL .269 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .270 '{' . PHP_EOL .271 "\t" . 'private $mockController = null;' . PHP_EOL .272 "\t" . 'public function getMockController()' . PHP_EOL .273 "\t" . '{' . PHP_EOL .274 "\t\t" . 'if ($this->mockController === null)' . PHP_EOL .275 "\t\t" . '{' . PHP_EOL .276 "\t\t\t" . '$this->setMockController(new \mageekguy\atoum\mock\controller());' . PHP_EOL .277 "\t\t" . '}' . PHP_EOL .278 "\t\t" . 'return $this->mockController;' . PHP_EOL .279 "\t" . '}' . PHP_EOL .280 "\t" . 'public function setMockController(\mageekguy\atoum\mock\controller $controller)' . PHP_EOL .281 "\t" . '{' . PHP_EOL .282 "\t\t" . 'if ($this->mockController !== $controller)' . PHP_EOL .283 "\t\t" . '{' . PHP_EOL .284 "\t\t\t" . '$this->mockController = $controller;' . PHP_EOL .285 "\t\t\t" . '$controller->control($this);' . PHP_EOL .286 "\t\t" . '}' . PHP_EOL .287 "\t\t" . 'return $this->mockController;' . PHP_EOL .288 "\t" . '}' . PHP_EOL .289 "\t" . 'public function resetMockController()' . PHP_EOL .290 "\t" . '{' . PHP_EOL .291 "\t\t" . 'if ($this->mockController !== null)' . PHP_EOL .292 "\t\t" . '{' . PHP_EOL .293 "\t\t\t" . '$mockController = $this->mockController;' . PHP_EOL .294 "\t\t\t" . '$this->mockController = null;' . PHP_EOL .295 "\t\t\t" . '$mockController->reset();' . PHP_EOL .296 "\t\t" . '}' . PHP_EOL .297 "\t\t" . 'return $this;' . PHP_EOL .298 "\t" . '}' . PHP_EOL .299 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .300 "\t" . '{' . PHP_EOL .301 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .302 "\t\t" . 'if ($mockController === null)' . PHP_EOL .303 "\t\t" . '{' . PHP_EOL .304 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .305 "\t\t" . '}' . PHP_EOL .306 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .307 "\t\t" . '{' . PHP_EOL .308 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .309 "\t\t" . '}' . PHP_EOL .310 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .311 "\t\t" . '{' . PHP_EOL .312 "\t\t\t" . '$this->mockController->invoke(\'__construct\', $arguments);' . PHP_EOL .313 "\t\t" . '}' . PHP_EOL .314 "\t\t" . 'else' . PHP_EOL .315 "\t\t" . '{' . PHP_EOL .316 "\t\t\t" . '$this->getMockController()->addCall(\'__construct\', $arguments);' . PHP_EOL .317 "\t\t\t" . 'call_user_func_array(\'parent::__construct\', $arguments);' . PHP_EOL .318 "\t\t" . '}' . PHP_EOL .319 "\t" . '}' . PHP_EOL .320 "\t" . 'public static function getMockedMethods()' . PHP_EOL .321 "\t" . '{' . PHP_EOL .322 "\t\t" . 'return ' . var_export(array('__construct'), true) . ';' . PHP_EOL .323 "\t" . '}' . PHP_EOL .324 '}' . PHP_EOL .325 '}'326 )327 ;328 }329 public function testGetMockedClassCodeForRealClassWithDeprecatedConstructor()330 {331 $this332 ->if($generator = new testedClass())333 ->and($reflectionMethodController = new mock\controller())334 ->and($reflectionMethodController->__construct = function() {})335 ->and($reflectionMethodController->getName = $realClass = uniqid())336 ->and($reflectionMethodController->isConstructor = true)337 ->and($reflectionMethodController->getParameters = array())338 ->and($reflectionMethodController->isPublic = true)339 ->and($reflectionMethodController->isProtected = false)340 ->and($reflectionMethodController->isFinal = false)341 ->and($reflectionMethodController->isStatic = false)342 ->and($reflectionMethodController->isAbstract = false)343 ->and($reflectionMethodController->returnsReference = false)344 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))345 ->and($reflectionClassController = new mock\controller())346 ->and($reflectionClassController->__construct = function() {})347 ->and($reflectionClassController->getName = $realClass)348 ->and($reflectionClassController->isFinal = false)349 ->and($reflectionClassController->isInterface = false)350 ->and($reflectionClassController->getMethods = array($reflectionMethod))351 ->and($reflectionClass = new \mock\reflectionClass(null))352 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))353 ->and($adapter = new atoum\test\adapter())354 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })355 ->and($generator->setAdapter($adapter))356 ->then357 ->string($generator->getMockedClassCode($realClass))->isEqualTo(358 'namespace mock {' . PHP_EOL .359 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .360 '{' . PHP_EOL .361 "\t" . 'private $mockController = null;' . PHP_EOL .362 "\t" . 'public function getMockController()' . PHP_EOL .363 "\t" . '{' . PHP_EOL .364 "\t\t" . 'if ($this->mockController === null)' . PHP_EOL .365 "\t\t" . '{' . PHP_EOL .366 "\t\t\t" . '$this->setMockController(new \mageekguy\atoum\mock\controller());' . PHP_EOL .367 "\t\t" . '}' . PHP_EOL .368 "\t\t" . 'return $this->mockController;' . PHP_EOL .369 "\t" . '}' . PHP_EOL .370 "\t" . 'public function setMockController(\mageekguy\atoum\mock\controller $controller)' . PHP_EOL .371 "\t" . '{' . PHP_EOL .372 "\t\t" . 'if ($this->mockController !== $controller)' . PHP_EOL .373 "\t\t" . '{' . PHP_EOL .374 "\t\t\t" . '$this->mockController = $controller;' . PHP_EOL .375 "\t\t\t" . '$controller->control($this);' . PHP_EOL .376 "\t\t" . '}' . PHP_EOL .377 "\t\t" . 'return $this->mockController;' . PHP_EOL .378 "\t" . '}' . PHP_EOL .379 "\t" . 'public function resetMockController()' . PHP_EOL .380 "\t" . '{' . PHP_EOL .381 "\t\t" . 'if ($this->mockController !== null)' . PHP_EOL .382 "\t\t" . '{' . PHP_EOL .383 "\t\t\t" . '$mockController = $this->mockController;' . PHP_EOL .384 "\t\t\t" . '$this->mockController = null;' . PHP_EOL .385 "\t\t\t" . '$mockController->reset();' . PHP_EOL .386 "\t\t" . '}' . PHP_EOL .387 "\t\t" . 'return $this;' . PHP_EOL .388 "\t" . '}' . PHP_EOL .389 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .390 "\t" . '{' . PHP_EOL .391 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .392 "\t\t" . 'if ($mockController === null)' . PHP_EOL .393 "\t\t" . '{' . PHP_EOL .394 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .395 "\t\t" . '}' . PHP_EOL .396 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .397 "\t\t" . '{' . PHP_EOL .398 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .399 "\t\t" . '}' . PHP_EOL .400 "\t\t" . 'if (isset($this->getMockController()->' . $realClass . ') === true)' . PHP_EOL .401 "\t\t" . '{' . PHP_EOL .402 "\t\t\t" . '$this->mockController->invoke(\'' . $realClass . '\', $arguments);' . PHP_EOL .403 "\t\t" . '}' . PHP_EOL .404 "\t\t" . 'else if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .405 "\t\t" . '{' . PHP_EOL .406 "\t\t\t" . '$this->mockController->invoke(\'__construct\', $arguments);' . PHP_EOL .407 "\t\t" . '}' . PHP_EOL .408 "\t\t" . 'else' . PHP_EOL .409 "\t\t" . '{' . PHP_EOL .410 "\t\t\t" . '$this->getMockController()->addCall(\'' . $realClass . '\', $arguments);' . PHP_EOL .411 "\t\t\t" . 'call_user_func_array(\'parent::' . $realClass . '\', $arguments);' . PHP_EOL .412 "\t\t" . '}' . PHP_EOL .413 "\t" . '}' . PHP_EOL .414 "\t" . 'public static function getMockedMethods()' . PHP_EOL .415 "\t" . '{' . PHP_EOL .416 "\t\t" . 'return ' . var_export(array($realClass), true) . ';' . PHP_EOL .417 "\t" . '}' . PHP_EOL .418 '}' . PHP_EOL .419 '}'420 )421 ;422 }423 public function testGetMockedClassCodeForRealClassWithCallsToParentClassShunted()424 {425 $this426 ->if($generator = new testedClass())427 ->and($reflectionMethodController = new mock\controller())428 ->and($reflectionMethodController->__construct = function() {})429 ->and($reflectionMethodController->getName = '__construct')430 ->and($reflectionMethodController->isConstructor = true)431 ->and($reflectionMethodController->getParameters = array())432 ->and($reflectionMethodController->isPublic = true)433 ->and($reflectionMethodController->isProtected = false)434 ->and($reflectionMethodController->isFinal = false)435 ->and($reflectionMethodController->isStatic = false)436 ->and($reflectionMethodController->isAbstract = false)437 ->and($reflectionMethodController->returnsReference = false)438 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))439 ->and($otherReflectionMethodController = new mock\controller())440 ->and($otherReflectionMethodController->__construct = function() {})441 ->and($otherReflectionMethodController->getName = $otherMethod = uniqid())442 ->and($otherReflectionMethodController->isConstructor = false)443 ->and($otherReflectionMethodController->getParameters = array())444 ->and($otherReflectionMethodController->isPublic = true)445 ->and($otherReflectionMethodController->isProtected = false)446 ->and($otherReflectionMethodController->isFinal = false)447 ->and($otherReflectionMethodController->isStatic = false)448 ->and($otherReflectionMethodController->isAbstract = false)449 ->and($otherReflectionMethodController->returnsReference = false)450 ->and($otherReflectionMethod = new \mock\reflectionMethod(null, null))451 ->and($reflectionClassController = new mock\controller())452 ->and($reflectionClassController->__construct = function() {})453 ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })454 ->and($reflectionClassController->isFinal = false)455 ->and($reflectionClassController->isInterface = false)456 ->and($reflectionClassController->getMethods = array($reflectionMethod, $otherReflectionMethod))457 ->and($reflectionClass = new \mock\reflectionClass(null))458 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))459 ->and($adapter = new atoum\test\adapter())460 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })461 ->and($generator->setAdapter($adapter))462 ->and($generator->shuntParentClassCalls())463 ->then464 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(465 'namespace mock {' . PHP_EOL .466 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .467 '{' . PHP_EOL .468 "\t" . 'private $mockController = null;' . PHP_EOL .469 "\t" . 'public function getMockController()' . PHP_EOL .470 "\t" . '{' . PHP_EOL .471 "\t\t" . 'if ($this->mockController === null)' . PHP_EOL .472 "\t\t" . '{' . PHP_EOL .473 "\t\t\t" . '$this->setMockController(new \mageekguy\atoum\mock\controller());' . PHP_EOL .474 "\t\t" . '}' . PHP_EOL .475 "\t\t" . 'return $this->mockController;' . PHP_EOL .476 "\t" . '}' . PHP_EOL .477 "\t" . 'public function setMockController(\mageekguy\atoum\mock\controller $controller)' . PHP_EOL .478 "\t" . '{' . PHP_EOL .479 "\t\t" . 'if ($this->mockController !== $controller)' . PHP_EOL .480 "\t\t" . '{' . PHP_EOL .481 "\t\t\t" . '$this->mockController = $controller;' . PHP_EOL .482 "\t\t\t" . '$controller->control($this);' . PHP_EOL .483 "\t\t" . '}' . PHP_EOL .484 "\t\t" . 'return $this->mockController;' . PHP_EOL .485 "\t" . '}' . PHP_EOL .486 "\t" . 'public function resetMockController()' . PHP_EOL .487 "\t" . '{' . PHP_EOL .488 "\t\t" . 'if ($this->mockController !== null)' . PHP_EOL .489 "\t\t" . '{' . PHP_EOL .490 "\t\t\t" . '$mockController = $this->mockController;' . PHP_EOL .491 "\t\t\t" . '$this->mockController = null;' . PHP_EOL .492 "\t\t\t" . '$mockController->reset();' . PHP_EOL .493 "\t\t" . '}' . PHP_EOL .494 "\t\t" . 'return $this;' . PHP_EOL .495 "\t" . '}' . PHP_EOL .496 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .497 "\t" . '{' . PHP_EOL .498 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .499 "\t\t" . 'if ($mockController === null)' . PHP_EOL .500 "\t\t" . '{' . PHP_EOL .501 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .502 "\t\t" . '}' . PHP_EOL .503 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .504 "\t\t" . '{' . PHP_EOL .505 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .506 "\t\t" . '}' . PHP_EOL .507 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .508 "\t\t" . '{' . PHP_EOL .509 "\t\t\t" . '$this->mockController->invoke(\'__construct\', $arguments);' . PHP_EOL .510 "\t\t" . '}' . PHP_EOL .511 "\t\t" . 'else' . PHP_EOL .512 "\t\t" . '{' . PHP_EOL .513 "\t\t\t" . '$this->getMockController()->addCall(\'__construct\', $arguments);' . PHP_EOL .514 "\t\t" . '}' . PHP_EOL .515 "\t" . '}' . PHP_EOL .516 "\t" . 'public function ' . $otherMethod . '()' . PHP_EOL .517 "\t" . '{' . PHP_EOL .518 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .519 "\t\t" . 'if (isset($this->getMockController()->' . $otherMethod . ') === true)' . PHP_EOL .520 "\t\t" . '{' . PHP_EOL .521 "\t\t\t" . 'return $this->mockController->invoke(\'' . $otherMethod . '\', $arguments);' . PHP_EOL .522 "\t\t" . '}' . PHP_EOL .523 "\t\t" . 'else' . PHP_EOL .524 "\t\t" . '{' . PHP_EOL .525 "\t\t\t" . '$this->getMockController()->addCall(\'' . $otherMethod . '\', $arguments);' . PHP_EOL .526 "\t\t" . '}' . PHP_EOL .527 "\t" . '}' . PHP_EOL .528 "\t" . 'public static function getMockedMethods()' . PHP_EOL .529 "\t" . '{' . PHP_EOL .530 "\t\t" . 'return ' . var_export(array('__construct', $otherMethod), true) . ';' . PHP_EOL .531 "\t" . '}' . PHP_EOL .532 '}' . PHP_EOL .533 '}'534 )535 ;536 }537 public function testGetMockedClassCodeWithOverloadMethod()538 {539 $this540 ->if($generator = new testedClass())541 ->and($reflectionMethodController = new mock\controller())542 ->and($reflectionMethodController->__construct = function() {})543 ->and($reflectionMethodController->getName = '__construct')544 ->and($reflectionMethodController->isConstructor = true)545 ->and($reflectionMethodController->getParameters = array())546 ->and($reflectionMethodController->isPublic = true)547 ->and($reflectionMethodController->isProtected = false)548 ->and($reflectionMethodController->isFinal = false)549 ->and($reflectionMethodController->isAbstract = false)550 ->and($reflectionMethodController->isStatic = false)551 ->and($reflectionMethodController->returnsReference = false)552 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))553 ->and($reflectionClassController = new mock\controller())554 ->and($reflectionClassController->__construct = function() {})555 ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })556 ->and($reflectionClassController->isFinal = false)557 ->and($reflectionClassController->isInterface = false)558 ->and($reflectionClassController->getMethods = array($reflectionMethod))559 ->and($reflectionClass = new \mock\reflectionClass(null))560 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))561 ->and($adapter = new atoum\test\adapter())562 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })563 ->and($generator->setAdapter($adapter))564 ->and($overloadedMethod = new mock\php\method('__construct'))565 ->and($overloadedMethod->addArgument($argument = new mock\php\method\argument(uniqid())))566 ->and($generator->overload($overloadedMethod))567 ->then568 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(569 'namespace mock {' . PHP_EOL .570 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .571 '{' . PHP_EOL .572 "\t" . 'private $mockController = null;' . PHP_EOL .573 "\t" . 'public function getMockController()' . PHP_EOL .574 "\t" . '{' . PHP_EOL .575 "\t\t" . 'if ($this->mockController === null)' . PHP_EOL .576 "\t\t" . '{' . PHP_EOL .577 "\t\t\t" . '$this->setMockController(new \mageekguy\atoum\mock\controller());' . PHP_EOL .578 "\t\t" . '}' . PHP_EOL .579 "\t\t" . 'return $this->mockController;' . PHP_EOL .580 "\t" . '}' . PHP_EOL .581 "\t" . 'public function setMockController(\mageekguy\atoum\mock\controller $controller)' . PHP_EOL .582 "\t" . '{' . PHP_EOL .583 "\t\t" . 'if ($this->mockController !== $controller)' . PHP_EOL .584 "\t\t" . '{' . PHP_EOL .585 "\t\t\t" . '$this->mockController = $controller;' . PHP_EOL .586 "\t\t\t" . '$controller->control($this);' . PHP_EOL .587 "\t\t" . '}' . PHP_EOL .588 "\t\t" . 'return $this->mockController;' . PHP_EOL .589 "\t" . '}' . PHP_EOL .590 "\t" . 'public function resetMockController()' . PHP_EOL .591 "\t" . '{' . PHP_EOL .592 "\t\t" . 'if ($this->mockController !== null)' . PHP_EOL .593 "\t\t" . '{' . PHP_EOL .594 "\t\t\t" . '$mockController = $this->mockController;' . PHP_EOL .595 "\t\t\t" . '$this->mockController = null;' . PHP_EOL .596 "\t\t\t" . '$mockController->reset();' . PHP_EOL .597 "\t\t" . '}' . PHP_EOL .598 "\t\t" . 'return $this;' . PHP_EOL .599 "\t" . '}' . PHP_EOL .600 "\t" . '' . $overloadedMethod . PHP_EOL .601 "\t" . '{' . PHP_EOL .602 "\t\t" . '$arguments = array_merge(array(' . $argument . '), array_slice(func_get_args(), 1, -1));' . PHP_EOL .603 "\t\t" . 'if ($mockController === null)' . PHP_EOL .604 "\t\t" . '{' . PHP_EOL .605 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .606 "\t\t" . '}' . PHP_EOL .607 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .608 "\t\t" . '{' . PHP_EOL .609 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .610 "\t\t" . '}' . PHP_EOL .611 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .612 "\t\t" . '{' . PHP_EOL .613 "\t\t\t" . '$this->mockController->invoke(\'__construct\', $arguments);' . PHP_EOL .614 "\t\t" . '}' . PHP_EOL .615 "\t\t" . 'else' . PHP_EOL .616 "\t\t" . '{' . PHP_EOL .617 "\t\t\t" . '$this->getMockController()->addCall(\'__construct\', $arguments);' . PHP_EOL .618 "\t\t\t" . 'call_user_func_array(\'parent::__construct\', $arguments);' . PHP_EOL .619 "\t\t" . '}' . PHP_EOL .620 "\t" . '}' . PHP_EOL .621 "\t" . 'public static function getMockedMethods()' . PHP_EOL .622 "\t" . '{' . PHP_EOL .623 "\t\t" . 'return ' . var_export(array('__construct'), true) . ';' . PHP_EOL .624 "\t" . '}' . PHP_EOL .625 '}' . PHP_EOL .626 '}'627 )628 ;629 }630 public function testGetMockedClassCodeWithAbstractMethod()631 {632 $this633 ->if($generator = new testedClass())634 ->and($realClass = uniqid())635 ->and($reflectionMethodController = new mock\controller())636 ->and($reflectionMethodController->__construct = function() {})637 ->and($reflectionMethodController->getName = function() { return '__construct'; })638 ->and($reflectionMethodController->isConstructor = true)639 ->and($reflectionMethodController->getParameters = array())640 ->and($reflectionMethodController->isPublic = true)641 ->and($reflectionMethodController->isProtected = false)642 ->and($reflectionMethodController->isFinal = false)643 ->and($reflectionMethodController->isStatic = false)644 ->and($reflectionMethodController->isAbstract = true)645 ->and($reflectionMethodController->returnsReference = false)646 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))647 ->and($reflectionClassController = new mock\controller())648 ->and($reflectionClassController->__construct = function() {})649 ->and($reflectionClassController->getName = function() use ($realClass) { return $realClass; })650 ->and($reflectionClassController->isFinal = false)651 ->and($reflectionClassController->isInterface = false)652 ->and($reflectionClassController->getMethods = array($reflectionMethod))653 ->and($reflectionClass = new \mock\reflectionClass(null))654 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))655 ->and($adapter = new atoum\test\adapter())656 ->and($adapter->class_exists = function($class) use ($realClass) { return ($class == '\\' . $realClass); })657 ->and($generator->setAdapter($adapter))658 ->then659 ->string($generator->getMockedClassCode($realClass))->isEqualTo(660 'namespace mock {' . PHP_EOL .661 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .662 '{' . PHP_EOL .663 "\t" . 'private $mockController = null;' . PHP_EOL .664 "\t" . 'public function getMockController()' . PHP_EOL .665 "\t" . '{' . PHP_EOL .666 "\t\t" . 'if ($this->mockController === null)' . PHP_EOL .667 "\t\t" . '{' . PHP_EOL .668 "\t\t\t" . '$this->setMockController(new \mageekguy\atoum\mock\controller());' . PHP_EOL .669 "\t\t" . '}' . PHP_EOL .670 "\t\t" . 'return $this->mockController;' . PHP_EOL .671 "\t" . '}' . PHP_EOL .672 "\t" . 'public function setMockController(\mageekguy\atoum\mock\controller $controller)' . PHP_EOL .673 "\t" . '{' . PHP_EOL .674 "\t\t" . 'if ($this->mockController !== $controller)' . PHP_EOL .675 "\t\t" . '{' . PHP_EOL .676 "\t\t\t" . '$this->mockController = $controller;' . PHP_EOL .677 "\t\t\t" . '$controller->control($this);' . PHP_EOL .678 "\t\t" . '}' . PHP_EOL .679 "\t\t" . 'return $this->mockController;' . PHP_EOL .680 "\t" . '}' . PHP_EOL .681 "\t" . 'public function resetMockController()' . PHP_EOL .682 "\t" . '{' . PHP_EOL .683 "\t\t" . 'if ($this->mockController !== null)' . PHP_EOL .684 "\t\t" . '{' . PHP_EOL .685 "\t\t\t" . '$mockController = $this->mockController;' . PHP_EOL .686 "\t\t\t" . '$this->mockController = null;' . PHP_EOL .687 "\t\t\t" . '$mockController->reset();' . PHP_EOL .688 "\t\t" . '}' . PHP_EOL .689 "\t\t" . 'return $this;' . PHP_EOL .690 "\t" . '}' . PHP_EOL .691 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .692 "\t" . '{' . PHP_EOL .693 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .694 "\t\t" . 'if ($mockController === null)' . PHP_EOL .695 "\t\t" . '{' . PHP_EOL .696 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .697 "\t\t" . '}' . PHP_EOL .698 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .699 "\t\t" . '{' . PHP_EOL .700 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .701 "\t\t" . '}' . PHP_EOL .702 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .703 "\t\t" . '{' . PHP_EOL .704 "\t\t\t" . '$this->mockController->__construct = function() {};' . PHP_EOL .705 "\t\t" . '}' . PHP_EOL .706 "\t\t" . '$this->mockController->invoke(\'__construct\', $arguments);' . PHP_EOL .707 "\t" . '}' . PHP_EOL .708 "\t" . 'public static function getMockedMethods()' . PHP_EOL .709 "\t" . '{' . PHP_EOL .710 "\t\t" . 'return ' . var_export(array('__construct'), true) . ';' . PHP_EOL .711 "\t" . '}' . PHP_EOL .712 '}' . PHP_EOL .713 '}'714 )715 ;716 }717 public function testGetMockedClassCodeWithShuntedMethod()718 {719 $this720 ->if($generator = new testedClass())721 ->and($realClass = uniqid())722 ->and($reflectionMethodController = new mock\controller())723 ->and($reflectionMethodController->__construct = function() {})724 ->and($reflectionMethodController->getName = function() { return '__construct'; })725 ->and($reflectionMethodController->isConstructor = true)726 ->and($reflectionMethodController->isAbstract = false)727 ->and($reflectionMethodController->getParameters = array())728 ->and($reflectionMethodController->isPublic = true)729 ->and($reflectionMethodController->isProtected = false)730 ->and($reflectionMethodController->isFinal = false)731 ->and($reflectionMethodController->isStatic = false)732 ->and($reflectionMethodController->returnsReference = false)733 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))734 ->and($reflectionClassController = new mock\controller())735 ->and($reflectionClassController->__construct = function() {})736 ->and($reflectionClassController->getName = function() use ($realClass) { return $realClass; })737 ->and($reflectionClassController->isFinal = false)738 ->and($reflectionClassController->isInterface = false)739 ->and($reflectionClassController->getMethods = array($reflectionMethod))740 ->and($reflectionClass = new \mock\reflectionClass(null))741 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))742 ->and($adapter = new atoum\test\adapter())743 ->and($adapter->class_exists = function($class) use ($realClass) { return ($class == '\\' . $realClass); })744 ->and($generator->setAdapter($adapter))745 ->and($generator->shunt('__construct'))746 ->then747 ->string($generator->getMockedClassCode($realClass))->isEqualTo(748 'namespace mock {' . PHP_EOL .749 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .750 '{' . PHP_EOL .751 "\t" . 'private $mockController = null;' . PHP_EOL .752 "\t" . 'public function getMockController()' . PHP_EOL .753 "\t" . '{' . PHP_EOL .754 "\t\t" . 'if ($this->mockController === null)' . PHP_EOL .755 "\t\t" . '{' . PHP_EOL .756 "\t\t\t" . '$this->setMockController(new \mageekguy\atoum\mock\controller());' . PHP_EOL .757 "\t\t" . '}' . PHP_EOL .758 "\t\t" . 'return $this->mockController;' . PHP_EOL .759 "\t" . '}' . PHP_EOL .760 "\t" . 'public function setMockController(\mageekguy\atoum\mock\controller $controller)' . PHP_EOL .761 "\t" . '{' . PHP_EOL .762 "\t\t" . 'if ($this->mockController !== $controller)' . PHP_EOL .763 "\t\t" . '{' . PHP_EOL .764 "\t\t\t" . '$this->mockController = $controller;' . PHP_EOL .765 "\t\t\t" . '$controller->control($this);' . PHP_EOL .766 "\t\t" . '}' . PHP_EOL .767 "\t\t" . 'return $this->mockController;' . PHP_EOL .768 "\t" . '}' . PHP_EOL .769 "\t" . 'public function resetMockController()' . PHP_EOL .770 "\t" . '{' . PHP_EOL .771 "\t\t" . 'if ($this->mockController !== null)' . PHP_EOL .772 "\t\t" . '{' . PHP_EOL .773 "\t\t\t" . '$mockController = $this->mockController;' . PHP_EOL .774 "\t\t\t" . '$this->mockController = null;' . PHP_EOL .775 "\t\t\t" . '$mockController->reset();' . PHP_EOL .776 "\t\t" . '}' . PHP_EOL .777 "\t\t" . 'return $this;' . PHP_EOL .778 "\t" . '}' . PHP_EOL .779 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .780 "\t" . '{' . PHP_EOL .781 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .782 "\t\t" . 'if ($mockController === null)' . PHP_EOL .783 "\t\t" . '{' . PHP_EOL .784 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .785 "\t\t" . '}' . PHP_EOL .786 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .787 "\t\t" . '{' . PHP_EOL .788 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .789 "\t\t" . '}' . PHP_EOL .790 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .791 "\t\t" . '{' . PHP_EOL .792 "\t\t\t" . '$this->mockController->__construct = function() {};' . PHP_EOL .793 "\t\t" . '}' . PHP_EOL .794 "\t\t" . '$this->mockController->invoke(\'__construct\', $arguments);' . PHP_EOL .795 "\t" . '}' . PHP_EOL .796 "\t" . 'public static function getMockedMethods()' . PHP_EOL .797 "\t" . '{' . PHP_EOL .798 "\t\t" . 'return ' . var_export(array('__construct'), true) . ';' . PHP_EOL .799 "\t" . '}' . PHP_EOL .800 '}' . PHP_EOL .801 '}'802 )803 ;804 }805 public function testGetMockedClassCodeWithShuntedDeprecatedConstructor()806 {807 $this808 ->if($generator = new testedClass())809 ->and($realClass = uniqid())810 ->and($reflectionMethodController = new mock\controller())811 ->and($reflectionMethodController->__construct = function() {})812 ->and($reflectionMethodController->getName = $realClass = uniqid())813 ->and($reflectionMethodController->isConstructor = true)814 ->and($reflectionMethodController->isAbstract = false)815 ->and($reflectionMethodController->getParameters = array())816 ->and($reflectionMethodController->isPublic = true)817 ->and($reflectionMethodController->isProtected = false)818 ->and($reflectionMethodController->isFinal = false)819 ->and($reflectionMethodController->isStatic = false)820 ->and($reflectionMethodController->returnsReference = false)821 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))822 ->and($reflectionClassController = new mock\controller())823 ->and($reflectionClassController->__construct = function() {})824 ->and($reflectionClassController->getName = $realClass)825 ->and($reflectionClassController->isFinal = false)826 ->and($reflectionClassController->isInterface = false)827 ->and($reflectionClassController->getMethods = array($reflectionMethod))828 ->and($reflectionClass = new \mock\reflectionClass(null))829 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))830 ->and($adapter = new atoum\test\adapter())831 ->and($adapter->class_exists = function($class) use ($realClass) { return ($class == '\\' . $realClass); })832 ->and($generator->setAdapter($adapter))833 ->and($generator->shunt($realClass))834 ->then835 ->string($generator->getMockedClassCode($realClass))->isEqualTo(836 'namespace mock {' . PHP_EOL .837 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .838 '{' . PHP_EOL .839 "\t" . 'private $mockController = null;' . PHP_EOL .840 "\t" . 'public function getMockController()' . PHP_EOL .841 "\t" . '{' . PHP_EOL .842 "\t\t" . 'if ($this->mockController === null)' . PHP_EOL .843 "\t\t" . '{' . PHP_EOL .844 "\t\t\t" . '$this->setMockController(new \mageekguy\atoum\mock\controller());' . PHP_EOL .845 "\t\t" . '}' . PHP_EOL .846 "\t\t" . 'return $this->mockController;' . PHP_EOL .847 "\t" . '}' . PHP_EOL .848 "\t" . 'public function setMockController(\mageekguy\atoum\mock\controller $controller)' . PHP_EOL .849 "\t" . '{' . PHP_EOL .850 "\t\t" . 'if ($this->mockController !== $controller)' . PHP_EOL .851 "\t\t" . '{' . PHP_EOL .852 "\t\t\t" . '$this->mockController = $controller;' . PHP_EOL .853 "\t\t\t" . '$controller->control($this);' . PHP_EOL .854 "\t\t" . '}' . PHP_EOL .855 "\t\t" . 'return $this->mockController;' . PHP_EOL .856 "\t" . '}' . PHP_EOL .857 "\t" . 'public function resetMockController()' . PHP_EOL .858 "\t" . '{' . PHP_EOL .859 "\t\t" . 'if ($this->mockController !== null)' . PHP_EOL .860 "\t\t" . '{' . PHP_EOL .861 "\t\t\t" . '$mockController = $this->mockController;' . PHP_EOL .862 "\t\t\t" . '$this->mockController = null;' . PHP_EOL .863 "\t\t\t" . '$mockController->reset();' . PHP_EOL .864 "\t\t" . '}' . PHP_EOL .865 "\t\t" . 'return $this;' . PHP_EOL .866 "\t" . '}' . PHP_EOL .867 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .868 "\t" . '{' . PHP_EOL .869 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .870 "\t\t" . 'if ($mockController === null)' . PHP_EOL .871 "\t\t" . '{' . PHP_EOL .872 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .873 "\t\t" . '}' . PHP_EOL .874 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .875 "\t\t" . '{' . PHP_EOL .876 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .877 "\t\t" . '}' . PHP_EOL .878 "\t\t" . 'if (isset($this->getMockController()->' . $realClass . ') === false)' . PHP_EOL .879 "\t\t" . '{' . PHP_EOL .880 "\t\t\t" . '$this->mockController->' . $realClass . ' = function() {};' . PHP_EOL .881 "\t\t" . '}' . PHP_EOL .882 "\t\t" . '$this->mockController->invoke(\'' . $realClass . '\', $arguments);' . PHP_EOL .883 "\t" . '}' . PHP_EOL .884 "\t" . 'public static function getMockedMethods()' . PHP_EOL .885 "\t" . '{' . PHP_EOL .886 "\t\t" . 'return ' . var_export(array($realClass), true) . ';' . PHP_EOL .887 "\t" . '}' . PHP_EOL .888 '}' . PHP_EOL .889 '}'890 )891 ;892 }893 public function testGetMockedClassCodeForInterface()894 {895 $this896 ->if($generator = new testedClass())897 ->and($reflectionMethodController = new mock\controller())898 ->and($reflectionMethodController->__construct = function() {})899 ->and($reflectionMethodController->getName = function() { return '__construct'; })900 ->and($reflectionMethodController->getParameters = array())901 ->and($reflectionMethodController->isFinal = false)902 ->and($reflectionMethodController->isStatic = false)903 ->and($reflectionMethodController->returnsReference = false)904 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))905 ->and($reflectionClassController = new mock\controller())906 ->and($reflectionClassController->__construct = function() {})907 ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })908 ->and($reflectionClassController->isFinal = false)909 ->and($reflectionClassController->isInterface = true)910 ->and($reflectionClassController->getMethods = array($reflectionMethod))911 ->and($reflectionClass = new \mock\reflectionClass(null))912 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))913 ->and($adapter = new atoum\test\adapter())914 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })915 ->and($generator->setAdapter($adapter))916 ->then917 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(918 'namespace mock {' . PHP_EOL .919 'final class ' . $realClass . ' implements \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .920 '{' . PHP_EOL .921 "\t" . 'private $mockController = null;' . PHP_EOL .922 "\t" . 'public function getMockController()' . PHP_EOL .923 "\t" . '{' . PHP_EOL .924 "\t\t" . 'if ($this->mockController === null)' . PHP_EOL .925 "\t\t" . '{' . PHP_EOL .926 "\t\t\t" . '$this->setMockController(new \mageekguy\atoum\mock\controller());' . PHP_EOL .927 "\t\t" . '}' . PHP_EOL .928 "\t\t" . 'return $this->mockController;' . PHP_EOL .929 "\t" . '}' . PHP_EOL .930 "\t" . 'public function setMockController(\mageekguy\atoum\mock\controller $controller)' . PHP_EOL .931 "\t" . '{' . PHP_EOL .932 "\t\t" . 'if ($this->mockController !== $controller)' . PHP_EOL .933 "\t\t" . '{' . PHP_EOL .934 "\t\t\t" . '$this->mockController = $controller;' . PHP_EOL .935 "\t\t\t" . '$controller->control($this);' . PHP_EOL .936 "\t\t" . '}' . PHP_EOL .937 "\t\t" . 'return $this->mockController;' . PHP_EOL .938 "\t" . '}' . PHP_EOL .939 "\t" . 'public function resetMockController()' . PHP_EOL .940 "\t" . '{' . PHP_EOL .941 "\t\t" . 'if ($this->mockController !== null)' . PHP_EOL .942 "\t\t" . '{' . PHP_EOL .943 "\t\t\t" . '$mockController = $this->mockController;' . PHP_EOL .944 "\t\t\t" . '$this->mockController = null;' . PHP_EOL .945 "\t\t\t" . '$mockController->reset();' . PHP_EOL .946 "\t\t" . '}' . PHP_EOL .947 "\t\t" . 'return $this;' . PHP_EOL .948 "\t" . '}' . PHP_EOL .949 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .950 "\t" . '{' . PHP_EOL .951 "\t\t" . 'if ($mockController === null)' . PHP_EOL .952 "\t\t" . '{' . PHP_EOL .953 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .954 "\t\t" . '}' . PHP_EOL .955 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .956 "\t\t" . '{' . PHP_EOL .957 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .958 "\t\t" . '}' . PHP_EOL .959 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .960 "\t\t" . '{' . PHP_EOL .961 "\t\t\t" . '$this->mockController->__construct = function() {};' . PHP_EOL .962 "\t\t" . '}' . PHP_EOL .963 "\t\t" . '$this->mockController->invoke(\'__construct\', func_get_args());' . PHP_EOL .964 "\t" . '}' . PHP_EOL .965 "\t" . 'public static function getMockedMethods()' . PHP_EOL .966 "\t" . '{' . PHP_EOL .967 "\t\t" . 'return ' . var_export(array('__construct'), true) . ';' . PHP_EOL .968 "\t" . '}' . PHP_EOL .969 '}' . PHP_EOL .970 '}'971 )972 ;973 }974 public function testGetMockedClassCodeForRealClassWithoutConstructor()975 {976 $this977 ->if($generator = new testedClass())978 ->and($reflectionMethodController = new mock\controller())979 ->and($reflectionMethodController->__construct = function() {})980 ->and($reflectionMethodController->getName = $methodName = uniqid())981 ->and($reflectionMethodController->isConstructor = false)982 ->and($reflectionMethodController->getParameters = array())983 ->and($reflectionMethodController->isPublic = true)984 ->and($reflectionMethodController->isProtected = false)985 ->and($reflectionMethodController->isFinal = false)986 ->and($reflectionMethodController->isAbstract = false)987 ->and($reflectionMethodController->isStatic = false)988 ->and($reflectionMethodController->returnsReference = false)989 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))990 ->and($reflectionClassController = new mock\controller())991 ->and($reflectionClassController->__construct = function() {})992 ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })993 ->and($reflectionClassController->isFinal = false)994 ->and($reflectionClassController->isInterface = false)995 ->and($reflectionClassController->getMethods = array($reflectionMethod))996 ->and($reflectionClass = new \mock\reflectionClass(null))997 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))998 ->and($adapter = new atoum\test\adapter())999 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })1000 ->and($generator->setAdapter($adapter))1001 ->then1002 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(1003 'namespace mock {' . PHP_EOL .1004 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .1005 '{' . PHP_EOL .1006 "\t" . 'private $mockController = null;' . PHP_EOL .1007 "\t" . 'public function getMockController()' . PHP_EOL .1008 "\t" . '{' . PHP_EOL .1009 "\t\t" . 'if ($this->mockController === null)' . PHP_EOL .1010 "\t\t" . '{' . PHP_EOL .1011 "\t\t\t" . '$this->setMockController(new \mageekguy\atoum\mock\controller());' . PHP_EOL .1012 "\t\t" . '}' . PHP_EOL .1013 "\t\t" . 'return $this->mockController;' . PHP_EOL .1014 "\t" . '}' . PHP_EOL .1015 "\t" . 'public function setMockController(\mageekguy\atoum\mock\controller $controller)' . PHP_EOL .1016 "\t" . '{' . PHP_EOL .1017 "\t\t" . 'if ($this->mockController !== $controller)' . PHP_EOL .1018 "\t\t" . '{' . PHP_EOL .1019 "\t\t\t" . '$this->mockController = $controller;' . PHP_EOL .1020 "\t\t\t" . '$controller->control($this);' . PHP_EOL .1021 "\t\t" . '}' . PHP_EOL .1022 "\t\t" . 'return $this->mockController;' . PHP_EOL .1023 "\t" . '}' . PHP_EOL .1024 "\t" . 'public function resetMockController()' . PHP_EOL .1025 "\t" . '{' . PHP_EOL .1026 "\t\t" . 'if ($this->mockController !== null)' . PHP_EOL .1027 "\t\t" . '{' . PHP_EOL .1028 "\t\t\t" . '$mockController = $this->mockController;' . PHP_EOL .1029 "\t\t\t" . '$this->mockController = null;' . PHP_EOL .1030 "\t\t\t" . '$mockController->reset();' . PHP_EOL .1031 "\t\t" . '}' . PHP_EOL .1032 "\t\t" . 'return $this;' . PHP_EOL .1033 "\t" . '}' . PHP_EOL .1034 "\t" . 'public function ' . $methodName . '()' . PHP_EOL .1035 "\t" . '{' . PHP_EOL .1036 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .1037 "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL .1038 "\t\t" . '{' . PHP_EOL .1039 "\t\t\t" . 'return $this->mockController->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL .1040 "\t\t" . '}' . PHP_EOL .1041 "\t\t" . 'else' . PHP_EOL .1042 "\t\t" . '{' . PHP_EOL .1043 "\t\t\t" . '$this->getMockController()->addCall(\'' . $methodName . '\', $arguments);' . PHP_EOL .1044 "\t\t\t" . 'return call_user_func_array(\'parent::' . $methodName . '\', $arguments);' . PHP_EOL .1045 "\t\t" . '}' . PHP_EOL .1046 "\t" . '}' . PHP_EOL .1047 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1048 "\t" . '{' . PHP_EOL .1049 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1050 "\t\t" . '{' . PHP_EOL .1051 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1052 "\t\t" . '}' . PHP_EOL .1053 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1054 "\t\t" . '{' . PHP_EOL .1055 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1056 "\t\t" . '}' . PHP_EOL .1057 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .1058 "\t\t" . '{' . PHP_EOL .1059 "\t\t\t" . '$this->mockController->invoke(\'__construct\', func_get_args());' . PHP_EOL .1060 "\t\t" . '}' . PHP_EOL .1061 "\t" . '}' . PHP_EOL .1062 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1063 "\t" . '{' . PHP_EOL .1064 "\t\t" . 'return ' . var_export(array($methodName, '__construct'), true) . ';' . PHP_EOL .1065 "\t" . '}' . PHP_EOL .1066 '}' . PHP_EOL .1067 '}'1068 )1069 ;1070 }1071 public function testGetMockedClassCodeWithProtectedAbstractMethod()1072 {1073 $this1074 ->if($generator = new testedClass())1075 ->and($publicMethodController = new mock\controller())1076 ->and($publicMethodController->__construct = function() {})1077 ->and($publicMethodController->getName = $publicMethodName = uniqid())1078 ->and($publicMethodController->isConstructor = false)1079 ->and($publicMethodController->getParameters = array())1080 ->and($publicMethodController->isPublic = true)1081 ->and($publicMethodController->isProtected = false)1082 ->and($publicMethodController->isFinal = false)1083 ->and($publicMethodController->isStatic = false)1084 ->and($publicMethodController->isAbstract = true)1085 ->and($publicMethodController->returnsReference = false)1086 ->and($publicMethod = new \mock\reflectionMethod(null, null))1087 ->and($protectedMethodController = new mock\controller())1088 ->and($protectedMethodController->__construct = function() {})1089 ->and($protectedMethodController->getName = $protectedMethodName = uniqid())1090 ->and($protectedMethodController->isConstructor = false)1091 ->and($protectedMethodController->getParameters = array())1092 ->and($protectedMethodController->isPublic = false)1093 ->and($protectedMethodController->isProtected = true)1094 ->and($protectedMethodController->isFinal = false)1095 ->and($protectedMethodController->isStatic = false)1096 ->and($protectedMethodController->isAbstract = true)1097 ->and($protectedMethodController->returnsReference = false)1098 ->and($protectedMethod = new \mock\reflectionMethod(null, null))1099 ->and($classController = new mock\controller())1100 ->and($classController->__construct = function() {})1101 ->and($classController->getName = $className = uniqid())1102 ->and($classController->isFinal = false)1103 ->and($classController->isInterface = false)1104 ->and($classController->getMethods = array($publicMethod, $protectedMethod))1105 ->and($class = new \mock\reflectionClass(null))1106 ->and($generator->setReflectionClassFactory(function() use ($class) { return $class; }))1107 ->and($adapter = new atoum\test\adapter())1108 ->and($adapter->class_exists = function($class) use ($className) { return ($class == '\\' . $className); })1109 ->and($generator->setAdapter($adapter))1110 ->then1111 ->string($generator->getMockedClassCode($className))->isEqualTo(1112 'namespace mock {' . PHP_EOL .1113 'final class ' . $className . ' extends \\' . $className . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .1114 '{' . PHP_EOL .1115 "\t" . 'private $mockController = null;' . PHP_EOL .1116 "\t" . 'public function getMockController()' . PHP_EOL .1117 "\t" . '{' . PHP_EOL .1118 "\t\t" . 'if ($this->mockController === null)' . PHP_EOL .1119 "\t\t" . '{' . PHP_EOL .1120 "\t\t\t" . '$this->setMockController(new \mageekguy\atoum\mock\controller());' . PHP_EOL .1121 "\t\t" . '}' . PHP_EOL .1122 "\t\t" . 'return $this->mockController;' . PHP_EOL .1123 "\t" . '}' . PHP_EOL .1124 "\t" . 'public function setMockController(\mageekguy\atoum\mock\controller $controller)' . PHP_EOL .1125 "\t" . '{' . PHP_EOL .1126 "\t\t" . 'if ($this->mockController !== $controller)' . PHP_EOL .1127 "\t\t" . '{' . PHP_EOL .1128 "\t\t\t" . '$this->mockController = $controller;' . PHP_EOL .1129 "\t\t\t" . '$controller->control($this);' . PHP_EOL .1130 "\t\t" . '}' . PHP_EOL .1131 "\t\t" . 'return $this->mockController;' . PHP_EOL .1132 "\t" . '}' . PHP_EOL .1133 "\t" . 'public function resetMockController()' . PHP_EOL .1134 "\t" . '{' . PHP_EOL .1135 "\t\t" . 'if ($this->mockController !== null)' . PHP_EOL .1136 "\t\t" . '{' . PHP_EOL .1137 "\t\t\t" . '$mockController = $this->mockController;' . PHP_EOL .1138 "\t\t\t" . '$this->mockController = null;' . PHP_EOL .1139 "\t\t\t" . '$mockController->reset();' . PHP_EOL .1140 "\t\t" . '}' . PHP_EOL .1141 "\t\t" . 'return $this;' . PHP_EOL .1142 "\t" . '}' . PHP_EOL .1143 "\t" . 'public function ' . $publicMethodName . '()' . PHP_EOL .1144 "\t" . '{' . PHP_EOL .1145 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .1146 "\t\t" . 'if (isset($this->getMockController()->' . $publicMethodName . ') === false)' . PHP_EOL .1147 "\t\t" . '{' . PHP_EOL .1148 "\t\t\t" . '$this->mockController->' . $publicMethodName . ' = function() {};' . PHP_EOL .1149 "\t\t" . '}' . PHP_EOL .1150 "\t\t" . 'return $this->mockController->invoke(\'' . $publicMethodName . '\', $arguments);' . PHP_EOL .1151 "\t" . '}' . PHP_EOL .1152 "\t" . 'protected function ' . $protectedMethodName . '()' . PHP_EOL .1153 "\t" . '{' . PHP_EOL .1154 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .1155 "\t\t" . 'if (isset($this->getMockController()->' . $protectedMethodName . ') === false)' . PHP_EOL .1156 "\t\t" . '{' . PHP_EOL .1157 "\t\t\t" . '$this->mockController->' . $protectedMethodName . ' = function() {};' . PHP_EOL .1158 "\t\t" . '}' . PHP_EOL .1159 "\t\t" . 'return $this->mockController->invoke(\'' . $protectedMethodName . '\', $arguments);' . PHP_EOL .1160 "\t" . '}' . PHP_EOL .1161 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1162 "\t" . '{' . PHP_EOL .1163 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1164 "\t\t" . '{' . PHP_EOL .1165 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1166 "\t\t" . '}' . PHP_EOL .1167 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1168 "\t\t" . '{' . PHP_EOL .1169 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1170 "\t\t" . '}' . PHP_EOL .1171 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .1172 "\t\t" . '{' . PHP_EOL .1173 "\t\t\t" . '$this->mockController->invoke(\'__construct\', func_get_args());' . PHP_EOL .1174 "\t\t" . '}' . PHP_EOL .1175 "\t" . '}' . PHP_EOL .1176 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1177 "\t" . '{' . PHP_EOL .1178 "\t\t" . 'return ' . var_export(array($publicMethodName, $protectedMethodName, '__construct'), true) . ';' . PHP_EOL .1179 "\t" . '}' . PHP_EOL .1180 '}' . PHP_EOL .1181 '}'1182 )1183 ;1184 }1185 public function testGetMockedClassCodeForAbstractClassWithConstructorInInterface()1186 {1187 $this1188 ->if($generator = new testedClass())1189 ->and($publicMethodController = new mock\controller())1190 ->and($publicMethodController->__construct = function() {})1191 ->and($publicMethodController->getName = '__construct')1192 ->and($publicMethodController->isConstructor = false)1193 ->and($publicMethodController->getParameters = array())1194 ->and($publicMethodController->isPublic = true)1195 ->and($publicMethodController->isProtected = false)1196 ->and($publicMethodController->isFinal = false)1197 ->and($publicMethodController->isStatic = false)1198 ->and($publicMethodController->isAbstract = true)1199 ->and($publicMethodController->returnsReference = false)1200 ->and($publicMethod = new \mock\reflectionMethod(null, null))1201 ->and($classController = new mock\controller())1202 ->and($classController->__construct = function() {})1203 ->and($classController->getName = $className = uniqid())1204 ->and($classController->isFinal = false)1205 ->and($classController->isInterface = false)1206 ->and($classController->isAbstract = true)1207 ->and($classController->getMethods = array($publicMethod))1208 ->and($class = new \mock\reflectionClass(null))1209 ->and($generator->setReflectionClassFactory(function() use ($class) { return $class; }))1210 ->and($adapter = new atoum\test\adapter())1211 ->and($adapter->class_exists = function($class) use ($className) { return ($class == '\\' . $className); })1212 ->and($generator->setAdapter($adapter))1213 ->then1214 ->string($generator->getMockedClassCode($className))->isEqualTo(1215 'namespace mock {' . PHP_EOL .1216 'final class ' . $className . ' extends \\' . $className . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .1217 '{' . PHP_EOL .1218 "\t" . 'private $mockController = null;' . PHP_EOL .1219 "\t" . 'public function getMockController()' . PHP_EOL .1220 "\t" . '{' . PHP_EOL .1221 "\t\t" . 'if ($this->mockController === null)' . PHP_EOL .1222 "\t\t" . '{' . PHP_EOL .1223 "\t\t\t" . '$this->setMockController(new \mageekguy\atoum\mock\controller());' . PHP_EOL .1224 "\t\t" . '}' . PHP_EOL .1225 "\t\t" . 'return $this->mockController;' . PHP_EOL .1226 "\t" . '}' . PHP_EOL .1227 "\t" . 'public function setMockController(\mageekguy\atoum\mock\controller $controller)' . PHP_EOL .1228 "\t" . '{' . PHP_EOL .1229 "\t\t" . 'if ($this->mockController !== $controller)' . PHP_EOL .1230 "\t\t" . '{' . PHP_EOL .1231 "\t\t\t" . '$this->mockController = $controller;' . PHP_EOL .1232 "\t\t\t" . '$controller->control($this);' . PHP_EOL .1233 "\t\t" . '}' . PHP_EOL .1234 "\t\t" . 'return $this->mockController;' . PHP_EOL .1235 "\t" . '}' . PHP_EOL .1236 "\t" . 'public function resetMockController()' . PHP_EOL .1237 "\t" . '{' . PHP_EOL .1238 "\t\t" . 'if ($this->mockController !== null)' . PHP_EOL .1239 "\t\t" . '{' . PHP_EOL .1240 "\t\t\t" . '$mockController = $this->mockController;' . PHP_EOL .1241 "\t\t\t" . '$this->mockController = null;' . PHP_EOL .1242 "\t\t\t" . '$mockController->reset();' . PHP_EOL .1243 "\t\t" . '}' . PHP_EOL .1244 "\t\t" . 'return $this;' . PHP_EOL .1245 "\t" . '}' . PHP_EOL .1246 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1247 "\t" . '{' . PHP_EOL .1248 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .1249 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1250 "\t\t" . '{' . PHP_EOL ....

Full Screen

Full Screen

resetMockController

Using AI Code Generation

copy

Full Screen

1$generator = new Generator();2$generator->resetMockController();3$generator = new Generator();4$generator->resetMockController();5$generator = new Generator();6$generator->resetMockController();7$generator = new Generator();8$generator->resetMockController();9$generator = new Generator();10$generator->resetMockController();11$generator = new Generator();12$generator->resetMockController();13$generator = new Generator();14$generator->resetMockController();15$generator = new Generator();16$generator->resetMockController();17$generator = new Generator();18$generator->resetMockController();19$generator = new Generator();20$generator->resetMockController();21$generator = new Generator();22$generator->resetMockController();23$generator = new Generator();24$generator->resetMockController();25$generator = new Generator();26$generator->resetMockController();27$generator = new Generator();28$generator->resetMockController();29$generator = new Generator();30$generator->resetMockController();31$generator = new Generator();32$generator->resetMockController();

Full Screen

Full Screen

resetMockController

Using AI Code Generation

copy

Full Screen

1require_once 'generator.php';2$generator = new generator();3$generator->resetMockController();4require_once 'generator.php';5$generator = new generator();6$generator->resetMockController();7require_once 'generator.php';8$generator = new generator();9$generator->resetMockController();10require_once 'generator.php';11$generator = new generator();12$generator->resetMockController();13require_once 'generator.php';14$generator = new generator();15$generator->resetMockController();16require_once 'generator.php';17$generator = new generator();18$generator->resetMockController();19require_once 'generator.php';20$generator = new generator();21$generator->resetMockController();22require_once 'generator.php';23$generator = new generator();24$generator->resetMockController();25require_once 'generator.php';26$generator = new generator();27$generator->resetMockController();28require_once 'generator.php';29$generator = new generator();30$generator->resetMockController();31require_once 'generator.php';32$generator = new generator();33$generator->resetMockController();34require_once 'generator.php';35$generator = new generator();36$generator->resetMockController();37require_once 'generator.php';38$generator = new generator();39$generator->resetMockController();

Full Screen

Full Screen

resetMockController

Using AI Code Generation

copy

Full Screen

1require_once 'generator.php';2$generator = new generator();3$generator->resetMockController();4require_once 'generator.php';5$generator = new generator();6$generator->resetMockController();

Full Screen

Full Screen

resetMockController

Using AI Code Generation

copy

Full Screen

1$generator = new Generator($this->getMockController());2$generator->resetMockController();3$generator = new Generator($this->getMockController());4$generator->resetMockController();5$generator = new Generator($this->getMockController());6$generator->resetMockController();7$generator = new Generator($this->getMockController());8$generator->resetMockController();9$generator = new Generator($this->getMockController());10$generator->resetMockController();11$generator = new Generator($this->getMockController());12$generator->resetMockController();13$generator = new Generator($this->getMockController());14$generator->resetMockController();15$generator = new Generator($this->getMockController());16$generator->resetMockController();17$generator = new Generator($this->getMockController());18$generator->resetMockController();19$generator = new Generator($this->getMockController());20$generator->resetMockController();21$generator = new Generator($this->getMockController());22$generator->resetMockController();23$generator = new Generator($this->getMockController());24$generator->resetMockController();25$generator = new Generator($this->getMockController());26$generator->resetMockController();27$generator = new Generator($this->getMockController());

Full Screen

Full Screen

resetMockController

Using AI Code Generation

copy

Full Screen

1$mockGenerator = new \Zend\Code\Generator\ClassGenerator();2$mockGenerator->resetMockController();3$mockGenerator->getMockController();4$mockGenerator = new \Zend\Code\Generator\ClassGenerator();5$mockGenerator->resetMockController();6$mockGenerator->getMockController();

Full Screen

Full Screen

resetMockController

Using AI Code Generation

copy

Full Screen

1$generator = new Generator();2$generator->resetMockController();3$generator->generate('1.php');4$generator = new Generator();5$generator->resetMockController();6$generator->generate('2.php');7$generator = new Generator();8$generator->resetMockController();9$generator->generate('3.php');10$generator = new Generator();11$generator->resetMockController();12$generator->generate('4.php');13$generator = new Generator();14$generator->resetMockController();15$generator->generate('5.php');16$generator = new Generator();17$generator->resetMockController();18$generator->generate('6.php');19$generator = new Generator();20$generator->resetMockController();21$generator->generate('7.php');22$generator = new Generator();23$generator->resetMockController();24$generator->generate('8.php');25$generator = new Generator();26$generator->resetMockController();27$generator->generate('9.php');28$generator = new Generator();29$generator->resetMockController();30$generator->generate('10.php');

Full Screen

Full Screen

resetMockController

Using AI Code Generation

copy

Full Screen

1$generator = new Generator();2$generator->resetMockController();3$generator = new Generator();4$generator->resetMockController();5$generator->getMock("ClassName", array(), array(), "MockClassName");6. 1 / 1 (100%)7OK (1 test, 1 assertion)

Full Screen

Full Screen

resetMockController

Using AI Code Generation

copy

Full Screen

1require_once 'PHPUnit/Extensions/Story/Generator.php';2$generator = new PHPUnit_Extensions_Story_Generator();3$generator->resetMockController();4require_once 'PHPUnit/Extensions/Story/Generator.php';5$generator = new PHPUnit_Extensions_Story_Generator();6$generator->createStory('story1', 'story1.story');7require_once 'PHPUnit/Extensions/Story/Generator.php';8$generator = new PHPUnit_Extensions_Story_Generator();9$generator->createStory('story2', 'story2.story');10$generator->addScenario('story2', 'scenario1', 'scenario1.scenario');11require_once 'PHPUnit/Extensions/Story/Generator.php';12$generator = new PHPUnit_Extensions_Story_Generator();13$generator->createStory('story3', 'story3.story');14$generator->addScenario('story3', 'scenario1', 'scenario1.scenario');15$generator->addStep('story3', 'scenario1', 'step1', 'step1.step');16require_once 'PHPUnit/Extensions/Story/Generator.php';17$generator = new PHPUnit_Extensions_Story_Generator();18$generator->createStory('story4', 'story4.story');19$generator->addScenario('story4', 'scenario1', 'scenario1.scenario');20$generator->addStep('story4', 'scenario1', 'step1', 'step1.step');21$generator->addCode('story4', 'scenario1', 'code1', 'code1.code');

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Atoum automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in generator

Trigger resetMockController code on LambdaTest Cloud Grid

Execute automation tests with resetMockController on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful