How to use getMockControllerMethods method of generator class

Best Atoum code snippet using generator.getMockControllerMethods

generator.php

Source:generator.php Github

copy

Full Screen

...171 ->string($generator->getMockedClassCode($unknownClass = uniqid()))->isEqualTo(172 'namespace mock {' . PHP_EOL .173 'final class ' . $unknownClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .174 '{' . PHP_EOL .175 $this->getMockControllerMethods() .176 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .177 "\t" . '{' . PHP_EOL .178 "\t\t" . 'if ($mockController === null)' . PHP_EOL .179 "\t\t" . '{' . PHP_EOL .180 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .181 "\t\t" . '}' . PHP_EOL .182 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .183 "\t\t" . '{' . PHP_EOL .184 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .185 "\t\t" . '}' . PHP_EOL .186 "\t\t" . '$this->getMockController()->disableMethodChecking();' . PHP_EOL .187 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .188 "\t\t" . '{' . PHP_EOL .189 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .190 "\t\t" . '}' . PHP_EOL .191 "\t" . '}' . PHP_EOL .192 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .193 "\t" . '{' . PHP_EOL .194 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .195 "\t\t" . '{' . PHP_EOL .196 "\t\t\t" . '$return = $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .197 "\t\t\t" . 'return $return;' . PHP_EOL .198 "\t\t" . '}' . PHP_EOL .199 "\t\t" . 'else' . PHP_EOL .200 "\t\t" . '{' . PHP_EOL .201 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .202 "\t\t" . '}' . PHP_EOL .203 "\t" . '}' . PHP_EOL .204 "\t" . 'public static function getMockedMethods()' . PHP_EOL .205 "\t" . '{' . PHP_EOL .206 "\t\t" . 'return ' . var_export(array('__call'), true) . ';' . PHP_EOL .207 "\t" . '}' . PHP_EOL .208 '}' . PHP_EOL .209 '}'210 )211 ->if($unknownClass = __NAMESPACE__ . '\dummy')212 ->and($generator->generate($unknownClass))213 ->and($mockedUnknownClass = '\mock\\' . $unknownClass)214 ->and($dummy = new $mockedUnknownClass())215 ->and($dummyController = new atoum\mock\controller())216 ->and($dummyController->notControlNextNewMock())217 ->and($calls = new \mock\mageekguy\atoum\test\adapter\calls())218 ->and($dummyController->setCalls($calls))219 ->and($dummyController->control($dummy))220 ->then221 ->when(function() use ($dummy) { $dummy->bar(); })222 ->mock($calls)->call('addCall')->withArguments(new atoum\test\adapter\call('bar', array(), new decorators\addClass($dummy)))->once()223 ->when(function() use ($dummy) { $dummy->bar(); })224 ->mock($calls)->call('addCall')->withArguments(new atoum\test\adapter\call('bar', array(), new decorators\addClass($dummy)))->twice()225 ;226 }227 public function testGetMockedClassCodeForRealClass()228 {229 $this230 ->if($generator = new testedClass())231 ->and($reflectionMethodController = new mock\controller())232 ->and($reflectionMethodController->__construct = function() {})233 ->and($reflectionMethodController->getName = '__construct')234 ->and($reflectionMethodController->isConstructor = true)235 ->and($reflectionMethodController->getParameters = array())236 ->and($reflectionMethodController->isPublic = true)237 ->and($reflectionMethodController->isProtected = false)238 ->and($reflectionMethodController->isPrivate = false)239 ->and($reflectionMethodController->isFinal = false)240 ->and($reflectionMethodController->isStatic = false)241 ->and($reflectionMethodController->isAbstract = false)242 ->and($reflectionMethodController->returnsReference = false)243 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))244 ->and($reflectionClassController = new mock\controller())245 ->and($reflectionClassController->__construct = function() {})246 ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })247 ->and($reflectionClassController->isFinal = false)248 ->and($reflectionClassController->isInterface = false)249 ->and($reflectionClassController->isAbstract = false)250 ->and($reflectionClassController->getMethods = array($reflectionMethod))251 ->and($reflectionClassController->getConstructor = $reflectionMethod)252 ->and($reflectionClass = new \mock\reflectionClass(null))253 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))254 ->and($adapter = new atoum\test\adapter())255 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })256 ->and($generator->setAdapter($adapter))257 ->then258 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(259 'namespace mock {' . PHP_EOL .260 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .261 '{' . PHP_EOL .262 $this->getMockControllerMethods() .263 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .264 "\t" . '{' . PHP_EOL .265 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .266 "\t\t" . 'if ($mockController === null)' . PHP_EOL .267 "\t\t" . '{' . PHP_EOL .268 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .269 "\t\t" . '}' . PHP_EOL .270 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .271 "\t\t" . '{' . PHP_EOL .272 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .273 "\t\t" . '}' . PHP_EOL .274 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .275 "\t\t" . '{' . PHP_EOL .276 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .277 "\t\t" . '}' . PHP_EOL .278 "\t\t" . 'else' . PHP_EOL .279 "\t\t" . '{' . PHP_EOL .280 "\t\t\t" . '$this->getMockController()->addCall(\'__construct\', $arguments);' . PHP_EOL .281 "\t\t\t" . 'call_user_func_array(\'parent::__construct\', $arguments);' . PHP_EOL .282 "\t\t" . '}' . PHP_EOL .283 "\t" . '}' . PHP_EOL .284 "\t" . 'public static function getMockedMethods()' . PHP_EOL .285 "\t" . '{' . PHP_EOL .286 "\t\t" . 'return ' . var_export(array('__construct'), true) . ';' . PHP_EOL .287 "\t" . '}' . PHP_EOL .288 '}' . PHP_EOL .289 '}'290 )291 ;292 }293 public function testGetMockedClassCodeForRealClassWithDeprecatedConstructor()294 {295 $this296 ->if($generator = new testedClass())297 ->and($reflectionMethodController = new mock\controller())298 ->and($reflectionMethodController->__construct = function() {})299 ->and($reflectionMethodController->getName = $realClass = uniqid())300 ->and($reflectionMethodController->isConstructor = true)301 ->and($reflectionMethodController->getParameters = array())302 ->and($reflectionMethodController->isPublic = true)303 ->and($reflectionMethodController->isProtected = false)304 ->and($reflectionMethodController->isPrivate = false)305 ->and($reflectionMethodController->isFinal = false)306 ->and($reflectionMethodController->isStatic = false)307 ->and($reflectionMethodController->isAbstract = false)308 ->and($reflectionMethodController->returnsReference = false)309 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))310 ->and($reflectionClassController = new mock\controller())311 ->and($reflectionClassController->__construct = function() {})312 ->and($reflectionClassController->getName = $realClass)313 ->and($reflectionClassController->isFinal = false)314 ->and($reflectionClassController->isInterface = false)315 ->and($reflectionClassController->isAbstract = false)316 ->and($reflectionClassController->getMethods = array($reflectionMethod))317 ->and($reflectionClassController->getConstructor = $reflectionMethod)318 ->and($reflectionClass = new \mock\reflectionClass(null))319 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))320 ->and($adapter = new atoum\test\adapter())321 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })322 ->and($generator->setAdapter($adapter))323 ->then324 ->string($generator->getMockedClassCode($realClass))->isEqualTo(325 'namespace mock {' . PHP_EOL .326 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .327 '{' . PHP_EOL .328 $this->getMockControllerMethods() .329 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .330 "\t" . '{' . PHP_EOL .331 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .332 "\t\t" . 'if ($mockController === null)' . PHP_EOL .333 "\t\t" . '{' . PHP_EOL .334 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .335 "\t\t" . '}' . PHP_EOL .336 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .337 "\t\t" . '{' . PHP_EOL .338 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .339 "\t\t" . '}' . PHP_EOL .340 "\t\t" . 'if (isset($this->getMockController()->' . $realClass . ') === true)' . PHP_EOL .341 "\t\t" . '{' . PHP_EOL .342 "\t\t\t" . '$this->getMockController()->invoke(\'' . $realClass . '\', $arguments);' . PHP_EOL .343 "\t\t" . '}' . PHP_EOL .344 "\t\t" . 'else' . PHP_EOL .345 "\t\t" . '{' . PHP_EOL .346 "\t\t\t" . '$this->getMockController()->addCall(\'' . $realClass . '\', $arguments);' . PHP_EOL .347 "\t\t\t" . 'call_user_func_array(\'parent::' . $realClass . '\', $arguments);' . PHP_EOL .348 "\t\t" . '}' . PHP_EOL .349 "\t" . '}' . PHP_EOL .350 "\t" . 'public static function getMockedMethods()' . PHP_EOL .351 "\t" . '{' . PHP_EOL .352 "\t\t" . 'return ' . var_export(array($realClass), true) . ';' . PHP_EOL .353 "\t" . '}' . PHP_EOL .354 '}' . PHP_EOL .355 '}'356 )357 ;358 }359 /** @php < 7.0 */360 public function testGetMockedClassCodeForRealClassWithCallsToParentClassShunted()361 {362 $this363 ->if($generator = new testedClass())364 ->and($reflectionMethodController = new mock\controller())365 ->and($reflectionMethodController->__construct = function() {})366 ->and($reflectionMethodController->getName = '__construct')367 ->and($reflectionMethodController->isConstructor = true)368 ->and($reflectionMethodController->getParameters = array())369 ->and($reflectionMethodController->isPublic = true)370 ->and($reflectionMethodController->isProtected = false)371 ->and($reflectionMethodController->isPrivate = false)372 ->and($reflectionMethodController->isFinal = false)373 ->and($reflectionMethodController->isStatic = false)374 ->and($reflectionMethodController->isAbstract = false)375 ->and($reflectionMethodController->returnsReference = false)376 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))377 ->and($otherReflectionMethodController = new mock\controller())378 ->and($otherReflectionMethodController->__construct = function() {})379 ->and($otherReflectionMethodController->getName = $otherMethod = uniqid())380 ->and($otherReflectionMethodController->isConstructor = false)381 ->and($otherReflectionMethodController->getParameters = array())382 ->and($otherReflectionMethodController->isPublic = true)383 ->and($otherReflectionMethodController->isProtected = false)384 ->and($otherReflectionMethodController->isPrivate = false)385 ->and($otherReflectionMethodController->isFinal = false)386 ->and($otherReflectionMethodController->isStatic = false)387 ->and($otherReflectionMethodController->isAbstract = false)388 ->and($otherReflectionMethodController->returnsReference = false)389 ->and($otherReflectionMethod = new \mock\reflectionMethod(null, null))390 ->and($reflectionClassController = new mock\controller())391 ->and($reflectionClassController->__construct = function() {})392 ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })393 ->and($reflectionClassController->isFinal = false)394 ->and($reflectionClassController->isInterface = false)395 ->and($reflectionClassController->isAbstract = false)396 ->and($reflectionClassController->getMethods = array($reflectionMethod, $otherReflectionMethod))397 ->and($reflectionClassController->getConstructor = $reflectionMethod)398 ->and($reflectionClass = new \mock\reflectionClass(null))399 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))400 ->and($adapter = new atoum\test\adapter())401 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })402 ->and($generator->setAdapter($adapter))403 ->and($generator->shuntParentClassCalls())404 ->then405 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(406 'namespace mock {' . PHP_EOL .407 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .408 '{' . PHP_EOL .409 $this->getMockControllerMethods() .410 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .411 "\t" . '{' . PHP_EOL .412 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .413 "\t\t" . 'if ($mockController === null)' . PHP_EOL .414 "\t\t" . '{' . PHP_EOL .415 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .416 "\t\t" . '}' . PHP_EOL .417 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .418 "\t\t" . '{' . PHP_EOL .419 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .420 "\t\t" . '}' . PHP_EOL .421 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .422 "\t\t" . '{' . PHP_EOL .423 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .424 "\t\t" . '}' . PHP_EOL .425 "\t\t" . 'else' . PHP_EOL .426 "\t\t" . '{' . PHP_EOL .427 "\t\t\t" . '$this->getMockController()->addCall(\'__construct\', $arguments);' . PHP_EOL .428 "\t\t" . '}' . PHP_EOL .429 "\t" . '}' . PHP_EOL .430 "\t" . 'public function ' . $otherMethod . '()' . PHP_EOL .431 "\t" . '{' . PHP_EOL .432 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .433 "\t\t" . 'if (isset($this->getMockController()->' . $otherMethod . ') === true)' . PHP_EOL .434 "\t\t" . '{' . PHP_EOL .435 "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $otherMethod . '\', $arguments);' . PHP_EOL .436 "\t\t\t" . 'return $return;' . PHP_EOL .437 "\t\t" . '}' . PHP_EOL .438 "\t\t" . 'else' . PHP_EOL .439 "\t\t" . '{' . PHP_EOL .440 "\t\t\t" . '$this->getMockController()->addCall(\'' . $otherMethod . '\', $arguments);' . PHP_EOL .441 "\t\t" . '}' . PHP_EOL .442 "\t" . '}' . PHP_EOL .443 "\t" . 'public static function getMockedMethods()' . PHP_EOL .444 "\t" . '{' . PHP_EOL .445 "\t\t" . 'return ' . var_export(array('__construct', $otherMethod), true) . ';' . PHP_EOL .446 "\t" . '}' . PHP_EOL .447 '}' . PHP_EOL .448 '}'449 )450 ;451 }452 /** @php >= 7.0 */453 public function testGetMockedClassCodeForRealClassWithCallsToParentClassShuntedPhp7()454 {455 $this456 ->if($generator = new testedClass())457 ->and($reflectionMethodController = new mock\controller())458 ->and($reflectionMethodController->__construct = function() {})459 ->and($reflectionMethodController->getName = '__construct')460 ->and($reflectionMethodController->isConstructor = true)461 ->and($reflectionMethodController->getParameters = array())462 ->and($reflectionMethodController->isPublic = true)463 ->and($reflectionMethodController->isProtected = false)464 ->and($reflectionMethodController->isPrivate = false)465 ->and($reflectionMethodController->isFinal = false)466 ->and($reflectionMethodController->isStatic = false)467 ->and($reflectionMethodController->isAbstract = false)468 ->and($reflectionMethodController->returnsReference = false)469 ->and($reflectionMethodController->hasReturnType = false)470 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))471 ->and($otherReflectionMethodController = new mock\controller())472 ->and($otherReflectionMethodController->__construct = function() {})473 ->and($otherReflectionMethodController->getName = $otherMethod = uniqid())474 ->and($otherReflectionMethodController->isConstructor = false)475 ->and($otherReflectionMethodController->getParameters = array())476 ->and($otherReflectionMethodController->isPublic = true)477 ->and($otherReflectionMethodController->isProtected = false)478 ->and($otherReflectionMethodController->isPrivate = false)479 ->and($otherReflectionMethodController->isFinal = false)480 ->and($otherReflectionMethodController->isStatic = false)481 ->and($otherReflectionMethodController->isAbstract = false)482 ->and($otherReflectionMethodController->returnsReference = false)483 ->and($otherReflectionMethodController->hasReturnType = false)484 ->and($otherReflectionMethod = new \mock\reflectionMethod(null, null))485 ->and($reflectionClassController = new mock\controller())486 ->and($reflectionClassController->__construct = function() {})487 ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })488 ->and($reflectionClassController->isFinal = false)489 ->and($reflectionClassController->isInterface = false)490 ->and($reflectionClassController->isAbstract = false)491 ->and($reflectionClassController->getMethods = array($reflectionMethod, $otherReflectionMethod))492 ->and($reflectionClassController->getConstructor = $reflectionMethod)493 ->and($reflectionClass = new \mock\reflectionClass(null))494 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))495 ->and($adapter = new atoum\test\adapter())496 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })497 ->and($generator->setAdapter($adapter))498 ->and($generator->shuntParentClassCalls())499 ->then500 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(501 'namespace mock {' . PHP_EOL .502 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .503 '{' . PHP_EOL .504 $this->getMockControllerMethods() .505 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .506 "\t" . '{' . PHP_EOL .507 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .508 "\t\t" . 'if ($mockController === null)' . PHP_EOL .509 "\t\t" . '{' . PHP_EOL .510 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .511 "\t\t" . '}' . PHP_EOL .512 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .513 "\t\t" . '{' . PHP_EOL .514 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .515 "\t\t" . '}' . PHP_EOL .516 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .517 "\t\t" . '{' . PHP_EOL .518 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .519 "\t\t" . '}' . PHP_EOL .520 "\t\t" . 'else' . PHP_EOL .521 "\t\t" . '{' . PHP_EOL .522 "\t\t\t" . '$this->getMockController()->addCall(\'__construct\', $arguments);' . PHP_EOL .523 "\t\t" . '}' . PHP_EOL .524 "\t" . '}' . PHP_EOL .525 "\t" . 'public function ' . $otherMethod . '()' . PHP_EOL .526 "\t" . '{' . PHP_EOL .527 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .528 "\t\t" . 'if (isset($this->getMockController()->' . $otherMethod . ') === true)' . PHP_EOL .529 "\t\t" . '{' . PHP_EOL .530 "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $otherMethod . '\', $arguments);' . PHP_EOL .531 "\t\t\t" . 'return $return;' . PHP_EOL .532 "\t\t" . '}' . PHP_EOL .533 "\t\t" . 'else' . PHP_EOL .534 "\t\t" . '{' . PHP_EOL .535 "\t\t\t" . '$this->getMockController()->addCall(\'' . $otherMethod . '\', $arguments);' . PHP_EOL .536 "\t\t" . '}' . PHP_EOL .537 "\t" . '}' . PHP_EOL .538 "\t" . 'public static function getMockedMethods()' . PHP_EOL .539 "\t" . '{' . PHP_EOL .540 "\t\t" . 'return ' . var_export(array('__construct', $otherMethod), true) . ';' . PHP_EOL .541 "\t" . '}' . PHP_EOL .542 '}' . PHP_EOL .543 '}'544 )545 ;546 }547 public function testGetMockedClassCodeWithOverloadMethod()548 {549 $this550 ->if($generator = new testedClass())551 ->and($reflectionMethodController = new mock\controller())552 ->and($reflectionMethodController->__construct = function() {})553 ->and($reflectionMethodController->getName = '__construct')554 ->and($reflectionMethodController->isConstructor = true)555 ->and($reflectionMethodController->getParameters = array())556 ->and($reflectionMethodController->isPublic = true)557 ->and($reflectionMethodController->isProtected = false)558 ->and($reflectionMethodController->isPrivate = false)559 ->and($reflectionMethodController->isFinal = false)560 ->and($reflectionMethodController->isAbstract = false)561 ->and($reflectionMethodController->isStatic = false)562 ->and($reflectionMethodController->returnsReference = false)563 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))564 ->and($reflectionClassController = new mock\controller())565 ->and($reflectionClassController->__construct = function() {})566 ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })567 ->and($reflectionClassController->isFinal = false)568 ->and($reflectionClassController->isInterface = false)569 ->and($reflectionClassController->getMethods = array($reflectionMethod))570 ->and($reflectionClassController->getConstructor = $reflectionMethod)571 ->and($reflectionClassController->isAbstract = false)572 ->and($reflectionClass = new \mock\reflectionClass(null))573 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))574 ->and($adapter = new atoum\test\adapter())575 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })576 ->and($generator->setAdapter($adapter))577 ->and($overloadedMethod = new mock\php\method('__construct'))578 ->and($overloadedMethod->addArgument($argument = new mock\php\method\argument(uniqid())))579 ->and($generator->overload($overloadedMethod))580 ->then581 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(582 'namespace mock {' . PHP_EOL .583 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .584 '{' . PHP_EOL .585 $this->getMockControllerMethods() .586 "\t" . '' . $overloadedMethod . PHP_EOL .587 "\t" . '{' . PHP_EOL .588 "\t\t" . '$arguments = array_merge(array(' . $argument . '), array_slice(func_get_args(), 1, -1));' . PHP_EOL .589 "\t\t" . 'if ($mockController === null)' . PHP_EOL .590 "\t\t" . '{' . PHP_EOL .591 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .592 "\t\t" . '}' . PHP_EOL .593 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .594 "\t\t" . '{' . PHP_EOL .595 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .596 "\t\t" . '}' . PHP_EOL .597 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .598 "\t\t" . '{' . PHP_EOL .599 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .600 "\t\t" . '}' . PHP_EOL .601 "\t\t" . 'else' . PHP_EOL .602 "\t\t" . '{' . PHP_EOL .603 "\t\t\t" . '$this->getMockController()->addCall(\'__construct\', $arguments);' . PHP_EOL .604 "\t\t\t" . 'call_user_func_array(\'parent::__construct\', $arguments);' . PHP_EOL .605 "\t\t" . '}' . PHP_EOL .606 "\t" . '}' . PHP_EOL .607 "\t" . 'public static function getMockedMethods()' . PHP_EOL .608 "\t" . '{' . PHP_EOL .609 "\t\t" . 'return ' . var_export(array('__construct'), true) . ';' . PHP_EOL .610 "\t" . '}' . PHP_EOL .611 '}' . PHP_EOL .612 '}'613 )614 ;615 }616 public function testGetMockedClassCodeWithAbstractMethod()617 {618 $this619 ->if($generator = new testedClass())620 ->and($realClass = uniqid())621 ->and($reflectionMethodController = new mock\controller())622 ->and($reflectionMethodController->__construct = function() {})623 ->and($reflectionMethodController->getName = function() { return '__construct'; })624 ->and($reflectionMethodController->isConstructor = true)625 ->and($reflectionMethodController->getParameters = array())626 ->and($reflectionMethodController->isPublic = true)627 ->and($reflectionMethodController->isProtected = false)628 ->and($reflectionMethodController->isPrivate = false)629 ->and($reflectionMethodController->isFinal = false)630 ->and($reflectionMethodController->isStatic = false)631 ->and($reflectionMethodController->isAbstract = true)632 ->and($reflectionMethodController->returnsReference = false)633 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))634 ->and($reflectionClassController = new mock\controller())635 ->and($reflectionClassController->__construct = function() {})636 ->and($reflectionClassController->getName = function() use ($realClass) { return $realClass; })637 ->and($reflectionClassController->isFinal = false)638 ->and($reflectionClassController->isInterface = false)639 ->and($reflectionClassController->getMethods = array($reflectionMethod))640 ->and($reflectionClassController->getConstructor = $reflectionMethod)641 ->and($reflectionClassController->isAbstract = false)642 ->and($reflectionClass = new \mock\reflectionClass(null))643 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))644 ->and($adapter = new atoum\test\adapter())645 ->and($adapter->class_exists = function($class) use ($realClass) { return ($class == '\\' . $realClass); })646 ->and($generator->setAdapter($adapter))647 ->then648 ->string($generator->getMockedClassCode($realClass))->isEqualTo(649 'namespace mock {' . PHP_EOL .650 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .651 '{' . PHP_EOL .652 $this->getMockControllerMethods() .653 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .654 "\t" . '{' . PHP_EOL .655 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .656 "\t\t" . 'if ($mockController === null)' . PHP_EOL .657 "\t\t" . '{' . PHP_EOL .658 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .659 "\t\t" . '}' . PHP_EOL .660 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .661 "\t\t" . '{' . PHP_EOL .662 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .663 "\t\t" . '}' . PHP_EOL .664 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .665 "\t\t" . '{' . PHP_EOL .666 "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .667 "\t\t" . '}' . PHP_EOL .668 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .669 "\t" . '}' . PHP_EOL .670 "\t" . 'public static function getMockedMethods()' . PHP_EOL .671 "\t" . '{' . PHP_EOL .672 "\t\t" . 'return ' . var_export(array('__construct'), true) . ';' . PHP_EOL .673 "\t" . '}' . PHP_EOL .674 '}' . PHP_EOL .675 '}'676 )677 ;678 }679 public function testGetMockedClassCodeWithShuntedMethod()680 {681 $this682 ->if($generator = new testedClass())683 ->and($realClass = uniqid())684 ->and($reflectionMethodController = new mock\controller())685 ->and($reflectionMethodController->__construct = function() {})686 ->and($reflectionMethodController->getName = function() { return '__construct'; })687 ->and($reflectionMethodController->isConstructor = true)688 ->and($reflectionMethodController->isAbstract = false)689 ->and($reflectionMethodController->getParameters = array())690 ->and($reflectionMethodController->isPublic = true)691 ->and($reflectionMethodController->isProtected = false)692 ->and($reflectionMethodController->isPrivate = false)693 ->and($reflectionMethodController->isFinal = false)694 ->and($reflectionMethodController->isStatic = false)695 ->and($reflectionMethodController->returnsReference = false)696 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))697 ->and($reflectionClassController = new mock\controller())698 ->and($reflectionClassController->__construct = function() {})699 ->and($reflectionClassController->getName = function() use ($realClass) { return $realClass; })700 ->and($reflectionClassController->isFinal = false)701 ->and($reflectionClassController->isInterface = false)702 ->and($reflectionClassController->getMethods = array($reflectionMethod))703 ->and($reflectionClassController->getConstructor = $reflectionMethod)704 ->and($reflectionClassController->isAbstract = false)705 ->and($reflectionClass = new \mock\reflectionClass(null))706 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))707 ->and($adapter = new atoum\test\adapter())708 ->and($adapter->class_exists = function($class) use ($realClass) { return ($class == '\\' . $realClass); })709 ->and($generator->setAdapter($adapter))710 ->and($generator->shunt('__construct'))711 ->then712 ->string($generator->getMockedClassCode($realClass))->isEqualTo(713 'namespace mock {' . PHP_EOL .714 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .715 '{' . PHP_EOL .716 $this->getMockControllerMethods() .717 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .718 "\t" . '{' . PHP_EOL .719 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .720 "\t\t" . 'if ($mockController === null)' . PHP_EOL .721 "\t\t" . '{' . PHP_EOL .722 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .723 "\t\t" . '}' . PHP_EOL .724 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .725 "\t\t" . '{' . PHP_EOL .726 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .727 "\t\t" . '}' . PHP_EOL .728 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .729 "\t\t" . '{' . PHP_EOL .730 "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .731 "\t\t" . '}' . PHP_EOL .732 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .733 "\t" . '}' . PHP_EOL .734 "\t" . 'public static function getMockedMethods()' . PHP_EOL .735 "\t" . '{' . PHP_EOL .736 "\t\t" . 'return ' . var_export(array('__construct'), true) . ';' . PHP_EOL .737 "\t" . '}' . PHP_EOL .738 '}' . PHP_EOL .739 '}'740 )741 ;742 }743 /** @php < 7.0 */744 public function testGetMockedClassCodeWithAllIsInterface()745 {746 $this747 ->if($generator = new testedClass())748 ->and($realClass = uniqid())749 ->and($reflectionMethodController = new mock\controller())750 ->and($reflectionMethodController->__construct = function() {})751 ->and($reflectionMethodController->getName = 'foo')752 ->and($reflectionMethodController->isConstructor = false)753 ->and($reflectionMethodController->getParameters = array())754 ->and($reflectionMethodController->isPublic = true)755 ->and($reflectionMethodController->isProtected = false)756 ->and($reflectionMethodController->isPrivate = false)757 ->and($reflectionMethodController->isFinal = false)758 ->and($reflectionMethodController->isAbstract = false)759 ->and($reflectionMethodController->isStatic = false)760 ->and($reflectionMethodController->returnsReference = false)761 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))762 ->and($reflectionClassController = new mock\controller())763 ->and($reflectionClassController->__construct = function() {})764 ->and($reflectionClassController->getName = function() use ($realClass) { return $realClass; })765 ->and($reflectionClassController->isFinal = false)766 ->and($reflectionClassController->isInterface = false)767 ->and($reflectionClassController->getMethods = array($reflectionMethod))768 ->and($reflectionClassController->getConstructor = null)769 ->and($reflectionClassController->isAbstract = false)770 ->and($reflectionClass = new \mock\reflectionClass(null))771 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))772 ->and($adapter = new atoum\test\adapter())773 ->and($adapter->class_exists = function($class) use ($realClass) { return ($class == '\\' . $realClass); })774 ->and($generator->setAdapter($adapter))775 ->and($generator->shunt('__construct'))776 ->and($generator->allIsInterface())777 ->then778 ->string($generator->getMockedClassCode($realClass))->isEqualTo(779 'namespace mock {' . PHP_EOL .780 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .781 '{' . PHP_EOL .782 $this->getMockControllerMethods() .783 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .784 "\t" . '{' . PHP_EOL .785 "\t\t" . 'if ($mockController === null)' . PHP_EOL .786 "\t\t" . '{' . PHP_EOL .787 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .788 "\t\t" . '}' . PHP_EOL .789 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .790 "\t\t" . '{' . PHP_EOL .791 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .792 "\t\t" . '}' . PHP_EOL .793 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .794 "\t\t" . '{' . PHP_EOL .795 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .796 "\t\t" . '}' . PHP_EOL .797 "\t" . '}' . PHP_EOL .798 "\t" . 'public function foo()' . PHP_EOL .799 "\t" . '{' . PHP_EOL .800 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .801 "\t\t" . 'if (isset($this->getMockController()->foo) === false)' . PHP_EOL .802 "\t\t" . '{' . PHP_EOL .803 "\t\t\t" . '$this->getMockController()->foo = function() {};' . PHP_EOL .804 "\t\t" . '}' . PHP_EOL .805 "\t\t" . '$return = $this->getMockController()->invoke(\'foo\', $arguments);' . PHP_EOL .806 "\t\t" . 'return $return;' . PHP_EOL .807 "\t" . '}' . PHP_EOL .808 "\t" . 'public static function getMockedMethods()' . PHP_EOL .809 "\t" . '{' . PHP_EOL .810 "\t\t" . 'return ' . var_export(array('__construct', 'foo'), true) . ';' . PHP_EOL .811 "\t" . '}' . PHP_EOL .812 '}' . PHP_EOL .813 '}'814 )815 ->if($generator->testedClassIs($realClass))816 ->then817 ->string($generator->getMockedClassCode($realClass))->isEqualTo(818 'namespace mock {' . PHP_EOL .819 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .820 '{' . PHP_EOL .821 $this->getMockControllerMethods() .822 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .823 "\t" . '{' . PHP_EOL .824 "\t\t" . 'if ($mockController === null)' . PHP_EOL .825 "\t\t" . '{' . PHP_EOL .826 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .827 "\t\t" . '}' . PHP_EOL .828 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .829 "\t\t" . '{' . PHP_EOL .830 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .831 "\t\t" . '}' . PHP_EOL .832 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .833 "\t\t" . '{' . PHP_EOL .834 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .835 "\t\t" . '}' . PHP_EOL .836 "\t" . '}' . PHP_EOL .837 "\t" . 'public function foo()' . PHP_EOL .838 "\t" . '{' . PHP_EOL .839 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .840 "\t\t" . 'if (isset($this->getMockController()->foo) === true)' . PHP_EOL .841 "\t\t" . '{' . PHP_EOL .842 "\t\t\t" . '$return = $this->getMockController()->invoke(\'foo\', $arguments);' . PHP_EOL .843 "\t\t\t" . 'return $return;' . PHP_EOL .844 "\t\t" . '}' . PHP_EOL .845 "\t\t" . 'else' . PHP_EOL .846 "\t\t" . '{' . PHP_EOL .847 "\t\t\t" . '$this->getMockController()->addCall(\'foo\', $arguments);' . PHP_EOL .848 "\t\t\t" . '$return = call_user_func_array(\'parent::foo\', $arguments);' . PHP_EOL .849 "\t\t\t" . 'return $return;' . PHP_EOL .850 "\t\t" . '}' . PHP_EOL .851 "\t" . '}' . PHP_EOL .852 "\t" . 'public static function getMockedMethods()' . PHP_EOL .853 "\t" . '{' . PHP_EOL .854 "\t\t" . 'return ' . var_export(array('__construct', 'foo'), true) . ';' . PHP_EOL .855 "\t" . '}' . PHP_EOL .856 '}' . PHP_EOL .857 '}'858 )859 ;860 }861 /** @php >= 7.0 */862 public function testGetMockedClassCodeWithAllIsInterfacePhp7()863 {864 $this865 ->if($generator = new testedClass())866 ->and($realClass = uniqid())867 ->and($reflectionMethodController = new mock\controller())868 ->and($reflectionMethodController->__construct = function() {})869 ->and($reflectionMethodController->getName = 'foo')870 ->and($reflectionMethodController->isConstructor = false)871 ->and($reflectionMethodController->getParameters = array())872 ->and($reflectionMethodController->isPublic = true)873 ->and($reflectionMethodController->isProtected = false)874 ->and($reflectionMethodController->isPrivate = false)875 ->and($reflectionMethodController->isFinal = false)876 ->and($reflectionMethodController->isAbstract = false)877 ->and($reflectionMethodController->isStatic = false)878 ->and($reflectionMethodController->returnsReference = false)879 ->and($reflectionMethodController->hasReturnType = false)880 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))881 ->and($reflectionClassController = new mock\controller())882 ->and($reflectionClassController->__construct = function() {})883 ->and($reflectionClassController->getName = function() use ($realClass) { return $realClass; })884 ->and($reflectionClassController->isFinal = false)885 ->and($reflectionClassController->isInterface = false)886 ->and($reflectionClassController->getMethods = array($reflectionMethod))887 ->and($reflectionClassController->getConstructor = null)888 ->and($reflectionClassController->isAbstract = false)889 ->and($reflectionClass = new \mock\reflectionClass(null))890 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))891 ->and($adapter = new atoum\test\adapter())892 ->and($adapter->class_exists = function($class) use ($realClass) { return ($class == '\\' . $realClass); })893 ->and($generator->setAdapter($adapter))894 ->and($generator->shunt('__construct'))895 ->and($generator->allIsInterface())896 ->then897 ->string($generator->getMockedClassCode($realClass))->isEqualTo(898 'namespace mock {' . PHP_EOL .899 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .900 '{' . PHP_EOL .901 $this->getMockControllerMethods() .902 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .903 "\t" . '{' . PHP_EOL .904 "\t\t" . 'if ($mockController === null)' . PHP_EOL .905 "\t\t" . '{' . PHP_EOL .906 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .907 "\t\t" . '}' . PHP_EOL .908 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .909 "\t\t" . '{' . PHP_EOL .910 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .911 "\t\t" . '}' . PHP_EOL .912 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .913 "\t\t" . '{' . PHP_EOL .914 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .915 "\t\t" . '}' . PHP_EOL .916 "\t" . '}' . PHP_EOL .917 "\t" . 'public function foo()' . PHP_EOL .918 "\t" . '{' . PHP_EOL .919 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .920 "\t\t" . 'if (isset($this->getMockController()->foo) === false)' . PHP_EOL .921 "\t\t" . '{' . PHP_EOL .922 "\t\t\t" . '$this->getMockController()->foo = function() {};' . PHP_EOL .923 "\t\t" . '}' . PHP_EOL .924 "\t\t" . '$return = $this->getMockController()->invoke(\'foo\', $arguments);' . PHP_EOL .925 "\t\t" . 'return $return;' . PHP_EOL .926 "\t" . '}' . PHP_EOL .927 "\t" . 'public static function getMockedMethods()' . PHP_EOL .928 "\t" . '{' . PHP_EOL .929 "\t\t" . 'return ' . var_export(array('__construct', 'foo'), true) . ';' . PHP_EOL .930 "\t" . '}' . PHP_EOL .931 '}' . PHP_EOL .932 '}'933 )934 ->if($generator->testedClassIs($realClass))935 ->then936 ->string($generator->getMockedClassCode($realClass))->isEqualTo(937 'namespace mock {' . PHP_EOL .938 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .939 '{' . PHP_EOL .940 $this->getMockControllerMethods() .941 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .942 "\t" . '{' . PHP_EOL .943 "\t\t" . 'if ($mockController === null)' . PHP_EOL .944 "\t\t" . '{' . PHP_EOL .945 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .946 "\t\t" . '}' . PHP_EOL .947 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .948 "\t\t" . '{' . PHP_EOL .949 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .950 "\t\t" . '}' . PHP_EOL .951 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .952 "\t\t" . '{' . PHP_EOL .953 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .954 "\t\t" . '}' . PHP_EOL .955 "\t" . '}' . PHP_EOL .956 "\t" . 'public function foo()' . PHP_EOL .957 "\t" . '{' . PHP_EOL .958 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .959 "\t\t" . 'if (isset($this->getMockController()->foo) === true)' . PHP_EOL .960 "\t\t" . '{' . PHP_EOL .961 "\t\t\t" . '$return = $this->getMockController()->invoke(\'foo\', $arguments);' . PHP_EOL .962 "\t\t\t" . 'return $return;' . PHP_EOL .963 "\t\t" . '}' . PHP_EOL .964 "\t\t" . 'else' . PHP_EOL .965 "\t\t" . '{' . PHP_EOL .966 "\t\t\t" . '$this->getMockController()->addCall(\'foo\', $arguments);' . PHP_EOL .967 "\t\t\t" . '$return = call_user_func_array(\'parent::foo\', $arguments);' . PHP_EOL .968 "\t\t\t" . 'return $return;' . PHP_EOL .969 "\t\t" . '}' . PHP_EOL .970 "\t" . '}' . PHP_EOL .971 "\t" . 'public static function getMockedMethods()' . PHP_EOL .972 "\t" . '{' . PHP_EOL .973 "\t\t" . 'return ' . var_export(array('__construct', 'foo'), true) . ';' . PHP_EOL .974 "\t" . '}' . PHP_EOL .975 '}' . PHP_EOL .976 '}'977 )978 ;979 }980 /** @php < 5.6 */981 public function testGetMockedClassCodeWithCloneMethod()982 {983 $this984 ->if($generator = new testedClass())985 ->and($realClass = uniqid())986 ->and($reflectionMethodController = new mock\controller())987 ->and($reflectionMethodController->__construct = function() {})988 ->and($reflectionMethodController->getName = 'clone')989 ->and($reflectionMethodController->isConstructor = false)990 ->and($reflectionMethodController->isAbstract = false)991 ->and($reflectionMethodController->getParameters = array())992 ->and($reflectionMethodController->isPublic = true)993 ->and($reflectionMethodController->isProtected = false)994 ->and($reflectionMethodController->isPrivate = false)995 ->and($reflectionMethodController->isFinal = false)996 ->and($reflectionMethodController->isStatic = false)997 ->and($reflectionMethodController->returnsReference = false)998 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))999 ->and($reflectionClassController = new mock\controller())1000 ->and($reflectionClassController->__construct = function() {})1001 ->and($reflectionClassController->getName = $realClass)1002 ->and($reflectionClassController->isFinal = false)1003 ->and($reflectionClassController->isInterface = false)1004 ->and($reflectionClassController->getMethods = array($reflectionMethod))1005 ->and($reflectionClassController->getConstructor = null)1006 ->and($reflectionClassController->isAbstract = false)1007 ->and($reflectionClass = new \mock\reflectionClass(null))1008 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))1009 ->and($adapter = new atoum\test\adapter())1010 ->and($adapter->class_exists = function($class) use ($realClass) { return ($class == '\\' . $realClass); })1011 ->and($generator->setAdapter($adapter))1012 ->then1013 ->string($generator->getMockedClassCode($realClass))->isEqualTo(1014 'namespace mock {' . PHP_EOL .1015 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .1016 '{' . PHP_EOL .1017 $this->getMockControllerMethods() .1018 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1019 "\t" . '{' . PHP_EOL .1020 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1021 "\t\t" . '{' . PHP_EOL .1022 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1023 "\t\t" . '}' . PHP_EOL .1024 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1025 "\t\t" . '{' . PHP_EOL .1026 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1027 "\t\t" . '}' . PHP_EOL .1028 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .1029 "\t\t" . '{' . PHP_EOL .1030 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .1031 "\t\t" . '}' . PHP_EOL .1032 "\t" . '}' . PHP_EOL .1033 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1034 "\t" . '{' . PHP_EOL .1035 "\t\t" . 'return ' . var_export(array('__construct'), true) . ';' . PHP_EOL .1036 "\t" . '}' . PHP_EOL .1037 '}' . PHP_EOL .1038 '}'1039 )1040 ;1041 }1042 public function testGetMockedClassCodeWithShuntedDeprecatedConstructor()1043 {1044 $this1045 ->if($generator = new testedClass())1046 ->and($reflectionMethodController = new mock\controller())1047 ->and($reflectionMethodController->__construct = function() {})1048 ->and($reflectionMethodController->getName = $realClass = uniqid())1049 ->and($reflectionMethodController->isConstructor = true)1050 ->and($reflectionMethodController->isAbstract = false)1051 ->and($reflectionMethodController->getParameters = array())1052 ->and($reflectionMethodController->isPublic = true)1053 ->and($reflectionMethodController->isProtected = false)1054 ->and($reflectionMethodController->isPrivate = false)1055 ->and($reflectionMethodController->isFinal = false)1056 ->and($reflectionMethodController->isStatic = false)1057 ->and($reflectionMethodController->returnsReference = false)1058 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))1059 ->and($reflectionClassController = new mock\controller())1060 ->and($reflectionClassController->__construct = function() {})1061 ->and($reflectionClassController->getName = $realClass)1062 ->and($reflectionClassController->isFinal = false)1063 ->and($reflectionClassController->isInterface = false)1064 ->and($reflectionClassController->getMethods = array($reflectionMethod))1065 ->and($reflectionClassController->getConstructor = $reflectionMethod)1066 ->and($reflectionClassController->isAbstract = false)1067 ->and($reflectionClass = new \mock\reflectionClass(null))1068 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))1069 ->and($adapter = new atoum\test\adapter())1070 ->and($adapter->class_exists = function($class) use ($realClass) { return ($class == '\\' . $realClass); })1071 ->and($generator->setAdapter($adapter))1072 ->and($generator->shunt($realClass))1073 ->then1074 ->string($generator->getMockedClassCode($realClass))->isEqualTo(1075 'namespace mock {' . PHP_EOL .1076 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .1077 '{' . PHP_EOL .1078 $this->getMockControllerMethods() .1079 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1080 "\t" . '{' . PHP_EOL .1081 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .1082 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1083 "\t\t" . '{' . PHP_EOL .1084 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1085 "\t\t" . '}' . PHP_EOL .1086 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1087 "\t\t" . '{' . PHP_EOL .1088 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1089 "\t\t" . '}' . PHP_EOL .1090 "\t\t" . 'if (isset($this->getMockController()->' . $realClass . ') === false)' . PHP_EOL .1091 "\t\t" . '{' . PHP_EOL .1092 "\t\t\t" . '$this->getMockController()->' . $realClass . ' = function() {};' . PHP_EOL .1093 "\t\t" . '}' . PHP_EOL .1094 "\t\t" . '$this->getMockController()->invoke(\'' . $realClass . '\', $arguments);' . PHP_EOL .1095 "\t" . '}' . PHP_EOL .1096 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1097 "\t" . '{' . PHP_EOL .1098 "\t\t" . 'return ' . var_export(array($realClass), true) . ';' . PHP_EOL .1099 "\t" . '}' . PHP_EOL .1100 '}' . PHP_EOL .1101 '}'1102 )1103 ;1104 }1105 /** @php < 7.0 */1106 public function testGetMockedClassCodeForInterface()1107 {1108 $this1109 ->if($generator = new testedClass())1110 ->and($reflectionMethodController = new mock\controller())1111 ->and($reflectionMethodController->__construct = function() {})1112 ->and($reflectionMethodController->getName = '__construct')1113 ->and($reflectionMethodController->isConstructor = true)1114 ->and($reflectionMethodController->getParameters = array())1115 ->and($reflectionMethodController->isFinal = false)1116 ->and($reflectionMethodController->isStatic = false)1117 ->and($reflectionMethodController->returnsReference = false)1118 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))1119 ->and($reflectionClassController = new mock\controller())1120 ->and($reflectionClassController->__construct = function() {})1121 ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })1122 ->and($reflectionClassController->isFinal = false)1123 ->and($reflectionClassController->isInterface = true)1124 ->and($reflectionClassController->getMethods = array($reflectionMethod))1125 ->and($reflectionClassController->isInstantiable = false)1126 ->and($reflectionClassController->implementsInterface = false)1127 ->and($reflectionClass = new \mock\reflectionClass(null))1128 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))1129 ->and($adapter = new atoum\test\adapter())1130 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })1131 ->and($generator->setAdapter($adapter))1132 ->then1133 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(1134 'namespace mock {' . PHP_EOL .1135 'final class ' . $realClass . ' implements \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .1136 '{' . PHP_EOL .1137 $this->getMockControllerMethods() .1138 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1139 "\t" . '{' . PHP_EOL .1140 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .1141 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1142 "\t\t" . '{' . PHP_EOL .1143 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1144 "\t\t" . '}' . PHP_EOL .1145 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1146 "\t\t" . '{' . PHP_EOL .1147 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1148 "\t\t" . '}' . PHP_EOL .1149 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .1150 "\t\t" . '{' . PHP_EOL .1151 "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .1152 "\t\t" . '}' . PHP_EOL .1153 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .1154 "\t" . '}' . PHP_EOL .1155 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .1156 "\t" . '{' . PHP_EOL .1157 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .1158 "\t\t" . '{' . PHP_EOL .1159 "\t\t\t" . '$return = $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .1160 "\t\t\t" . 'return $return;' . PHP_EOL .1161 "\t\t" . '}' . PHP_EOL .1162 "\t\t" . 'else' . PHP_EOL .1163 "\t\t" . '{' . PHP_EOL .1164 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .1165 "\t\t" . '}' . PHP_EOL .1166 "\t" . '}' . PHP_EOL .1167 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1168 "\t" . '{' . PHP_EOL .1169 "\t\t" . 'return ' . var_export(array('__construct', '__call'), true) . ';' . PHP_EOL .1170 "\t" . '}' . PHP_EOL .1171 '}' . PHP_EOL .1172 '}'1173 )1174 ->if($reflectionClassController->implementsInterface = function($interface) { return ($interface == 'traversable' ? true : false); })1175 ->and($generator->setReflectionClassFactory(function($class) use ($reflectionClass) { return ($class == 'iteratorAggregate' ? new \reflectionClass('iteratorAggregate') : $reflectionClass); }))1176 ->then1177 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(1178 'namespace mock {' . PHP_EOL .1179 'final class ' . $realClass . ' implements \\iteratorAggregate, \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .1180 '{' . PHP_EOL .1181 $this->getMockControllerMethods() .1182 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1183 "\t" . '{' . PHP_EOL .1184 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .1185 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1186 "\t\t" . '{' . PHP_EOL .1187 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1188 "\t\t" . '}' . PHP_EOL .1189 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1190 "\t\t" . '{' . PHP_EOL .1191 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1192 "\t\t" . '}' . PHP_EOL .1193 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .1194 "\t\t" . '{' . PHP_EOL .1195 "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .1196 "\t\t" . '}' . PHP_EOL .1197 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .1198 "\t" . '}' . PHP_EOL .1199 "\t" . 'public function getIterator()' . PHP_EOL .1200 "\t" . '{' . PHP_EOL .1201 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .1202 "\t\t" . 'if (isset($this->getMockController()->getIterator) === false)' . PHP_EOL .1203 "\t\t" . '{' . PHP_EOL .1204 "\t\t\t" . '$this->getMockController()->getIterator = function() {};' . PHP_EOL .1205 "\t\t" . '}' . PHP_EOL .1206 "\t\t" . '$return = $this->getMockController()->invoke(\'getIterator\', $arguments);' . PHP_EOL .1207 "\t\t" . 'return $return;' . PHP_EOL .1208 "\t" . '}' . PHP_EOL .1209 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .1210 "\t" . '{' . PHP_EOL .1211 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .1212 "\t\t" . '{' . PHP_EOL .1213 "\t\t\t" . '$return = $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .1214 "\t\t\t" . 'return $return;' . PHP_EOL .1215 "\t\t" . '}' . PHP_EOL .1216 "\t\t" . 'else' . PHP_EOL .1217 "\t\t" . '{' . PHP_EOL .1218 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .1219 "\t\t" . '}' . PHP_EOL .1220 "\t" . '}' . PHP_EOL .1221 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1222 "\t" . '{' . PHP_EOL .1223 "\t\t" . 'return ' . var_export(array('__construct', 'getiterator', '__call'), true) . ';' . PHP_EOL .1224 "\t" . '}' . PHP_EOL .1225 '}' . PHP_EOL .1226 '}'1227 )1228 ->if($generator = new testedClass())1229 ->and($reflectionMethodController = new mock\controller())1230 ->and($reflectionMethodController->__construct = function() {})1231 ->and($reflectionMethodController->getName = '__construct')1232 ->and($reflectionMethodController->isConstructor = true)1233 ->and($reflectionMethodController->getParameters = array())1234 ->and($reflectionMethodController->isFinal = false)1235 ->and($reflectionMethodController->isStatic = false)1236 ->and($reflectionMethodController->returnsReference = false)1237 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))1238 ->and($reflectionClassController = new mock\controller())1239 ->and($reflectionClassController->__construct = function() {})1240 ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })1241 ->and($reflectionClassController->isFinal = false)1242 ->and($reflectionClassController->isInterface = true)1243 ->and($reflectionClassController->getMethods = array($reflectionMethod))1244 ->and($reflectionClassController->isInstantiable = false)1245 ->and($reflectionClassController->implementsInterface = false)1246 ->and($reflectionClass = new \mock\reflectionClass(null))1247 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))1248 ->and($adapter = new atoum\test\adapter())1249 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })1250 ->and($generator->setAdapter($adapter))1251 ->and($generator->disallowUndefinedMethodUsage())1252 ->then1253 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(1254 'namespace mock {' . PHP_EOL .1255 'final class ' . $realClass . ' implements \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .1256 '{' . PHP_EOL .1257 $this->getMockControllerMethods() .1258 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1259 "\t" . '{' . PHP_EOL .1260 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .1261 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1262 "\t\t" . '{' . PHP_EOL .1263 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1264 "\t\t" . '}' . PHP_EOL .1265 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1266 "\t\t" . '{' . PHP_EOL .1267 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1268 "\t\t" . '}' . PHP_EOL .1269 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .1270 "\t\t" . '{' . PHP_EOL .1271 "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .1272 "\t\t" . '}' . PHP_EOL .1273 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .1274 "\t" . '}' . PHP_EOL .1275 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1276 "\t" . '{' . PHP_EOL .1277 "\t\t" . 'return ' . var_export(array('__construct'), true) . ';' . PHP_EOL .1278 "\t" . '}' . PHP_EOL .1279 '}' . PHP_EOL .1280 '}'1281 )1282 ;1283 }1284 /** @php >= 7.0 */1285 public function testGetMockedClassCodeForInterfacePhp7()1286 {1287 $this1288 ->if($generator = new testedClass())1289 ->and($reflectionMethodController = new mock\controller())1290 ->and($reflectionMethodController->__construct = function() {})1291 ->and($reflectionMethodController->getName = '__construct')1292 ->and($reflectionMethodController->isConstructor = true)1293 ->and($reflectionMethodController->getParameters = array())1294 ->and($reflectionMethodController->isFinal = false)1295 ->and($reflectionMethodController->isStatic = false)1296 ->and($reflectionMethodController->returnsReference = false)1297 ->and($reflectionMethodController->hasReturnType = false)1298 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))1299 ->and($reflectionClassController = new mock\controller())1300 ->and($reflectionClassController->__construct = function() {})1301 ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })1302 ->and($reflectionClassController->isFinal = false)1303 ->and($reflectionClassController->isInterface = true)1304 ->and($reflectionClassController->getMethods = array($reflectionMethod))1305 ->and($reflectionClassController->isInstantiable = false)1306 ->and($reflectionClassController->implementsInterface = false)1307 ->and($reflectionClass = new \mock\reflectionClass(null))1308 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))1309 ->and($adapter = new atoum\test\adapter())1310 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })1311 ->and($generator->setAdapter($adapter))1312 ->then1313 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(1314 'namespace mock {' . PHP_EOL .1315 'final class ' . $realClass . ' implements \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .1316 '{' . PHP_EOL .1317 $this->getMockControllerMethods() .1318 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1319 "\t" . '{' . PHP_EOL .1320 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .1321 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1322 "\t\t" . '{' . PHP_EOL .1323 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1324 "\t\t" . '}' . PHP_EOL .1325 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1326 "\t\t" . '{' . PHP_EOL .1327 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1328 "\t\t" . '}' . PHP_EOL .1329 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .1330 "\t\t" . '{' . PHP_EOL .1331 "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .1332 "\t\t" . '}' . PHP_EOL .1333 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .1334 "\t" . '}' . PHP_EOL .1335 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .1336 "\t" . '{' . PHP_EOL .1337 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .1338 "\t\t" . '{' . PHP_EOL .1339 "\t\t\t" . '$return = $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .1340 "\t\t\t" . 'return $return;' . PHP_EOL .1341 "\t\t" . '}' . PHP_EOL .1342 "\t\t" . 'else' . PHP_EOL .1343 "\t\t" . '{' . PHP_EOL .1344 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .1345 "\t\t" . '}' . PHP_EOL .1346 "\t" . '}' . PHP_EOL .1347 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1348 "\t" . '{' . PHP_EOL .1349 "\t\t" . 'return ' . var_export(array('__construct', '__call'), true) . ';' . PHP_EOL .1350 "\t" . '}' . PHP_EOL .1351 '}' . PHP_EOL .1352 '}'1353 )1354 ->if($reflectionClassController->implementsInterface = function($interface) { return ($interface == 'traversable' ? true : false); })1355 ->and($generator->setReflectionClassFactory(function($class) use ($reflectionClass) { return ($class == 'iteratorAggregate' ? new \reflectionClass('iteratorAggregate') : $reflectionClass); }))1356 ->then1357 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(1358 'namespace mock {' . PHP_EOL .1359 'final class ' . $realClass . ' implements \\iteratorAggregate, \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .1360 '{' . PHP_EOL .1361 $this->getMockControllerMethods() .1362 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1363 "\t" . '{' . PHP_EOL .1364 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .1365 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1366 "\t\t" . '{' . PHP_EOL .1367 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1368 "\t\t" . '}' . PHP_EOL .1369 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1370 "\t\t" . '{' . PHP_EOL .1371 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1372 "\t\t" . '}' . PHP_EOL .1373 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .1374 "\t\t" . '{' . PHP_EOL .1375 "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .1376 "\t\t" . '}' . PHP_EOL .1377 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .1378 "\t" . '}' . PHP_EOL .1379 "\t" . 'public function getIterator()' . PHP_EOL .1380 "\t" . '{' . PHP_EOL .1381 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .1382 "\t\t" . 'if (isset($this->getMockController()->getIterator) === false)' . PHP_EOL .1383 "\t\t" . '{' . PHP_EOL .1384 "\t\t\t" . '$this->getMockController()->getIterator = function() {};' . PHP_EOL .1385 "\t\t" . '}' . PHP_EOL .1386 "\t\t" . '$return = $this->getMockController()->invoke(\'getIterator\', $arguments);' . PHP_EOL .1387 "\t\t" . 'return $return;' . PHP_EOL .1388 "\t" . '}' . PHP_EOL .1389 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .1390 "\t" . '{' . PHP_EOL .1391 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .1392 "\t\t" . '{' . PHP_EOL .1393 "\t\t\t" . '$return = $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .1394 "\t\t\t" . 'return $return;' . PHP_EOL .1395 "\t\t" . '}' . PHP_EOL .1396 "\t\t" . 'else' . PHP_EOL .1397 "\t\t" . '{' . PHP_EOL .1398 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .1399 "\t\t" . '}' . PHP_EOL .1400 "\t" . '}' . PHP_EOL .1401 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1402 "\t" . '{' . PHP_EOL .1403 "\t\t" . 'return ' . var_export(array('__construct', 'getiterator', '__call'), true) . ';' . PHP_EOL .1404 "\t" . '}' . PHP_EOL .1405 '}' . PHP_EOL .1406 '}'1407 )1408 ->if($generator = new testedClass())1409 ->and($reflectionMethodController = new mock\controller())1410 ->and($reflectionMethodController->__construct = function() {})1411 ->and($reflectionMethodController->getName = '__construct')1412 ->and($reflectionMethodController->isConstructor = true)1413 ->and($reflectionMethodController->getParameters = array())1414 ->and($reflectionMethodController->isFinal = false)1415 ->and($reflectionMethodController->isStatic = false)1416 ->and($reflectionMethodController->returnsReference = false)1417 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))1418 ->and($reflectionClassController = new mock\controller())1419 ->and($reflectionClassController->__construct = function() {})1420 ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })1421 ->and($reflectionClassController->isFinal = false)1422 ->and($reflectionClassController->isInterface = true)1423 ->and($reflectionClassController->getMethods = array($reflectionMethod))1424 ->and($reflectionClassController->isInstantiable = false)1425 ->and($reflectionClassController->implementsInterface = false)1426 ->and($reflectionClass = new \mock\reflectionClass(null))1427 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))1428 ->and($adapter = new atoum\test\adapter())1429 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })1430 ->and($generator->setAdapter($adapter))1431 ->and($generator->disallowUndefinedMethodUsage())1432 ->then1433 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(1434 'namespace mock {' . PHP_EOL .1435 'final class ' . $realClass . ' implements \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .1436 '{' . PHP_EOL .1437 $this->getMockControllerMethods() .1438 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1439 "\t" . '{' . PHP_EOL .1440 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .1441 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1442 "\t\t" . '{' . PHP_EOL .1443 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1444 "\t\t" . '}' . PHP_EOL .1445 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1446 "\t\t" . '{' . PHP_EOL .1447 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1448 "\t\t" . '}' . PHP_EOL .1449 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .1450 "\t\t" . '{' . PHP_EOL .1451 "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .1452 "\t\t" . '}' . PHP_EOL .1453 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .1454 "\t" . '}' . PHP_EOL .1455 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1456 "\t" . '{' . PHP_EOL .1457 "\t\t" . 'return ' . var_export(array('__construct'), true) . ';' . PHP_EOL .1458 "\t" . '}' . PHP_EOL .1459 '}' . PHP_EOL .1460 '}'1461 )1462 ;1463 }1464 /** @php < 5.6 */1465 public function testGetMockedClassCodeForInterfaceWithConstructorArguments()1466 {1467 $this1468 ->if($generator = new testedClass())1469 ->and($reflectionParameterController = new mock\controller())1470 ->and($reflectionParameterController->__construct = function() {})1471 ->and($reflectionParameterController->isArray = true)1472 ->and($reflectionParameterController->getName = 'param')1473 ->and($reflectionParameterController->isPassedByReference = false)1474 ->and($reflectionParameterController->isDefaultValueAvailable = false)1475 ->and($reflectionParameterController->isOptional = false)1476 ->and($reflectionParameter = new \mock\reflectionParameter(null, null))1477 ->and($reflectionMethodController = new mock\controller())1478 ->and($reflectionMethodController->__construct = function() {})1479 ->and($reflectionMethodController->getName = '__construct')1480 ->and($reflectionMethodController->isConstructor = true)1481 ->and($reflectionMethodController->getParameters = array($reflectionParameter))1482 ->and($reflectionMethodController->isFinal = false)1483 ->and($reflectionMethodController->isStatic = false)1484 ->and($reflectionMethodController->returnsReference = false)1485 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))1486 ->and($reflectionClassController = new mock\controller())1487 ->and($reflectionClassController->__construct = function() {})1488 ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })1489 ->and($reflectionClassController->isFinal = false)1490 ->and($reflectionClassController->isInterface = true)1491 ->and($reflectionClassController->getMethods = array($reflectionMethod))1492 ->and($reflectionClassController->isInstantiable = false)1493 ->and($reflectionClassController->implementsInterface = false)1494 ->and($reflectionClass = new \mock\reflectionClass(null))1495 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))1496 ->and($adapter = new atoum\test\adapter())1497 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })1498 ->and($generator->setAdapter($adapter))1499 ->then1500 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(1501 'namespace mock {' . PHP_EOL .1502 'final class ' . $realClass . ' implements \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .1503 '{' . PHP_EOL .1504 $this->getMockControllerMethods() .1505 "\t" . 'public function __construct(array $param, \mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1506 "\t" . '{' . PHP_EOL .1507 "\t\t" . '$arguments = array_merge(array($param), array_slice(func_get_args(), 1, -1));' . PHP_EOL .1508 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1509 "\t\t" . '{' . PHP_EOL .1510 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1511 "\t\t" . '}' . PHP_EOL .1512 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1513 "\t\t" . '{' . PHP_EOL .1514 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1515 "\t\t" . '}' . PHP_EOL .1516 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .1517 "\t\t" . '{' . PHP_EOL .1518 "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .1519 "\t\t" . '}' . PHP_EOL .1520 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .1521 "\t" . '}' . PHP_EOL .1522 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .1523 "\t" . '{' . PHP_EOL .1524 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .1525 "\t\t" . '{' . PHP_EOL .1526 "\t\t\t" . '$return = $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .1527 "\t\t\t" . 'return $return;' . PHP_EOL .1528 "\t\t" . '}' . PHP_EOL .1529 "\t\t" . 'else' . PHP_EOL .1530 "\t\t" . '{' . PHP_EOL .1531 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .1532 "\t\t" . '}' . PHP_EOL .1533 "\t" . '}' . PHP_EOL .1534 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1535 "\t" . '{' . PHP_EOL .1536 "\t\t" . 'return ' . var_export(array('__construct', '__call'), true) . ';' . PHP_EOL .1537 "\t" . '}' . PHP_EOL .1538 '}' . PHP_EOL .1539 '}'1540 )1541 ;1542 }1543 /**1544 * @php >= 5.61545 * @php < 7.01546 */1547 public function testGetMockedClassCodeForInterfaceWithConstructorArgumentsPhp56()1548 {1549 $this1550 ->if($generator = new testedClass())1551 ->and($reflectionParameterController = new mock\controller())1552 ->and($reflectionParameterController->__construct = function() {})1553 ->and($reflectionParameterController->isArray = true)1554 ->and($reflectionParameterController->getName = 'param')1555 ->and($reflectionParameterController->isPassedByReference = false)1556 ->and($reflectionParameterController->isDefaultValueAvailable = false)1557 ->and($reflectionParameterController->isOptional = false)1558 ->and($reflectionParameterController->isVariadic = false)1559 ->and($reflectionParameter = new \mock\reflectionParameter(null, null))1560 ->and($reflectionMethodController = new mock\controller())1561 ->and($reflectionMethodController->__construct = function() {})1562 ->and($reflectionMethodController->getName = '__construct')1563 ->and($reflectionMethodController->isConstructor = true)1564 ->and($reflectionMethodController->getParameters = array($reflectionParameter))1565 ->and($reflectionMethodController->isFinal = false)1566 ->and($reflectionMethodController->isStatic = false)1567 ->and($reflectionMethodController->returnsReference = false)1568 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))1569 ->and($reflectionClassController = new mock\controller())1570 ->and($reflectionClassController->__construct = function() {})1571 ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })1572 ->and($reflectionClassController->isFinal = false)1573 ->and($reflectionClassController->isInterface = true)1574 ->and($reflectionClassController->getMethods = array($reflectionMethod))1575 ->and($reflectionClassController->isInstantiable = false)1576 ->and($reflectionClassController->implementsInterface = false)1577 ->and($reflectionClass = new \mock\reflectionClass(null))1578 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))1579 ->and($adapter = new atoum\test\adapter())1580 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })1581 ->and($generator->setAdapter($adapter))1582 ->then1583 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(1584 'namespace mock {' . PHP_EOL .1585 'final class ' . $realClass . ' implements \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .1586 '{' . PHP_EOL .1587 $this->getMockControllerMethods() .1588 "\t" . 'public function __construct(array $param, \mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1589 "\t" . '{' . PHP_EOL .1590 "\t\t" . '$arguments = array_merge(array($param), array_slice(func_get_args(), 1, -1));' . PHP_EOL .1591 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1592 "\t\t" . '{' . PHP_EOL .1593 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1594 "\t\t" . '}' . PHP_EOL .1595 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1596 "\t\t" . '{' . PHP_EOL .1597 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1598 "\t\t" . '}' . PHP_EOL .1599 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .1600 "\t\t" . '{' . PHP_EOL .1601 "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .1602 "\t\t" . '}' . PHP_EOL .1603 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .1604 "\t" . '}' . PHP_EOL .1605 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .1606 "\t" . '{' . PHP_EOL .1607 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .1608 "\t\t" . '{' . PHP_EOL .1609 "\t\t\t" . '$return = $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .1610 "\t\t\t" . 'return $return;' . PHP_EOL .1611 "\t\t" . '}' . PHP_EOL .1612 "\t\t" . 'else' . PHP_EOL .1613 "\t\t" . '{' . PHP_EOL .1614 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .1615 "\t\t" . '}' . PHP_EOL .1616 "\t" . '}' . PHP_EOL .1617 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1618 "\t" . '{' . PHP_EOL .1619 "\t\t" . 'return ' . var_export(array('__construct', '__call'), true) . ';' . PHP_EOL .1620 "\t" . '}' . PHP_EOL .1621 '}' . PHP_EOL .1622 '}'1623 )1624 ;1625 }1626 public function testGetMockedClassCodeForInterfaceWithStaticMethod()1627 {1628 $this1629 ->if($generator = new testedClass())1630 ->and($reflectionMethodController = new mock\controller())1631 ->and($reflectionMethodController->__construct = function() {})1632 ->and($reflectionMethodController->getName = $methodName = uniqid())1633 ->and($reflectionMethodController->isConstructor = false)1634 ->and($reflectionMethodController->getParameters = array())1635 ->and($reflectionMethodController->isFinal = false)1636 ->and($reflectionMethodController->isStatic = true)1637 ->and($reflectionMethodController->returnsReference = false)1638 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))1639 ->and($reflectionClassController = new mock\controller())1640 ->and($reflectionClassController->__construct = function() {})1641 ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })1642 ->and($reflectionClassController->isFinal = false)1643 ->and($reflectionClassController->isInterface = true)1644 ->and($reflectionClassController->getMethods = array($reflectionMethod))1645 ->and($reflectionClassController->isInstantiable = false)1646 ->and($reflectionClassController->implementsInterface = false)1647 ->and($reflectionClass = new \mock\reflectionClass(null))1648 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))1649 ->and($adapter = new atoum\test\adapter())1650 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })1651 ->and($generator->setAdapter($adapter))1652 ->then1653 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(1654 'namespace mock {' . PHP_EOL .1655 'final class ' . $realClass . ' implements \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .1656 '{' . PHP_EOL .1657 $this->getMockControllerMethods() .1658 "\t" . 'public static function ' . $methodName . '()' . PHP_EOL .1659 "\t" . '{' . PHP_EOL .1660 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .1661 "\t\t" . 'return call_user_func_array(array(\'parent\', \'' . $methodName . '\'), $arguments);' . PHP_EOL .1662 "\t" . '}' . PHP_EOL .1663 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1664 "\t" . '{' . PHP_EOL .1665 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1666 "\t\t" . '{' . PHP_EOL .1667 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1668 "\t\t" . '}' . PHP_EOL .1669 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1670 "\t\t" . '{' . PHP_EOL .1671 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1672 "\t\t" . '}' . PHP_EOL .1673 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .1674 "\t\t" . '{' . PHP_EOL .1675 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .1676 "\t\t" . '}' . PHP_EOL .1677 "\t" . '}' . PHP_EOL .1678 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .1679 "\t" . '{' . PHP_EOL .1680 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .1681 "\t\t" . '{' . PHP_EOL .1682 "\t\t\t" . '$return = $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .1683 "\t\t\t" . 'return $return;' . PHP_EOL .1684 "\t\t" . '}' . PHP_EOL .1685 "\t\t" . 'else' . PHP_EOL .1686 "\t\t" . '{' . PHP_EOL .1687 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .1688 "\t\t" . '}' . PHP_EOL .1689 "\t" . '}' . PHP_EOL .1690 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1691 "\t" . '{' . PHP_EOL .1692 "\t\t" . 'return ' . var_export(array($methodName, '__construct', '__call'), true) . ';' . PHP_EOL .1693 "\t" . '}' . PHP_EOL .1694 '}' . PHP_EOL .1695 '}'1696 )1697 ->if($reflectionClassController->implementsInterface = function($interface) { return ($interface == 'traversable' ? true : false); })1698 ->and($generator->setReflectionClassFactory(function($class) use ($reflectionClass) { return ($class == 'iteratorAggregate' ? new \reflectionClass('iteratorAggregate') : $reflectionClass); }))1699 ->then1700 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(1701 'namespace mock {' . PHP_EOL .1702 'final class ' . $realClass . ' implements \\iteratorAggregate, \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .1703 '{' . PHP_EOL .1704 $this->getMockControllerMethods() .1705 "\t" . 'public static function ' . $methodName . '()' . PHP_EOL .1706 "\t" . '{' . PHP_EOL .1707 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .1708 "\t\t" . 'return call_user_func_array(array(\'parent\', \'' . $methodName . '\'), $arguments);' . PHP_EOL .1709 "\t" . '}' . PHP_EOL .1710 "\t" . 'public function getIterator()' . PHP_EOL .1711 "\t" . '{' . PHP_EOL .1712 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .1713 "\t\t" . 'if (isset($this->getMockController()->getIterator) === false)' . PHP_EOL .1714 "\t\t" . '{' . PHP_EOL .1715 "\t\t\t" . '$this->getMockController()->getIterator = function() {};' . PHP_EOL .1716 "\t\t" . '}' . PHP_EOL .1717 "\t\t" . '$return = $this->getMockController()->invoke(\'getIterator\', $arguments);' . PHP_EOL .1718 "\t\t" . 'return $return;' . PHP_EOL .1719 "\t" . '}' . PHP_EOL .1720 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1721 "\t" . '{' . PHP_EOL .1722 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1723 "\t\t" . '{' . PHP_EOL .1724 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1725 "\t\t" . '}' . PHP_EOL .1726 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1727 "\t\t" . '{' . PHP_EOL .1728 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1729 "\t\t" . '}' . PHP_EOL .1730 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .1731 "\t\t" . '{' . PHP_EOL .1732 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .1733 "\t\t" . '}' . PHP_EOL .1734 "\t" . '}' . PHP_EOL .1735 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .1736 "\t" . '{' . PHP_EOL .1737 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .1738 "\t\t" . '{' . PHP_EOL .1739 "\t\t\t" . '$return = $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .1740 "\t\t\t" . 'return $return;' . PHP_EOL .1741 "\t\t" . '}' . PHP_EOL .1742 "\t\t" . 'else' . PHP_EOL .1743 "\t\t" . '{' . PHP_EOL .1744 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .1745 "\t\t" . '}' . PHP_EOL .1746 "\t" . '}' . PHP_EOL .1747 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1748 "\t" . '{' . PHP_EOL .1749 "\t\t" . 'return ' . var_export(array($methodName, 'getiterator', '__construct', '__call'), true) . ';' . PHP_EOL .1750 "\t" . '}' . PHP_EOL .1751 '}' . PHP_EOL .1752 '}'1753 )1754 ;1755 }1756 /** @php >= 7.0 */1757 public function testGetMockedClassCodeForInterfaceWithTypeHint()1758 {1759 $this1760 ->if($generator = new testedClass())1761 ->and($reflectionParameterController = new mock\controller())1762 ->and($reflectionParameterController->__construct = function() {})1763 ->and($reflectionParameterController->isArray = false)1764 ->and($reflectionParameterController->isCallable = false)1765 ->and($reflectionParameterController->getName = 'typeHint')1766 ->and($reflectionParameterController->isPassedByReference = false)1767 ->and($reflectionParameterController->isDefaultValueAvailable = false)1768 ->and($reflectionParameterController->isOptional = false)1769 ->and($reflectionParameterController->isVariadic = false)1770 ->and($reflectionParameterController->getClass = null)1771 ->and($reflectionParameterController->hasType = true)1772 ->and($reflectionParameterController->getType = 'string')1773 ->and($reflectionParameter = new \mock\reflectionParameter(null, null))1774 ->and($reflectionMethodController = new mock\controller())1775 ->and($reflectionMethodController->__construct = function() {})1776 ->and($reflectionMethodController->getName = $methodName = uniqid())1777 ->and($reflectionMethodController->isConstructor = false)1778 ->and($reflectionMethodController->getParameters = array($reflectionParameter))1779 ->and($reflectionMethodController->isPublic = true)1780 ->and($reflectionMethodController->isProtected = false)1781 ->and($reflectionMethodController->isPrivate = false)1782 ->and($reflectionMethodController->isFinal = false)1783 ->and($reflectionMethodController->isStatic = false)1784 ->and($reflectionMethodController->isAbstract = false)1785 ->and($reflectionMethodController->returnsReference = false)1786 ->and($reflectionMethodController->hasReturnType = false)1787 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))1788 ->and($reflectionClassController = new mock\controller())1789 ->and($reflectionClassController->__construct = function() {})1790 ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })1791 ->and($reflectionClassController->isFinal = false)1792 ->and($reflectionClassController->isInterface = false)1793 ->and($reflectionClassController->getMethods = array($reflectionMethod))1794 ->and($reflectionClassController->getConstructor = null)1795 ->and($reflectionClassController->isAbstract = false)1796 ->and($reflectionClass = new \mock\reflectionClass(null))1797 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))1798 ->and($adapter = new atoum\test\adapter())1799 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })1800 ->and($generator->setAdapter($adapter))1801 ->then1802 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(1803 'namespace mock {' . PHP_EOL .1804 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .1805 '{' . PHP_EOL .1806 $this->getMockControllerMethods() .1807 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1808 "\t" . '{' . PHP_EOL .1809 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1810 "\t\t" . '{' . PHP_EOL .1811 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1812 "\t\t" . '}' . PHP_EOL .1813 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1814 "\t\t" . '{' . PHP_EOL .1815 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1816 "\t\t" . '}' . PHP_EOL .1817 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .1818 "\t\t" . '{' . PHP_EOL .1819 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .1820 "\t\t" . '}' . PHP_EOL .1821 "\t" . '}' . PHP_EOL .1822 "\t" . 'public function ' . $methodName . '(string $typeHint)' . PHP_EOL .1823 "\t" . '{' . PHP_EOL .1824 "\t\t" . '$arguments = array_merge(array($typeHint), array_slice(func_get_args(), 1));' . PHP_EOL .1825 "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL .1826 "\t\t" . '{' . PHP_EOL .1827 "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL .1828 "\t\t\t" . 'return $return;' . PHP_EOL .1829 "\t\t" . '}' . PHP_EOL .1830 "\t\t" . 'else' . PHP_EOL .1831 "\t\t" . '{' . PHP_EOL .1832 "\t\t\t" . '$this->getMockController()->addCall(\'' . $methodName . '\', $arguments);' . PHP_EOL .1833 "\t\t\t" . '$return = call_user_func_array(\'parent::' . $methodName . '\', $arguments);' . PHP_EOL .1834 "\t\t\t" . 'return $return;' . PHP_EOL .1835 "\t\t" . '}' . PHP_EOL .1836 "\t" . '}' . PHP_EOL .1837 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1838 "\t" . '{' . PHP_EOL .1839 "\t\t" . 'return ' . var_export(array('__construct', $methodName), true) . ';' . PHP_EOL .1840 "\t" . '}' . PHP_EOL .1841 '}' . PHP_EOL .1842 '}'1843 )1844 ;1845 }1846 /** @php >= 7.0 */1847 public function testGetMockedClassCodeForInterfaceWithReturnType()1848 {1849 $this1850 ->if($generator = new testedClass())1851 ->and($reflectionTypeController = new mock\controller())1852 ->and($reflectionTypeController->__construct = function() {})1853 ->and($reflectionTypeController->isBuiltin = true)1854 ->and($reflectionTypeController->__toString = $returnType = 'string')1855 ->and($reflectionType = new \mock\reflectionType())1856 ->and($reflectionMethodController = new mock\controller())1857 ->and($reflectionMethodController->__construct = function() {})1858 ->and($reflectionMethodController->getName = $methodName = uniqid())1859 ->and($reflectionMethodController->isConstructor = false)1860 ->and($reflectionMethodController->getParameters = array())1861 ->and($reflectionMethodController->isPublic = true)1862 ->and($reflectionMethodController->isProtected = false)1863 ->and($reflectionMethodController->isPrivate = false)1864 ->and($reflectionMethodController->isFinal = false)1865 ->and($reflectionMethodController->isStatic = false)1866 ->and($reflectionMethodController->isAbstract = false)1867 ->and($reflectionMethodController->returnsReference = false)1868 ->and($reflectionMethodController->hasReturnType = true)1869 ->and($reflectionMethodController->getReturnType = $reflectionType)1870 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))1871 ->and($reflectionClassController = new mock\controller())1872 ->and($reflectionClassController->__construct = function() {})1873 ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })1874 ->and($reflectionClassController->isFinal = false)1875 ->and($reflectionClassController->isInterface = false)1876 ->and($reflectionClassController->getMethods = array($reflectionMethod))1877 ->and($reflectionClassController->getConstructor = null)1878 ->and($reflectionClassController->isAbstract = false)1879 ->and($reflectionClass = new \mock\reflectionClass(null))1880 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))1881 ->and($adapter = new atoum\test\adapter())1882 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })1883 ->and($generator->setAdapter($adapter))1884 ->then1885 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(1886 'namespace mock {' . PHP_EOL .1887 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .1888 '{' . PHP_EOL .1889 $this->getMockControllerMethods() .1890 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1891 "\t" . '{' . PHP_EOL .1892 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1893 "\t\t" . '{' . PHP_EOL .1894 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1895 "\t\t" . '}' . PHP_EOL .1896 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1897 "\t\t" . '{' . PHP_EOL .1898 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1899 "\t\t" . '}' . PHP_EOL .1900 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .1901 "\t\t" . '{' . PHP_EOL .1902 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .1903 "\t\t" . '}' . PHP_EOL .1904 "\t" . '}' . PHP_EOL .1905 "\t" . 'public function ' . $methodName . '(): ' . $returnType . PHP_EOL .1906 "\t" . '{' . PHP_EOL .1907 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .1908 "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL .1909 "\t\t" . '{' . PHP_EOL .1910 "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL .1911 "\t\t\t" . 'return $return;' . PHP_EOL .1912 "\t\t" . '}' . PHP_EOL .1913 "\t\t" . 'else' . PHP_EOL .1914 "\t\t" . '{' . PHP_EOL .1915 "\t\t\t" . '$this->getMockController()->addCall(\'' . $methodName . '\', $arguments);' . PHP_EOL .1916 "\t\t\t" . '$return = call_user_func_array(\'parent::' . $methodName . '\', $arguments);' . PHP_EOL .1917 "\t\t\t" . 'return $return;' . PHP_EOL .1918 "\t\t" . '}' . PHP_EOL .1919 "\t" . '}' . PHP_EOL .1920 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1921 "\t" . '{' . PHP_EOL .1922 "\t\t" . 'return ' . var_export(array('__construct', $methodName), true) . ';' . PHP_EOL .1923 "\t" . '}' . PHP_EOL .1924 '}' . PHP_EOL .1925 '}'1926 )1927 ;1928 }1929 /** @php >= 7.0 */1930 public function testGetMockedClassCodeForInterfaceWithReturnTypeNotBuiltIn()1931 {1932 $this1933 ->if($generator = new testedClass())1934 ->and($reflectionTypeController = new mock\controller())1935 ->and($reflectionTypeController->__construct = function() {})1936 ->and($reflectionTypeController->isBuiltin = false)1937 ->and($reflectionTypeController->__toString = $returnType = 'Mock\Foo')1938 ->and($reflectionType = new \mock\reflectionType())1939 ->and($reflectionMethodController = new mock\controller())1940 ->and($reflectionMethodController->__construct = function() {})1941 ->and($reflectionMethodController->getName = $methodName = uniqid())1942 ->and($reflectionMethodController->isConstructor = false)1943 ->and($reflectionMethodController->getParameters = array())1944 ->and($reflectionMethodController->isPublic = true)1945 ->and($reflectionMethodController->isProtected = false)1946 ->and($reflectionMethodController->isPrivate = false)1947 ->and($reflectionMethodController->isFinal = false)1948 ->and($reflectionMethodController->isStatic = false)1949 ->and($reflectionMethodController->isAbstract = false)1950 ->and($reflectionMethodController->returnsReference = false)1951 ->and($reflectionMethodController->hasReturnType = true)1952 ->and($reflectionMethodController->getReturnType = $reflectionType)1953 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))1954 ->and($reflectionClassController = new mock\controller())1955 ->and($reflectionClassController->__construct = function() {})1956 ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })1957 ->and($reflectionClassController->isFinal = false)1958 ->and($reflectionClassController->isInterface = false)1959 ->and($reflectionClassController->getMethods = array($reflectionMethod))1960 ->and($reflectionClassController->getConstructor = null)1961 ->and($reflectionClassController->isAbstract = false)1962 ->and($reflectionClass = new \mock\reflectionClass(null))1963 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))1964 ->and($adapter = new atoum\test\adapter())1965 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })1966 ->and($generator->setAdapter($adapter))1967 ->then1968 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(1969 'namespace mock {' . PHP_EOL .1970 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .1971 '{' . PHP_EOL .1972 $this->getMockControllerMethods() .1973 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1974 "\t" . '{' . PHP_EOL .1975 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1976 "\t\t" . '{' . PHP_EOL .1977 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1978 "\t\t" . '}' . PHP_EOL .1979 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1980 "\t\t" . '{' . PHP_EOL .1981 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1982 "\t\t" . '}' . PHP_EOL .1983 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .1984 "\t\t" . '{' . PHP_EOL .1985 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .1986 "\t\t" . '}' . PHP_EOL .1987 "\t" . '}' . PHP_EOL .1988 "\t" . 'public function ' . $methodName . '(): \\' . $returnType . PHP_EOL .1989 "\t" . '{' . PHP_EOL .1990 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .1991 "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL .1992 "\t\t" . '{' . PHP_EOL .1993 "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL .1994 "\t\t\t" . 'return $return;' . PHP_EOL .1995 "\t\t" . '}' . PHP_EOL .1996 "\t\t" . 'else' . PHP_EOL .1997 "\t\t" . '{' . PHP_EOL .1998 "\t\t\t" . '$this->getMockController()->addCall(\'' . $methodName . '\', $arguments);' . PHP_EOL .1999 "\t\t\t" . '$return = call_user_func_array(\'parent::' . $methodName . '\', $arguments);' . PHP_EOL .2000 "\t\t\t" . 'return $return;' . PHP_EOL .2001 "\t\t" . '}' . PHP_EOL .2002 "\t" . '}' . PHP_EOL .2003 "\t" . 'public static function getMockedMethods()' . PHP_EOL .2004 "\t" . '{' . PHP_EOL .2005 "\t\t" . 'return ' . var_export(array('__construct', $methodName), true) . ';' . PHP_EOL .2006 "\t" . '}' . PHP_EOL .2007 '}' . PHP_EOL .2008 '}'2009 )2010 ;2011 }2012 /** @php < 7.0 */2013 public function testGetMockedClassCodeForRealClassWithoutConstructor()2014 {2015 $this2016 ->if($generator = new testedClass())2017 ->and($reflectionMethodController = new mock\controller())2018 ->and($reflectionMethodController->__construct = function() {})2019 ->and($reflectionMethodController->getName = $methodName = uniqid())2020 ->and($reflectionMethodController->isConstructor = false)2021 ->and($reflectionMethodController->getParameters = array())2022 ->and($reflectionMethodController->isPublic = true)2023 ->and($reflectionMethodController->isProtected = false)2024 ->and($reflectionMethodController->isPrivate = false)2025 ->and($reflectionMethodController->isFinal = false)2026 ->and($reflectionMethodController->isAbstract = false)2027 ->and($reflectionMethodController->isStatic = false)2028 ->and($reflectionMethodController->returnsReference = false)2029 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))2030 ->and($reflectionClassController = new mock\controller())2031 ->and($reflectionClassController->__construct = function() {})2032 ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })2033 ->and($reflectionClassController->isFinal = false)2034 ->and($reflectionClassController->isInterface = false)2035 ->and($reflectionClassController->getMethods = array($reflectionMethod))2036 ->and($reflectionClassController->getConstructor = null)2037 ->and($reflectionClassController->isAbstract = false)2038 ->and($reflectionClass = new \mock\reflectionClass(null))2039 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))2040 ->and($adapter = new atoum\test\adapter())2041 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })2042 ->and($generator->setAdapter($adapter))2043 ->then2044 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(2045 'namespace mock {' . PHP_EOL .2046 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .2047 '{' . PHP_EOL .2048 $this->getMockControllerMethods() .2049 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .2050 "\t" . '{' . PHP_EOL .2051 "\t\t" . 'if ($mockController === null)' . PHP_EOL .2052 "\t\t" . '{' . PHP_EOL .2053 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .2054 "\t\t" . '}' . PHP_EOL .2055 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .2056 "\t\t" . '{' . PHP_EOL .2057 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .2058 "\t\t" . '}' . PHP_EOL .2059 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .2060 "\t\t" . '{' . PHP_EOL .2061 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .2062 "\t\t" . '}' . PHP_EOL .2063 "\t" . '}' . PHP_EOL .2064 "\t" . 'public function ' . $methodName . '()' . PHP_EOL .2065 "\t" . '{' . PHP_EOL .2066 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .2067 "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL .2068 "\t\t" . '{' . PHP_EOL .2069 "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL .2070 "\t\t\t" . 'return $return;' . PHP_EOL .2071 "\t\t" . '}' . PHP_EOL .2072 "\t\t" . 'else' . PHP_EOL .2073 "\t\t" . '{' . PHP_EOL .2074 "\t\t\t" . '$this->getMockController()->addCall(\'' . $methodName . '\', $arguments);' . PHP_EOL .2075 "\t\t\t" . '$return = call_user_func_array(\'parent::' . $methodName . '\', $arguments);' . PHP_EOL .2076 "\t\t\t" . 'return $return;' . PHP_EOL .2077 "\t\t" . '}' . PHP_EOL .2078 "\t" . '}' . PHP_EOL .2079 "\t" . 'public static function getMockedMethods()' . PHP_EOL .2080 "\t" . '{' . PHP_EOL .2081 "\t\t" . 'return ' . var_export(array('__construct', $methodName), true) . ';' . PHP_EOL .2082 "\t" . '}' . PHP_EOL .2083 '}' . PHP_EOL .2084 '}'2085 )2086 ;2087 }2088 /** @php >= 7.0 */2089 public function testGetMockedClassCodeForRealClassWithoutConstructorPhp7()2090 {2091 $this2092 ->if($generator = new testedClass())2093 ->and($reflectionMethodController = new mock\controller())2094 ->and($reflectionMethodController->__construct = function() {})2095 ->and($reflectionMethodController->getName = $methodName = uniqid())2096 ->and($reflectionMethodController->isConstructor = false)2097 ->and($reflectionMethodController->getParameters = array())2098 ->and($reflectionMethodController->isPublic = true)2099 ->and($reflectionMethodController->isProtected = false)2100 ->and($reflectionMethodController->isPrivate = false)2101 ->and($reflectionMethodController->isFinal = false)2102 ->and($reflectionMethodController->isAbstract = false)2103 ->and($reflectionMethodController->isStatic = false)2104 ->and($reflectionMethodController->returnsReference = false)2105 ->and($reflectionMethodController->hasReturnType = false)2106 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))2107 ->and($reflectionClassController = new mock\controller())2108 ->and($reflectionClassController->__construct = function() {})2109 ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })2110 ->and($reflectionClassController->isFinal = false)2111 ->and($reflectionClassController->isInterface = false)2112 ->and($reflectionClassController->getMethods = array($reflectionMethod))2113 ->and($reflectionClassController->getConstructor = null)2114 ->and($reflectionClassController->isAbstract = false)2115 ->and($reflectionClass = new \mock\reflectionClass(null))2116 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))2117 ->and($adapter = new atoum\test\adapter())2118 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })2119 ->and($generator->setAdapter($adapter))2120 ->then2121 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(2122 'namespace mock {' . PHP_EOL .2123 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .2124 '{' . PHP_EOL .2125 $this->getMockControllerMethods() .2126 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .2127 "\t" . '{' . PHP_EOL .2128 "\t\t" . 'if ($mockController === null)' . PHP_EOL .2129 "\t\t" . '{' . PHP_EOL .2130 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .2131 "\t\t" . '}' . PHP_EOL .2132 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .2133 "\t\t" . '{' . PHP_EOL .2134 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .2135 "\t\t" . '}' . PHP_EOL .2136 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .2137 "\t\t" . '{' . PHP_EOL .2138 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .2139 "\t\t" . '}' . PHP_EOL .2140 "\t" . '}' . PHP_EOL .2141 "\t" . 'public function ' . $methodName . '()' . PHP_EOL .2142 "\t" . '{' . PHP_EOL .2143 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .2144 "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL .2145 "\t\t" . '{' . PHP_EOL .2146 "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL .2147 "\t\t\t" . 'return $return;' . PHP_EOL .2148 "\t\t" . '}' . PHP_EOL .2149 "\t\t" . 'else' . PHP_EOL .2150 "\t\t" . '{' . PHP_EOL .2151 "\t\t\t" . '$this->getMockController()->addCall(\'' . $methodName . '\', $arguments);' . PHP_EOL .2152 "\t\t\t" . '$return = call_user_func_array(\'parent::' . $methodName . '\', $arguments);' . PHP_EOL .2153 "\t\t\t" . 'return $return;' . PHP_EOL .2154 "\t\t" . '}' . PHP_EOL .2155 "\t" . '}' . PHP_EOL .2156 "\t" . 'public static function getMockedMethods()' . PHP_EOL .2157 "\t" . '{' . PHP_EOL .2158 "\t\t" . 'return ' . var_export(array('__construct', $methodName), true) . ';' . PHP_EOL .2159 "\t" . '}' . PHP_EOL .2160 '}' . PHP_EOL .2161 '}'2162 )2163 ;2164 }2165 public function testGetMockedClassCodeForAbstractClassWithConstructorInInterface()2166 {2167 $this2168 ->if($generator = new testedClass())2169 ->and($publicMethodController = new mock\controller())2170 ->and($publicMethodController->__construct = function() {})2171 ->and($publicMethodController->getName = '__construct')2172 ->and($publicMethodController->isConstructor = true)2173 ->and($publicMethodController->getParameters = array())2174 ->and($publicMethodController->isPublic = true)2175 ->and($publicMethodController->isProtected = false)2176 ->and($publicMethodController->isPrivate = false)2177 ->and($publicMethodController->isFinal = false)2178 ->and($publicMethodController->isStatic = false)2179 ->and($publicMethodController->isAbstract = true)2180 ->and($publicMethodController->returnsReference = false)2181 ->and($publicMethod = new \mock\reflectionMethod(null, null))2182 ->and($classController = new mock\controller())2183 ->and($classController->__construct = function() {})2184 ->and($classController->getName = $className = uniqid())2185 ->and($classController->isFinal = false)2186 ->and($classController->isInterface = false)2187 ->and($classController->isAbstract = true)2188 ->and($classController->getMethods = array($publicMethod))2189 ->and($classController->getConstructor = $publicMethod)2190 ->and($class = new \mock\reflectionClass(null))2191 ->and($generator->setReflectionClassFactory(function() use ($class) { return $class; }))2192 ->and($adapter = new atoum\test\adapter())2193 ->and($adapter->class_exists = function($class) use ($className) { return ($class == '\\' . $className); })2194 ->and($generator->setAdapter($adapter))2195 ->then2196 ->string($generator->getMockedClassCode($className))->isEqualTo(2197 'namespace mock {' . PHP_EOL .2198 'final class ' . $className . ' extends \\' . $className . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .2199 '{' . PHP_EOL .2200 $this->getMockControllerMethods() .2201 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .2202 "\t" . '{' . PHP_EOL .2203 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .2204 "\t\t" . 'if ($mockController === null)' . PHP_EOL .2205 "\t\t" . '{' . PHP_EOL .2206 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .2207 "\t\t" . '}' . PHP_EOL .2208 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .2209 "\t\t" . '{' . PHP_EOL .2210 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .2211 "\t\t" . '}' . PHP_EOL .2212 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .2213 "\t\t" . '{' . PHP_EOL .2214 "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .2215 "\t\t" . '}' . PHP_EOL .2216 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .2217 "\t" . '}' . PHP_EOL .2218 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .2219 "\t" . '{' . PHP_EOL .2220 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .2221 "\t\t" . '{' . PHP_EOL .2222 "\t\t\t" . '$return = $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .2223 "\t\t\t" . 'return $return;' . PHP_EOL .2224 "\t\t" . '}' . PHP_EOL .2225 "\t\t" . 'else' . PHP_EOL .2226 "\t\t" . '{' . PHP_EOL .2227 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .2228 "\t\t" . '}' . PHP_EOL .2229 "\t" . '}' . PHP_EOL .2230 "\t" . 'public static function getMockedMethods()' . PHP_EOL .2231 "\t" . '{' . PHP_EOL .2232 "\t\t" . 'return ' . var_export(array('__construct', '__call'), true) . ';' . PHP_EOL .2233 "\t" . '}' . PHP_EOL .2234 '}' . PHP_EOL .2235 '}'2236 )2237 ;2238 }2239 public function testGenerate()2240 {2241 $this2242 ->if($generator = new testedClass())2243 ->then2244 ->exception(function() use ($generator) { $generator->generate(''); })2245 ->isInstanceOf('mageekguy\atoum\exceptions\runtime')2246 ->hasMessage('Class name \'\' is invalid')2247 ->exception(function() use ($generator) { $generator->generate('\\'); })2248 ->isInstanceOf('mageekguy\atoum\exceptions\runtime')2249 ->hasMessage('Class name \'\\\' is invalid')2250 ->exception(function() use ($generator, & $class) { $generator->generate($class = ('\\' . uniqid() . '\\')); })2251 ->isInstanceOf('mageekguy\atoum\exceptions\runtime')2252 ->hasMessage('Class name \'' . $class . '\' is invalid')2253 ->if($adapter = new atoum\test\adapter())2254 ->and($adapter->class_exists = false)2255 ->and($adapter->interface_exists = false)2256 ->and($generator->setAdapter($adapter))2257 ->and($class = uniqid('unknownClass'))2258 ->then2259 ->object($generator->generate($class))->isIdenticalTo($generator)2260 ->class('\mock\\' . $class)2261 ->hasNoParent()2262 ->hasInterface('mageekguy\atoum\mock\aggregator')2263 ->if($class = '\\' . uniqid('unknownClass'))2264 ->then2265 ->object($generator->generate($class))->isIdenticalTo($generator)2266 ->class('\mock' . $class)2267 ->hasNoParent()2268 ->hasInterface('mageekguy\atoum\mock\aggregator')2269 ->if($adapter->class_exists = true)2270 ->and($class = uniqid())2271 ->then2272 ->exception(function () use ($generator, $class) {2273 $generator->generate($class);2274 }2275 )2276 ->isInstanceOf('mageekguy\atoum\exceptions\logic')2277 ->hasMessage('Class \'\mock\\' . $class . '\' already exists')2278 ->if($class = '\\' . uniqid())2279 ->then2280 ->exception(function () use ($generator, $class) {2281 $generator->generate($class);2282 }2283 )2284 ->isInstanceOf('mageekguy\atoum\exceptions\logic')2285 ->hasMessage('Class \'\mock' . $class . '\' already exists')2286 ->if($class = uniqid())2287 ->and($adapter->class_exists = function($arg) use ($class) { return $arg === '\\' . $class; })2288 ->and($reflectionClassController = new mock\controller())2289 ->and($reflectionClassController->__construct = function() {})2290 ->and($reflectionClassController->isFinal = true)2291 ->and($reflectionClassController->isInterface = false)2292 ->and($reflectionClass = new \mock\reflectionClass(uniqid(), $reflectionClassController))2293 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))2294 ->then2295 ->exception(function () use ($generator, $class) {2296 $generator->generate($class);2297 }2298 )2299 ->isInstanceOf('mageekguy\atoum\exceptions\logic')2300 ->hasMessage('Class \'\\' . $class . '\' is final, unable to mock it')2301 ->if($class = '\\' . uniqid())2302 ->and($adapter->class_exists = function($arg) use ($class) { return $arg === $class; })2303 ->then2304 ->exception(function () use ($generator, $class) {2305 $generator->generate($class);2306 }2307 )2308 ->isInstanceOf('mageekguy\atoum\exceptions\logic')2309 ->hasMessage('Class \'' . $class . '\' is final, unable to mock it')2310 ->if($reflectionClassController->isFinal = false)2311 ->and($generator = new testedClass())2312 ->then2313 ->object($generator->generate(__CLASS__))->isIdenticalTo($generator)2314 ->class('\mock\\' . __CLASS__)2315 ->hasParent(__CLASS__)2316 ->hasInterface('mageekguy\atoum\mock\aggregator')2317 ->if($generator = new testedClass())2318 ->and($generator->shunt('__construct'))2319 ->then2320 ->boolean($generator->isShunted('__construct'))->isTrue()2321 ->object($generator->generate('reflectionMethod'))->isIdenticalTo($generator)2322 ->boolean($generator->isShunted('__construct'))->isFalse()2323 ->if($generator = new testedClass())2324 ->and($generator->shuntParentClassCalls())2325 ->then2326 ->object($generator->generate('reflectionParameter'))->isIdenticalTo($generator)2327 ->boolean($generator->callsToParentClassAreShunted())->isFalse()2328 ;2329 }2330 public function testMethodIsMockable()2331 {2332 $this2333 ->if($generator = new testedClass())2334 ->and($this->mockGenerator->orphanize('__construct'))2335 ->and($method = new \mock\reflectionMethod($this, $methodName = uniqid()))2336 ->and($this->calling($method)->getName = $methodName)2337 ->and($this->calling($method)->isFinal = false)2338 ->and($this->calling($method)->isStatic = false)2339 ->and($this->calling($method)->isAbstract = false)2340 ->and($this->calling($method)->isPrivate = false)2341 ->and($this->calling($method)->isProtected = false)2342 ->then2343 ->boolean($generator->methodIsMockable($method))->isTrue()2344 ->if($this->calling($method)->isFinal = true)2345 ->then2346 ->boolean($generator->methodIsMockable($method))->isFalse()2347 ->if($this->calling($method)->isFinal = false)2348 ->and($this->calling($method)->isStatic = true)2349 ->then2350 ->boolean($generator->methodIsMockable($method))->isFalse()2351 ->if($this->calling($method)->isStatic = false)2352 ->and($this->calling($method)->isPrivate = true)2353 ->then2354 ->boolean($generator->methodIsMockable($method))->isFalse()2355 ->if($this->calling($method)->isPrivate = false)2356 ->and($this->calling($method)->isProtected = true)2357 ->then2358 ->boolean($generator->methodIsMockable($method))->isFalse()2359 ->if($generator->overload(new mock\php\method($methodName)))2360 ->then2361 ->boolean($generator->methodIsMockable($method))->isTrue()2362 ;2363 }2364 /** @php < 7.0 */2365 public function testMethodIsMockableWithReservedWord($reservedWord)2366 {2367 $this2368 ->if($generator = new testedClass())2369 ->and($this->mockGenerator->orphanize('__construct'))2370 ->and($method = new \mock\reflectionMethod($this, $reservedWord))2371 ->and($this->calling($method)->getName = $reservedWord)2372 ->and($this->calling($method)->isFinal = false)2373 ->and($this->calling($method)->isStatic = false)2374 ->and($this->calling($method)->isAbstract = false)2375 ->and($this->calling($method)->isPrivate = false)2376 ->and($this->calling($method)->isProtected = false)2377 ->then2378 ->boolean($generator->methodIsMockable($method))->isFalse()2379 ;2380 }2381 /** @php >= 7.0 */2382 public function testMethodIsMockableWithReservedWordPhp7($reservedWord)2383 {2384 $this2385 ->if($generator = new testedClass())2386 ->and($this->mockGenerator->orphanize('__construct'))2387 ->and($method = new \mock\reflectionMethod($this, $reservedWord))2388 ->and($this->calling($method)->getName = $reservedWord)2389 ->and($this->calling($method)->isFinal = false)2390 ->and($this->calling($method)->isStatic = false)2391 ->and($this->calling($method)->isAbstract = false)2392 ->and($this->calling($method)->isPrivate = false)2393 ->and($this->calling($method)->isProtected = false)2394 ->then2395 ->boolean($generator->methodIsMockable($method))->isFalse()2396 ;2397 }2398 /**2399 * @php >= 5.42400 * @php < 5.62401 */2402 public function testGetMockedClassCodeWithOrphanizedMethod()2403 {2404 $this2405 ->if->mockGenerator->orphanize('__construct')2406 ->and($a = new \mock\reflectionParameter())2407 ->and($this->calling($a)->getName = 'a')2408 ->and($this->calling($a)->isArray = false)2409 ->and($this->calling($a)->isCallable = false)2410 ->and($this->calling($a)->getClass = null)2411 ->and($this->calling($a)->isPassedByReference = false)2412 ->and($this->calling($a)->isDefaultValueAvailable = false)2413 ->and($this->calling($a)->isOptional = false)2414 ->and($b = new \mock\reflectionParameter())2415 ->and($this->calling($b)->getName = 'b')2416 ->and($this->calling($b)->isArray = false)2417 ->and($this->calling($b)->isCallable = false)2418 ->and($this->calling($b)->getClass = null)2419 ->and($this->calling($b)->isPassedByReference = false)2420 ->and($this->calling($b)->isDefaultValueAvailable = false)2421 ->and($this->calling($b)->isOptional = false)2422 ->and($c = new \mock\reflectionParameter())2423 ->and($this->calling($c)->getName = 'c')2424 ->and($this->calling($c)->isArray = false)2425 ->and($this->calling($c)->isCallable = false)2426 ->and($this->calling($c)->getClass = null)2427 ->and($this->calling($c)->isPassedByReference = false)2428 ->and($this->calling($c)->isDefaultValueAvailable = false)2429 ->and($this->calling($c)->isOptional = false)2430 ->and->mockGenerator->orphanize('__construct')2431 ->and($constructor = new \mock\reflectionMethod())2432 ->and($this->calling($constructor)->getName = '__construct')2433 ->and($this->calling($constructor)->isConstructor = true)2434 ->and($this->calling($constructor)->getParameters = array($a, $b, $c))2435 ->and($this->calling($constructor)->isPublic = true)2436 ->and($this->calling($constructor)->isProtected = false)2437 ->and($this->calling($constructor)->isPrivate = false)2438 ->and($this->calling($constructor)->isFinal = false)2439 ->and($this->calling($constructor)->isStatic = false)2440 ->and($this->calling($constructor)->isAbstract = false)2441 ->and($this->calling($constructor)->returnsReference = false)2442 ->and->mockGenerator->orphanize('__construct')2443 ->and($class = new \mock\reflectionClass())2444 ->and($this->calling($class)->getName = $className = uniqid())2445 ->and($this->calling($class)->isFinal = false)2446 ->and($this->calling($class)->isInterface = false)2447 ->and($this->calling($class)->isAbstract = false)2448 ->and($this->calling($class)->getMethods = array($constructor))2449 ->and($this->calling($class)->getConstructor = $constructor)2450 ->and($adapter = new atoum\test\adapter())2451 ->and($adapter->class_exists = function($class) use ($className) { return ($class == '\\' . $className); })2452 ->and($generator = new testedClass())2453 ->and($generator->setReflectionClassFactory(function() use ($class) { return $class; }))2454 ->and($generator->setAdapter($adapter))2455 ->and($generator->orphanize('__construct'))2456 ->then2457 ->string($generator->getMockedClassCode($className))->isEqualTo(2458 'namespace mock {' . PHP_EOL .2459 'final class ' . $className . ' extends \\' . $className . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .2460 '{' . PHP_EOL .2461 $this->getMockControllerMethods() .2462 "\t" . 'public function __construct($a = null, $b = null, $c = null, \mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .2463 "\t" . '{' . PHP_EOL .2464 "\t\t" . '$arguments = array_merge(array($a, $b, $c), array_slice(func_get_args(), 3, -1));' . PHP_EOL .2465 "\t\t" . 'if ($mockController === null)' . PHP_EOL .2466 "\t\t" . '{' . PHP_EOL .2467 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .2468 "\t\t" . '}' . PHP_EOL .2469 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .2470 "\t\t" . '{' . PHP_EOL .2471 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .2472 "\t\t" . '}' . PHP_EOL .2473 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .2474 "\t\t" . '{' . PHP_EOL .2475 "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .2476 "\t\t" . '}' . PHP_EOL .2477 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .2478 "\t" . '}' . PHP_EOL .2479 "\t" . 'public static function getMockedMethods()' . PHP_EOL .2480 "\t" . '{' . PHP_EOL .2481 "\t\t" . 'return ' . var_export(array('__construct'), true) . ';' . PHP_EOL .2482 "\t" . '}' . PHP_EOL .2483 '}' . PHP_EOL .2484 '}'2485 )2486 ;2487 }2488 /**2489 * @php >= 5.62490 * @php < 7.02491 */2492 public function testGetMockedClassCodeWithOrphanizedMethodPhp56()2493 {2494 $this2495 ->if->mockGenerator->orphanize('__construct')2496 ->and($a = new \mock\reflectionParameter())2497 ->and($this->calling($a)->getName = 'a')2498 ->and($this->calling($a)->isArray = false)2499 ->and($this->calling($a)->isCallable = false)2500 ->and($this->calling($a)->getClass = null)2501 ->and($this->calling($a)->isPassedByReference = false)2502 ->and($this->calling($a)->isDefaultValueAvailable = false)2503 ->and($this->calling($a)->isOptional = false)2504 ->and($this->calling($a)->isVariadic = false)2505 ->and($b = new \mock\reflectionParameter())2506 ->and($this->calling($b)->getName = 'b')2507 ->and($this->calling($b)->isArray = false)2508 ->and($this->calling($b)->isCallable = false)2509 ->and($this->calling($b)->getClass = null)2510 ->and($this->calling($b)->isPassedByReference = false)2511 ->and($this->calling($b)->isDefaultValueAvailable = false)2512 ->and($this->calling($b)->isOptional = false)2513 ->and($this->calling($b)->isVariadic = false)2514 ->and($c = new \mock\reflectionParameter())2515 ->and($this->calling($c)->getName = 'c')2516 ->and($this->calling($c)->isArray = false)2517 ->and($this->calling($c)->isCallable = false)2518 ->and($this->calling($c)->getClass = null)2519 ->and($this->calling($c)->isPassedByReference = false)2520 ->and($this->calling($c)->isDefaultValueAvailable = false)2521 ->and($this->calling($c)->isOptional = false)2522 ->and($this->calling($c)->isVariadic = false)2523 ->and->mockGenerator->orphanize('__construct')2524 ->and($constructor = new \mock\reflectionMethod())2525 ->and($this->calling($constructor)->getName = '__construct')2526 ->and($this->calling($constructor)->isConstructor = true)2527 ->and($this->calling($constructor)->getParameters = array($a, $b, $c))2528 ->and($this->calling($constructor)->isPublic = true)2529 ->and($this->calling($constructor)->isProtected = false)2530 ->and($this->calling($constructor)->isPrivate = false)2531 ->and($this->calling($constructor)->isFinal = false)2532 ->and($this->calling($constructor)->isStatic = false)2533 ->and($this->calling($constructor)->isAbstract = false)2534 ->and($this->calling($constructor)->returnsReference = false)2535 ->and->mockGenerator->orphanize('__construct')2536 ->and($class = new \mock\reflectionClass())2537 ->and($this->calling($class)->getName = $className = uniqid())2538 ->and($this->calling($class)->isFinal = false)2539 ->and($this->calling($class)->isInterface = false)2540 ->and($this->calling($class)->isAbstract = false)2541 ->and($this->calling($class)->getMethods = array($constructor))2542 ->and($this->calling($class)->getConstructor = $constructor)2543 ->and($adapter = new atoum\test\adapter())2544 ->and($adapter->class_exists = function($class) use ($className) { return ($class == '\\' . $className); })2545 ->and($generator = new testedClass())2546 ->and($generator->setReflectionClassFactory(function() use ($class) { return $class; }))2547 ->and($generator->setAdapter($adapter))2548 ->and($generator->orphanize('__construct'))2549 ->then2550 ->string($generator->getMockedClassCode($className))->isEqualTo(2551 'namespace mock {' . PHP_EOL .2552 'final class ' . $className . ' extends \\' . $className . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .2553 '{' . PHP_EOL .2554 $this->getMockControllerMethods() .2555 "\t" . 'public function __construct($a = null, $b = null, $c = null, \mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .2556 "\t" . '{' . PHP_EOL .2557 "\t\t" . '$arguments = array_merge(array($a, $b, $c), array_slice(func_get_args(), 3, -1));' . PHP_EOL .2558 "\t\t" . 'if ($mockController === null)' . PHP_EOL .2559 "\t\t" . '{' . PHP_EOL .2560 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .2561 "\t\t" . '}' . PHP_EOL .2562 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .2563 "\t\t" . '{' . PHP_EOL .2564 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .2565 "\t\t" . '}' . PHP_EOL .2566 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .2567 "\t\t" . '{' . PHP_EOL .2568 "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .2569 "\t\t" . '}' . PHP_EOL .2570 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .2571 "\t" . '}' . PHP_EOL .2572 "\t" . 'public static function getMockedMethods()' . PHP_EOL .2573 "\t" . '{' . PHP_EOL .2574 "\t\t" . 'return ' . var_export(array('__construct'), true) . ';' . PHP_EOL .2575 "\t" . '}' . PHP_EOL .2576 '}' . PHP_EOL .2577 '}'2578 )2579 ;2580 }2581 /**2582 * @php 5.42583 * @php < 5.62584 */2585 public function testGetMockedClassCodeWithProtectedAbstractMethod()2586 {2587 $this2588 ->if($generator = new testedClass())2589 ->and($parameterController1 = new mock\controller())2590 ->and($parameterController1->__construct = function() {})2591 ->and($parameterController1->isArray = false)2592 ->and($parameterController1->isCallable = false)2593 ->and($parameterController1->getClass = null)2594 ->and($parameterController1->getName = 'arg1')2595 ->and($parameterController1->isPassedByReference = false)2596 ->and($parameterController1->isDefaultValueAvailable = false)2597 ->and($parameterController1->isOptional = false)2598 ->and($parameter1 = new \mock\reflectionParameter(null, null))2599 ->and($parameterController2 = new mock\controller())2600 ->and($parameterController2->__construct = function() {})2601 ->and($parameterController2->isArray = true)2602 ->and($parameterController2->isCallable = false)2603 ->and($parameterController2->getClass = null)2604 ->and($parameterController2->getName = 'arg2')2605 ->and($parameterController2->isPassedByReference = true)2606 ->and($parameterController2->isDefaultValueAvailable = false)2607 ->and($parameterController2->isOptional = false)2608 ->and($parameter2 = new \mock\reflectionParameter(null, null))2609 ->and($publicMethodController = new mock\controller())2610 ->and($publicMethodController->__construct = function() {})2611 ->and($publicMethodController->getName = $publicMethodName = uniqid())2612 ->and($publicMethodController->isConstructor = false)2613 ->and($publicMethodController->getParameters = array($parameter1, $parameter2))2614 ->and($publicMethodController->isPublic = true)2615 ->and($publicMethodController->isProtected = false)2616 ->and($publicMethodController->isPrivate = false)2617 ->and($publicMethodController->isFinal = false)2618 ->and($publicMethodController->isStatic = false)2619 ->and($publicMethodController->isAbstract = true)2620 ->and($publicMethodController->returnsReference = false)2621 ->and($publicMethod = new \mock\reflectionMethod(null, null))2622 ->and($protectedMethodController = new mock\controller())2623 ->and($protectedMethodController->__construct = function() {})2624 ->and($protectedMethodController->getName = $protectedMethodName = uniqid())2625 ->and($protectedMethodController->isConstructor = false)2626 ->and($protectedMethodController->getParameters = array())2627 ->and($protectedMethodController->isPublic = false)2628 ->and($protectedMethodController->isProtected = true)2629 ->and($protectedMethodController->isPrivate = false)2630 ->and($protectedMethodController->isFinal = false)2631 ->and($protectedMethodController->isStatic = false)2632 ->and($protectedMethodController->isAbstract = true)2633 ->and($protectedMethodController->returnsReference = false)2634 ->and($protectedMethod = new \mock\reflectionMethod(null, null))2635 ->and($classController = new mock\controller())2636 ->and($classController->__construct = function() {})2637 ->and($classController->getName = $className = uniqid())2638 ->and($classController->isFinal = false)2639 ->and($classController->isInterface = false)2640 ->and($classController->getMethods = array($publicMethod, $protectedMethod))2641 ->and($classController->getConstructor = null)2642 ->and($classController->isAbstract = false)2643 ->and($class = new \mock\reflectionClass(null))2644 ->and($generator->setReflectionClassFactory(function() use ($class) { return $class; }))2645 ->and($adapter = new atoum\test\adapter())2646 ->and($adapter->class_exists = function($class) use ($className) { return ($class == '\\' . $className); })2647 ->and($generator->setAdapter($adapter))2648 ->then2649 ->string($generator->getMockedClassCode($className))->isEqualTo(2650 'namespace mock {' . PHP_EOL .2651 'final class ' . $className . ' extends \\' . $className . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .2652 '{' . PHP_EOL .2653 $this->getMockControllerMethods() .2654 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .2655 "\t" . '{' . PHP_EOL .2656 "\t\t" . 'if ($mockController === null)' . PHP_EOL .2657 "\t\t" . '{' . PHP_EOL .2658 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .2659 "\t\t" . '}' . PHP_EOL .2660 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .2661 "\t\t" . '{' . PHP_EOL .2662 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .2663 "\t\t" . '}' . PHP_EOL .2664 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .2665 "\t\t" . '{' . PHP_EOL .2666 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .2667 "\t\t" . '}' . PHP_EOL .2668 "\t" . '}' . PHP_EOL .2669 "\t" . 'public function ' . $publicMethodName . '($arg1, array & $arg2)' . PHP_EOL .2670 "\t" . '{' . PHP_EOL .2671 "\t\t" . '$arguments = array_merge(array($arg1, & $arg2), array_slice(func_get_args(), 2));' . PHP_EOL .2672 "\t\t" . 'if (isset($this->getMockController()->' . $publicMethodName . ') === false)' . PHP_EOL .2673 "\t\t" . '{' . PHP_EOL .2674 "\t\t\t" . '$this->getMockController()->' . $publicMethodName . ' = function() {};' . PHP_EOL .2675 "\t\t" . '}' . PHP_EOL .2676 "\t\t" . '$return = $this->getMockController()->invoke(\'' . $publicMethodName . '\', $arguments);' . PHP_EOL .2677 "\t\t" . 'return $return;' . PHP_EOL .2678 "\t" . '}' . PHP_EOL .2679 "\t" . 'protected function ' . $protectedMethodName . '()' . PHP_EOL .2680 "\t" . '{' . PHP_EOL .2681 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .2682 "\t\t" . 'if (isset($this->getMockController()->' . $protectedMethodName . ') === false)' . PHP_EOL .2683 "\t\t" . '{' . PHP_EOL .2684 "\t\t\t" . '$this->getMockController()->' . $protectedMethodName . ' = function() {};' . PHP_EOL .2685 "\t\t" . '}' . PHP_EOL .2686 "\t\t" . '$return = $this->getMockController()->invoke(\'' . $protectedMethodName . '\', $arguments);' . PHP_EOL .2687 "\t\t" . 'return $return;' . PHP_EOL .2688 "\t" . '}' . PHP_EOL .2689 "\t" . 'public static function getMockedMethods()' . PHP_EOL .2690 "\t" . '{' . PHP_EOL .2691 "\t\t" . 'return ' . var_export(array('__construct', $publicMethodName, $protectedMethodName), true) . ';' . PHP_EOL .2692 "\t" . '}' . PHP_EOL .2693 '}' . PHP_EOL .2694 '}'2695 )2696 ;2697 }2698 /**2699 * @php >= 5.62700 * @php < 7.02701 */2702 public function testGetMockedClassCodeWithProtectedAbstractMethodPhp56()2703 {2704 $this2705 ->if($generator = new testedClass())2706 ->and($parameterController1 = new mock\controller())2707 ->and($parameterController1->__construct = function() {})2708 ->and($parameterController1->isArray = false)2709 ->and($parameterController1->isCallable = false)2710 ->and($parameterController1->getClass = null)2711 ->and($parameterController1->getName = 'arg1')2712 ->and($parameterController1->isPassedByReference = false)2713 ->and($parameterController1->isDefaultValueAvailable = false)2714 ->and($parameterController1->isOptional = false)2715 ->and($parameterController1->isVariadic = false)2716 ->and($parameter1 = new \mock\reflectionParameter(null, null))2717 ->and($parameterController2 = new mock\controller())2718 ->and($parameterController2->__construct = function() {})2719 ->and($parameterController2->isArray = true)2720 ->and($parameterController2->isCallable = false)2721 ->and($parameterController2->getClass = null)2722 ->and($parameterController2->getName = 'arg2')2723 ->and($parameterController2->isPassedByReference = true)2724 ->and($parameterController2->isDefaultValueAvailable = false)2725 ->and($parameterController2->isOptional = false)2726 ->and($parameterController2->isVariadic = false)2727 ->and($parameter2 = new \mock\reflectionParameter(null, null))2728 ->and($publicMethodController = new mock\controller())2729 ->and($publicMethodController->__construct = function() {})2730 ->and($publicMethodController->getName = $publicMethodName = uniqid())2731 ->and($publicMethodController->isConstructor = false)2732 ->and($publicMethodController->getParameters = array($parameter1, $parameter2))2733 ->and($publicMethodController->isPublic = true)2734 ->and($publicMethodController->isProtected = false)2735 ->and($publicMethodController->isPrivate = false)2736 ->and($publicMethodController->isFinal = false)2737 ->and($publicMethodController->isStatic = false)2738 ->and($publicMethodController->isAbstract = true)2739 ->and($publicMethodController->returnsReference = false)2740 ->and($publicMethod = new \mock\reflectionMethod(null, null))2741 ->and($protectedMethodController = new mock\controller())2742 ->and($protectedMethodController->__construct = function() {})2743 ->and($protectedMethodController->getName = $protectedMethodName = uniqid())2744 ->and($protectedMethodController->isConstructor = false)2745 ->and($protectedMethodController->getParameters = array())2746 ->and($protectedMethodController->isPublic = false)2747 ->and($protectedMethodController->isProtected = true)2748 ->and($protectedMethodController->isPrivate = false)2749 ->and($protectedMethodController->isFinal = false)2750 ->and($protectedMethodController->isStatic = false)2751 ->and($protectedMethodController->isAbstract = true)2752 ->and($protectedMethodController->returnsReference = false)2753 ->and($protectedMethod = new \mock\reflectionMethod(null, null))2754 ->and($classController = new mock\controller())2755 ->and($classController->__construct = function() {})2756 ->and($classController->getName = $className = uniqid())2757 ->and($classController->isFinal = false)2758 ->and($classController->isInterface = false)2759 ->and($classController->getMethods = array($publicMethod, $protectedMethod))2760 ->and($classController->getConstructor = null)2761 ->and($classController->isAbstract = false)2762 ->and($class = new \mock\reflectionClass(null))2763 ->and($generator->setReflectionClassFactory(function() use ($class) { return $class; }))2764 ->and($adapter = new atoum\test\adapter())2765 ->and($adapter->class_exists = function($class) use ($className) { return ($class == '\\' . $className); })2766 ->and($generator->setAdapter($adapter))2767 ->then2768 ->string($generator->getMockedClassCode($className))->isEqualTo(2769 'namespace mock {' . PHP_EOL .2770 'final class ' . $className . ' extends \\' . $className . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .2771 '{' . PHP_EOL .2772 $this->getMockControllerMethods() .2773 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .2774 "\t" . '{' . PHP_EOL .2775 "\t\t" . 'if ($mockController === null)' . PHP_EOL .2776 "\t\t" . '{' . PHP_EOL .2777 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .2778 "\t\t" . '}' . PHP_EOL .2779 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .2780 "\t\t" . '{' . PHP_EOL .2781 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .2782 "\t\t" . '}' . PHP_EOL .2783 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .2784 "\t\t" . '{' . PHP_EOL .2785 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .2786 "\t\t" . '}' . PHP_EOL .2787 "\t" . '}' . PHP_EOL .2788 "\t" . 'public function ' . $publicMethodName . '($arg1, array & $arg2)' . PHP_EOL .2789 "\t" . '{' . PHP_EOL .2790 "\t\t" . '$arguments = array_merge(array($arg1, & $arg2), array_slice(func_get_args(), 2));' . PHP_EOL .2791 "\t\t" . 'if (isset($this->getMockController()->' . $publicMethodName . ') === false)' . PHP_EOL .2792 "\t\t" . '{' . PHP_EOL .2793 "\t\t\t" . '$this->getMockController()->' . $publicMethodName . ' = function() {};' . PHP_EOL .2794 "\t\t" . '}' . PHP_EOL .2795 "\t\t" . '$return = $this->getMockController()->invoke(\'' . $publicMethodName . '\', $arguments);' . PHP_EOL .2796 "\t\t" . 'return $return;' . PHP_EOL .2797 "\t" . '}' . PHP_EOL .2798 "\t" . 'protected function ' . $protectedMethodName . '()' . PHP_EOL .2799 "\t" . '{' . PHP_EOL .2800 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .2801 "\t\t" . 'if (isset($this->getMockController()->' . $protectedMethodName . ') === false)' . PHP_EOL .2802 "\t\t" . '{' . PHP_EOL .2803 "\t\t\t" . '$this->getMockController()->' . $protectedMethodName . ' = function() {};' . PHP_EOL .2804 "\t\t" . '}' . PHP_EOL .2805 "\t\t" . '$return = $this->getMockController()->invoke(\'' . $protectedMethodName . '\', $arguments);' . PHP_EOL .2806 "\t\t" . 'return $return;' . PHP_EOL .2807 "\t" . '}' . PHP_EOL .2808 "\t" . 'public static function getMockedMethods()' . PHP_EOL .2809 "\t" . '{' . PHP_EOL .2810 "\t\t" . 'return ' . var_export(array('__construct', $publicMethodName, $protectedMethodName), true) . ';' . PHP_EOL .2811 "\t" . '}' . PHP_EOL .2812 '}' . PHP_EOL .2813 '}'2814 )2815 ;2816 }2817 /**2818 * @php 5.42819 * @php < 5.62820 */2821 public function testGetMockedClassCodeForClassWithCallableTypeHint()2822 {2823 $this2824 ->if($generator = new testedClass())2825 ->and($reflectionParameterController = new mock\controller())2826 ->and($reflectionParameterController->__construct = function() {})2827 ->and($reflectionParameterController->isArray = false)2828 ->and($reflectionParameterController->isCallable = true)2829 ->and($reflectionParameterController->getName = 'callback')2830 ->and($reflectionParameterController->isPassedByReference = false)2831 ->and($reflectionParameterController->isDefaultValueAvailable = false)2832 ->and($reflectionParameterController->isOptional = false)2833 ->and($reflectionParameter = new \mock\reflectionParameter(null, null))2834 ->and($reflectionMethodController = new mock\controller())2835 ->and($reflectionMethodController->__construct = function() {})2836 ->and($reflectionMethodController->getName = '__construct')2837 ->and($reflectionMethodController->isConstructor = true)2838 ->and($reflectionMethodController->getParameters = array($reflectionParameter))2839 ->and($reflectionMethodController->isPublic = true)2840 ->and($reflectionMethodController->isProtected = false)2841 ->and($reflectionMethodController->isPrivate = false)2842 ->and($reflectionMethodController->isFinal = false)2843 ->and($reflectionMethodController->isStatic = false)2844 ->and($reflectionMethodController->isAbstract = false)2845 ->and($reflectionMethodController->returnsReference = false)2846 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))2847 ->and($reflectionClassController = new mock\controller())2848 ->and($reflectionClassController->__construct = function() {})2849 ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })2850 ->and($reflectionClassController->isFinal = false)2851 ->and($reflectionClassController->isInterface = false)2852 ->and($reflectionClassController->getMethods = array($reflectionMethod))2853 ->and($reflectionClassController->getConstructor = $reflectionMethod)2854 ->and($reflectionClassController->isAbstract = false)2855 ->and($reflectionClass = new \mock\reflectionClass(null))2856 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))2857 ->and($adapter = new atoum\test\adapter())2858 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })2859 ->and($generator->setAdapter($adapter))2860 ->then2861 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(2862 'namespace mock {' . PHP_EOL .2863 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .2864 '{' . PHP_EOL .2865 $this->getMockControllerMethods() .2866 "\t" . 'public function __construct(callable $callback, \mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .2867 "\t" . '{' . PHP_EOL .2868 "\t\t" . '$arguments = array_merge(array($callback), array_slice(func_get_args(), 1, -1));' . PHP_EOL .2869 "\t\t" . 'if ($mockController === null)' . PHP_EOL .2870 "\t\t" . '{' . PHP_EOL .2871 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .2872 "\t\t" . '}' . PHP_EOL .2873 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .2874 "\t\t" . '{' . PHP_EOL .2875 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .2876 "\t\t" . '}' . PHP_EOL .2877 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .2878 "\t\t" . '{' . PHP_EOL .2879 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .2880 "\t\t" . '}' . PHP_EOL .2881 "\t\t" . 'else' . PHP_EOL .2882 "\t\t" . '{' . PHP_EOL .2883 "\t\t\t" . '$this->getMockController()->addCall(\'__construct\', $arguments);' . PHP_EOL .2884 "\t\t\t" . 'call_user_func_array(\'parent::__construct\', $arguments);' . PHP_EOL .2885 "\t\t" . '}' . PHP_EOL .2886 "\t" . '}' . PHP_EOL .2887 "\t" . 'public static function getMockedMethods()' . PHP_EOL .2888 "\t" . '{' . PHP_EOL .2889 "\t\t" . 'return ' . var_export(array('__construct'), true) . ';' . PHP_EOL .2890 "\t" . '}' . PHP_EOL .2891 '}' . PHP_EOL .2892 '}'2893 )2894 ;2895 }2896 /** @php 5.6 */2897 public function testGetMockedClassCodeForClassWithCallableTypeHintPhp56()2898 {2899 $this2900 ->if($generator = new testedClass())2901 ->and($reflectionParameterController = new mock\controller())2902 ->and($reflectionParameterController->__construct = function() {})2903 ->and($reflectionParameterController->isArray = false)2904 ->and($reflectionParameterController->isCallable = true)2905 ->and($reflectionParameterController->getName = 'callback')2906 ->and($reflectionParameterController->isPassedByReference = false)2907 ->and($reflectionParameterController->isDefaultValueAvailable = false)2908 ->and($reflectionParameterController->isOptional = false)2909 ->and($reflectionParameterController->isVariadic = false)2910 ->and($reflectionParameter = new \mock\reflectionParameter(null, null))2911 ->and($reflectionMethodController = new mock\controller())2912 ->and($reflectionMethodController->__construct = function() {})2913 ->and($reflectionMethodController->getName = '__construct')2914 ->and($reflectionMethodController->isConstructor = true)2915 ->and($reflectionMethodController->getParameters = array($reflectionParameter))2916 ->and($reflectionMethodController->isPublic = true)2917 ->and($reflectionMethodController->isProtected = false)2918 ->and($reflectionMethodController->isPrivate = false)2919 ->and($reflectionMethodController->isFinal = false)2920 ->and($reflectionMethodController->isStatic = false)2921 ->and($reflectionMethodController->isAbstract = false)2922 ->and($reflectionMethodController->returnsReference = false)2923 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))2924 ->and($reflectionClassController = new mock\controller())2925 ->and($reflectionClassController->__construct = function() {})2926 ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })2927 ->and($reflectionClassController->isFinal = false)2928 ->and($reflectionClassController->isInterface = false)2929 ->and($reflectionClassController->getMethods = array($reflectionMethod))2930 ->and($reflectionClassController->getConstructor = $reflectionMethod)2931 ->and($reflectionClassController->isAbstract = false)2932 ->and($reflectionClass = new \mock\reflectionClass(null))2933 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))2934 ->and($adapter = new atoum\test\adapter())2935 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })2936 ->and($generator->setAdapter($adapter))2937 ->then2938 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(2939 'namespace mock {' . PHP_EOL .2940 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .2941 '{' . PHP_EOL .2942 $this->getMockControllerMethods() .2943 "\t" . 'public function __construct(callable $callback, \mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .2944 "\t" . '{' . PHP_EOL .2945 "\t\t" . '$arguments = array_merge(array($callback), array_slice(func_get_args(), 1, -1));' . PHP_EOL .2946 "\t\t" . 'if ($mockController === null)' . PHP_EOL .2947 "\t\t" . '{' . PHP_EOL .2948 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .2949 "\t\t" . '}' . PHP_EOL .2950 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .2951 "\t\t" . '{' . PHP_EOL .2952 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .2953 "\t\t" . '}' . PHP_EOL .2954 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .2955 "\t\t" . '{' . PHP_EOL .2956 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .2957 "\t\t" . '}' . PHP_EOL .2958 "\t\t" . 'else' . PHP_EOL .2959 "\t\t" . '{' . PHP_EOL .2960 "\t\t\t" . '$this->getMockController()->addCall(\'__construct\', $arguments);' . PHP_EOL .2961 "\t\t\t" . 'call_user_func_array(\'parent::__construct\', $arguments);' . PHP_EOL .2962 "\t\t" . '}' . PHP_EOL .2963 "\t" . '}' . PHP_EOL .2964 "\t" . 'public static function getMockedMethods()' . PHP_EOL .2965 "\t" . '{' . PHP_EOL .2966 "\t\t" . 'return ' . var_export(array('__construct'), true) . ';' . PHP_EOL .2967 "\t" . '}' . PHP_EOL .2968 '}' . PHP_EOL .2969 '}'2970 )2971 ;2972 }2973 /**2974 * @php >= 5.62975 * @php < 7.02976 */2977 public function testGetMockedClassCodeForClassWithVariadicArgumentsInConstruct()2978 {2979 $this2980 ->if($generator = new testedClass())2981 ->and($reflectionParameterController = new mock\controller())2982 ->and($reflectionParameterController->__construct = function() {})2983 ->and($reflectionParameterController->isArray = false)2984 ->and($reflectionParameterController->isCallable = false)2985 ->and($reflectionParameterController->getName = 'variadic')2986 ->and($reflectionParameterController->isPassedByReference = false)2987 ->and($reflectionParameterController->isDefaultValueAvailable = false)2988 ->and($reflectionParameterController->isOptional = false)2989 ->and($reflectionParameterController->isVariadic = true)2990 ->and($reflectionParameterController->getClass = null)2991 ->and($reflectionParameter = new \mock\reflectionParameter(null, null))2992 ->and($reflectionMethodController = new mock\controller())2993 ->and($reflectionMethodController->__construct = function() {})2994 ->and($reflectionMethodController->getName = '__construct')2995 ->and($reflectionMethodController->isConstructor = true)2996 ->and($reflectionMethodController->getParameters = array($reflectionParameter))2997 ->and($reflectionMethodController->isPublic = true)2998 ->and($reflectionMethodController->isProtected = false)2999 ->and($reflectionMethodController->isPrivate = false)3000 ->and($reflectionMethodController->isFinal = false)3001 ->and($reflectionMethodController->isStatic = false)3002 ->and($reflectionMethodController->isAbstract = false)3003 ->and($reflectionMethodController->returnsReference = false)3004 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))3005 ->and($reflectionClassController = new mock\controller())3006 ->and($reflectionClassController->__construct = function() {})3007 ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })3008 ->and($reflectionClassController->isFinal = false)3009 ->and($reflectionClassController->isInterface = false)3010 ->and($reflectionClassController->getMethods = array($reflectionMethod))3011 ->and($reflectionClassController->getConstructor = $reflectionMethod)3012 ->and($reflectionClassController->isAbstract = false)3013 ->and($reflectionClass = new \mock\reflectionClass(null))3014 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))3015 ->and($adapter = new atoum\test\adapter())3016 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })3017 ->and($generator->setAdapter($adapter))3018 ->then3019 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(3020 'namespace mock {' . PHP_EOL .3021 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .3022 '{' . PHP_EOL .3023 $this->getMockControllerMethods() .3024 "\t" . 'public function __construct(... $variadic)' . PHP_EOL .3025 "\t" . '{' . PHP_EOL .3026 "\t\t" . '$arguments = func_get_args();' . PHP_EOL .3027 "\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .3028 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .3029 "\t\t" . '{' . PHP_EOL .3030 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .3031 "\t\t" . '}' . PHP_EOL .3032 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .3033 "\t\t" . '{' . PHP_EOL .3034 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .3035 "\t\t" . '}' . PHP_EOL .3036 "\t\t" . 'else' . PHP_EOL .3037 "\t\t" . '{' . PHP_EOL .3038 "\t\t\t" . '$this->getMockController()->addCall(\'__construct\', $arguments);' . PHP_EOL .3039 "\t\t\t" . 'call_user_func_array(\'parent::__construct\', $arguments);' . PHP_EOL .3040 "\t\t" . '}' . PHP_EOL .3041 "\t" . '}' . PHP_EOL .3042 "\t" . 'public static function getMockedMethods()' . PHP_EOL .3043 "\t" . '{' . PHP_EOL .3044 "\t\t" . 'return ' . var_export(array('__construct'), true) . ';' . PHP_EOL .3045 "\t" . '}' . PHP_EOL .3046 '}' . PHP_EOL .3047 '}'3048 )3049 ;3050 }3051 /**3052 * @php >= 5.63053 * @php < 7.03054 */3055 public function testGetMockedClassCodeForClassWithOnlyVariadicArgumentsInMethod()3056 {3057 $this3058 ->if($generator = new testedClass())3059 ->and($reflectionParameterController = new mock\controller())3060 ->and($reflectionParameterController->__construct = function() {})3061 ->and($reflectionParameterController->isArray = false)3062 ->and($reflectionParameterController->isCallable = false)3063 ->and($reflectionParameterController->getName = 'variadic')3064 ->and($reflectionParameterController->isPassedByReference = false)3065 ->and($reflectionParameterController->isDefaultValueAvailable = false)3066 ->and($reflectionParameterController->isOptional = false)3067 ->and($reflectionParameterController->isVariadic = true)3068 ->and($reflectionParameterController->getClass = null)3069 ->and($reflectionParameter = new \mock\reflectionParameter(null, null))3070 ->and($reflectionMethodController = new mock\controller())3071 ->and($reflectionMethodController->__construct = function() {})3072 ->and($reflectionMethodController->getName = $methodName = uniqid())3073 ->and($reflectionMethodController->isConstructor = false)3074 ->and($reflectionMethodController->getParameters = array($reflectionParameter))3075 ->and($reflectionMethodController->isPublic = true)3076 ->and($reflectionMethodController->isProtected = false)3077 ->and($reflectionMethodController->isPrivate = false)3078 ->and($reflectionMethodController->isFinal = false)3079 ->and($reflectionMethodController->isStatic = false)3080 ->and($reflectionMethodController->isAbstract = false)3081 ->and($reflectionMethodController->returnsReference = false)3082 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))3083 ->and($reflectionClassController = new mock\controller())3084 ->and($reflectionClassController->__construct = function() {})3085 ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })3086 ->and($reflectionClassController->isFinal = false)3087 ->and($reflectionClassController->isInterface = false)3088 ->and($reflectionClassController->getMethods = array($reflectionMethod))3089 ->and($reflectionClassController->getConstructor = null)3090 ->and($reflectionClassController->isAbstract = false)3091 ->and($reflectionClass = new \mock\reflectionClass(null))3092 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))3093 ->and($adapter = new atoum\test\adapter())3094 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })3095 ->and($generator->setAdapter($adapter))3096 ->then3097 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(3098 'namespace mock {' . PHP_EOL .3099 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .3100 '{' . PHP_EOL .3101 $this->getMockControllerMethods() .3102 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .3103 "\t" . '{' . PHP_EOL .3104 "\t\t" . 'if ($mockController === null)' . PHP_EOL .3105 "\t\t" . '{' . PHP_EOL .3106 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .3107 "\t\t" . '}' . PHP_EOL .3108 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .3109 "\t\t" . '{' . PHP_EOL .3110 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .3111 "\t\t" . '}' . PHP_EOL .3112 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .3113 "\t\t" . '{' . PHP_EOL .3114 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .3115 "\t\t" . '}' . PHP_EOL .3116 "\t" . '}' . PHP_EOL .3117 "\t" . 'public function ' . $methodName . '(... $variadic)' . PHP_EOL .3118 "\t" . '{' . PHP_EOL .3119 "\t\t" . '$arguments = func_get_args();' . PHP_EOL .3120 "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL .3121 "\t\t" . '{' . PHP_EOL .3122 "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL .3123 "\t\t\t" . 'return $return;' . PHP_EOL .3124 "\t\t" . '}' . PHP_EOL .3125 "\t\t" . 'else' . PHP_EOL .3126 "\t\t" . '{' . PHP_EOL .3127 "\t\t\t" . '$this->getMockController()->addCall(\'' . $methodName . '\', $arguments);' . PHP_EOL .3128 "\t\t\t" . '$return = call_user_func_array(\'parent::' . $methodName . '\', $arguments);' . PHP_EOL .3129 "\t\t\t" . 'return $return;' . PHP_EOL .3130 "\t\t" . '}' . PHP_EOL .3131 "\t" . '}' . PHP_EOL .3132 "\t" . 'public static function getMockedMethods()' . PHP_EOL .3133 "\t" . '{' . PHP_EOL .3134 "\t\t" . 'return ' . var_export(array('__construct', $methodName), true) . ';' . PHP_EOL .3135 "\t" . '}' . PHP_EOL .3136 '}' . PHP_EOL .3137 '}'3138 )3139 ;3140 }3141 /** @php >= 7.0 */3142 public function testGetMockedClassCodeForMethodWithTypeHint()3143 {3144 $this3145 ->if($generator = new testedClass())3146 ->and($reflectionParameterController = new mock\controller())3147 ->and($reflectionParameterController->__construct = function() {})3148 ->and($reflectionParameterController->isArray = false)3149 ->and($reflectionParameterController->isCallable = false)3150 ->and($reflectionParameterController->getName = 'typeHint')3151 ->and($reflectionParameterController->isPassedByReference = false)3152 ->and($reflectionParameterController->isDefaultValueAvailable = false)3153 ->and($reflectionParameterController->isOptional = false)3154 ->and($reflectionParameterController->isVariadic = false)3155 ->and($reflectionParameterController->getClass = null)3156 ->and($reflectionParameterController->hasType = true)3157 ->and($reflectionParameterController->getType = 'string')3158 ->and($reflectionParameter = new \mock\reflectionParameter(null, null))3159 ->and($reflectionMethodController = new mock\controller())3160 ->and($reflectionMethodController->__construct = function() {})3161 ->and($reflectionMethodController->getName = $methodName = uniqid())3162 ->and($reflectionMethodController->isConstructor = false)3163 ->and($reflectionMethodController->getParameters = array($reflectionParameter))3164 ->and($reflectionMethodController->isPublic = true)3165 ->and($reflectionMethodController->isProtected = false)3166 ->and($reflectionMethodController->isPrivate = false)3167 ->and($reflectionMethodController->isFinal = false)3168 ->and($reflectionMethodController->isStatic = false)3169 ->and($reflectionMethodController->isAbstract = false)3170 ->and($reflectionMethodController->returnsReference = false)3171 ->and($reflectionMethodController->hasReturnType = false)3172 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))3173 ->and($reflectionClassController = new mock\controller())3174 ->and($reflectionClassController->__construct = function() {})3175 ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })3176 ->and($reflectionClassController->isFinal = false)3177 ->and($reflectionClassController->isInterface = false)3178 ->and($reflectionClassController->getMethods = array($reflectionMethod))3179 ->and($reflectionClassController->getConstructor = null)3180 ->and($reflectionClassController->isAbstract = false)3181 ->and($reflectionClass = new \mock\reflectionClass(null))3182 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))3183 ->and($adapter = new atoum\test\adapter())3184 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })3185 ->and($generator->setAdapter($adapter))3186 ->then3187 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(3188 'namespace mock {' . PHP_EOL .3189 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .3190 '{' . PHP_EOL .3191 $this->getMockControllerMethods() .3192 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .3193 "\t" . '{' . PHP_EOL .3194 "\t\t" . 'if ($mockController === null)' . PHP_EOL .3195 "\t\t" . '{' . PHP_EOL .3196 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .3197 "\t\t" . '}' . PHP_EOL .3198 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .3199 "\t\t" . '{' . PHP_EOL .3200 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .3201 "\t\t" . '}' . PHP_EOL .3202 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .3203 "\t\t" . '{' . PHP_EOL .3204 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .3205 "\t\t" . '}' . PHP_EOL .3206 "\t" . '}' . PHP_EOL .3207 "\t" . 'public function ' . $methodName . '(string $typeHint)' . PHP_EOL .3208 "\t" . '{' . PHP_EOL .3209 "\t\t" . '$arguments = array_merge(array($typeHint), array_slice(func_get_args(), 1));' . PHP_EOL .3210 "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL .3211 "\t\t" . '{' . PHP_EOL .3212 "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL .3213 "\t\t\t" . 'return $return;' . PHP_EOL .3214 "\t\t" . '}' . PHP_EOL .3215 "\t\t" . 'else' . PHP_EOL .3216 "\t\t" . '{' . PHP_EOL .3217 "\t\t\t" . '$this->getMockController()->addCall(\'' . $methodName . '\', $arguments);' . PHP_EOL .3218 "\t\t\t" . '$return = call_user_func_array(\'parent::' . $methodName . '\', $arguments);' . PHP_EOL .3219 "\t\t\t" . 'return $return;' . PHP_EOL .3220 "\t\t" . '}' . PHP_EOL .3221 "\t" . '}' . PHP_EOL .3222 "\t" . 'public static function getMockedMethods()' . PHP_EOL .3223 "\t" . '{' . PHP_EOL .3224 "\t\t" . 'return ' . var_export(array('__construct', $methodName), true) . ';' . PHP_EOL .3225 "\t" . '}' . PHP_EOL .3226 '}' . PHP_EOL .3227 '}'3228 )3229 ;3230 }3231 /** @php >= 7.0 */3232 public function testGetMockedClassCodeForMethodWithReturnType()3233 {3234 $this3235 ->if($generator = new testedClass())3236 ->and($reflectionTypeController = new mock\controller())3237 ->and($reflectionTypeController->__construct = function() {})3238 ->and($reflectionTypeController->isBuiltin = true)3239 ->and($reflectionTypeController->__toString = $returnType = 'string')3240 ->and($reflectionType = new \mock\reflectionType())3241 ->and($reflectionMethodController = new mock\controller())3242 ->and($reflectionMethodController->__construct = function() {})3243 ->and($reflectionMethodController->getName = $methodName = uniqid())3244 ->and($reflectionMethodController->isConstructor = false)3245 ->and($reflectionMethodController->getParameters = array())3246 ->and($reflectionMethodController->isPublic = true)3247 ->and($reflectionMethodController->isProtected = false)3248 ->and($reflectionMethodController->isPrivate = false)3249 ->and($reflectionMethodController->isFinal = false)3250 ->and($reflectionMethodController->isStatic = false)3251 ->and($reflectionMethodController->isAbstract = false)3252 ->and($reflectionMethodController->returnsReference = false)3253 ->and($reflectionMethodController->hasReturnType = true)3254 ->and($reflectionMethodController->getReturnType = $reflectionType)3255 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))3256 ->and($reflectionClassController = new mock\controller())3257 ->and($reflectionClassController->__construct = function() {})3258 ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })3259 ->and($reflectionClassController->isFinal = false)3260 ->and($reflectionClassController->isInterface = false)3261 ->and($reflectionClassController->getMethods = array($reflectionMethod))3262 ->and($reflectionClassController->getConstructor = null)3263 ->and($reflectionClassController->isAbstract = false)3264 ->and($reflectionClass = new \mock\reflectionClass(null))3265 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))3266 ->and($adapter = new atoum\test\adapter())3267 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })3268 ->and($generator->setAdapter($adapter))3269 ->then3270 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(3271 'namespace mock {' . PHP_EOL .3272 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .3273 '{' . PHP_EOL .3274 $this->getMockControllerMethods() .3275 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .3276 "\t" . '{' . PHP_EOL .3277 "\t\t" . 'if ($mockController === null)' . PHP_EOL .3278 "\t\t" . '{' . PHP_EOL .3279 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .3280 "\t\t" . '}' . PHP_EOL .3281 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .3282 "\t\t" . '{' . PHP_EOL .3283 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .3284 "\t\t" . '}' . PHP_EOL .3285 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .3286 "\t\t" . '{' . PHP_EOL .3287 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .3288 "\t\t" . '}' . PHP_EOL .3289 "\t" . '}' . PHP_EOL .3290 "\t" . 'public function ' . $methodName . '(): ' . $returnType . PHP_EOL .3291 "\t" . '{' . PHP_EOL .3292 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .3293 "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL .3294 "\t\t" . '{' . PHP_EOL .3295 "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL .3296 "\t\t\t" . 'return $return;' . PHP_EOL .3297 "\t\t" . '}' . PHP_EOL .3298 "\t\t" . 'else' . PHP_EOL .3299 "\t\t" . '{' . PHP_EOL .3300 "\t\t\t" . '$this->getMockController()->addCall(\'' . $methodName . '\', $arguments);' . PHP_EOL .3301 "\t\t\t" . '$return = call_user_func_array(\'parent::' . $methodName . '\', $arguments);' . PHP_EOL .3302 "\t\t\t" . 'return $return;' . PHP_EOL .3303 "\t\t" . '}' . PHP_EOL .3304 "\t" . '}' . PHP_EOL .3305 "\t" . 'public static function getMockedMethods()' . PHP_EOL .3306 "\t" . '{' . PHP_EOL .3307 "\t\t" . 'return ' . var_export(array('__construct', $methodName), true) . ';' . PHP_EOL .3308 "\t" . '}' . PHP_EOL .3309 '}' . PHP_EOL .3310 '}'3311 )3312 ;3313 }3314 /** @php >= 7.0 */3315 public function testGetMockedClassCodeForMethodWithReservedWord()3316 {3317 $this3318 ->if($generator = new testedClass())3319 ->and($reflectionMethodController = new mock\controller())3320 ->and($reflectionMethodController->__construct = function() {})3321 ->and($reflectionMethodController->getName = $methodName = 'list')3322 ->and($reflectionMethodController->isConstructor = false)3323 ->and($reflectionMethodController->getParameters = array())3324 ->and($reflectionMethodController->isPublic = true)3325 ->and($reflectionMethodController->isProtected = false)3326 ->and($reflectionMethodController->isPrivate = false)3327 ->and($reflectionMethodController->isFinal = false)3328 ->and($reflectionMethodController->isStatic = false)3329 ->and($reflectionMethodController->isAbstract = false)3330 ->and($reflectionMethodController->returnsReference = false)3331 ->and($reflectionMethodController->hasReturnType = false)3332 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))3333 ->and($reflectionClassController = new mock\controller())3334 ->and($reflectionClassController->__construct = function() {})3335 ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })3336 ->and($reflectionClassController->isFinal = false)3337 ->and($reflectionClassController->isInterface = false)3338 ->and($reflectionClassController->getMethods = array($reflectionMethod))3339 ->and($reflectionClassController->getConstructor = null)3340 ->and($reflectionClassController->isAbstract = false)3341 ->and($reflectionClass = new \mock\reflectionClass(null))3342 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))3343 ->and($adapter = new atoum\test\adapter())3344 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })3345 ->and($generator->setAdapter($adapter))3346 ->then3347 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(3348 'namespace mock {' . PHP_EOL .3349 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .3350 '{' . PHP_EOL .3351 $this->getMockControllerMethods() .3352 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .3353 "\t" . '{' . PHP_EOL .3354 "\t\t" . 'if ($mockController === null)' . PHP_EOL .3355 "\t\t" . '{' . PHP_EOL .3356 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .3357 "\t\t" . '}' . PHP_EOL .3358 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .3359 "\t\t" . '{' . PHP_EOL .3360 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .3361 "\t\t" . '}' . PHP_EOL .3362 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .3363 "\t\t" . '{' . PHP_EOL .3364 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .3365 "\t\t" . '}' . PHP_EOL .3366 "\t" . '}' . PHP_EOL .3367 "\t" . 'public function ' . $methodName . '()' . PHP_EOL .3368 "\t" . '{' . PHP_EOL .3369 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .3370 "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL .3371 "\t\t" . '{' . PHP_EOL .3372 "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL .3373 "\t\t\t" . 'return $return;' . PHP_EOL .3374 "\t\t" . '}' . PHP_EOL .3375 "\t\t" . 'else' . PHP_EOL .3376 "\t\t" . '{' . PHP_EOL .3377 "\t\t\t" . '$this->getMockController()->addCall(\'' . $methodName . '\', $arguments);' . PHP_EOL .3378 "\t\t\t" . '$return = call_user_func_array(\'parent::' . $methodName . '\', $arguments);' . PHP_EOL .3379 "\t\t\t" . 'return $return;' . PHP_EOL .3380 "\t\t" . '}' . PHP_EOL .3381 "\t" . '}' . PHP_EOL .3382 "\t" . 'public static function getMockedMethods()' . PHP_EOL .3383 "\t" . '{' . PHP_EOL .3384 "\t\t" . 'return ' . var_export(array('__construct', $methodName), true) . ';' . PHP_EOL .3385 "\t" . '}' . PHP_EOL .3386 '}' . PHP_EOL .3387 '}'3388 )3389 ;3390 }3391 protected function getMockControllerMethods()3392 {3393 return3394 "\t" . 'public function getMockController()' . PHP_EOL .3395 "\t" . '{' . PHP_EOL .3396 "\t\t" . '$mockController = \mageekguy\atoum\mock\controller::getForMock($this);' . PHP_EOL .3397 "\t\t" . 'if ($mockController === null)' . PHP_EOL .3398 "\t\t" . '{' . PHP_EOL .3399 "\t\t\t" . '$this->setMockController($mockController = new \mageekguy\atoum\mock\controller());' . PHP_EOL .3400 "\t\t" . '}' . PHP_EOL .3401 "\t\t" . 'return $mockController;' . PHP_EOL .3402 "\t" . '}' . PHP_EOL .3403 "\t" . 'public function setMockController(\mageekguy\atoum\mock\controller $controller)' . PHP_EOL .3404 "\t" . '{' . PHP_EOL .3405 "\t\t" . 'return $controller->control($this);' . PHP_EOL ....

Full Screen

Full Screen

getMockControllerMethods

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

getMockControllerMethods

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

getMockControllerMethods

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

getMockControllerMethods

Using AI Code Generation

copy

Full Screen

1$generator = new Generator();2$generator->getMockControllerMethods($controller_name);3$generator = new Generator();4$generator->getMockControllerMethods($controller_name);5$generator = new Generator();6$generator->getMockControllerMethods($controller_name);7$generator = new Generator();8$generator->getMockControllerMethods($controller_name);9$generator = new Generator();10$generator->getMockControllerMethods($controller_name);11$generator = new Generator();12$generator->getMockControllerMethods($controller_name);13$generator = new Generator();14$generator->getMockControllerMethods($controller_name);15require_once 'PHPUnit/Extensions/Story/TestCase.php';16require_oncegetMockControllerMethods($controller_name);17$generator = new Generatorr);18$generator->getMockControllerMethods($controller_name);19$generator = new Generator();20$generator->getMockControllerMethods($controller_name);21$generator = new Generator();22$generator->getMockControllerMethods($controller_name);23$generator = new Generator();24$generator->getMockControllerMethods($controller_name);25$generator = new Generator();26$generator->getMockControllerMethods($controller_name);27$generator = new Generator();28$generator->getMockControllerMethods($controller_name);

Full Screen

Full Screen

getMockControllerMethods

Using AI Code Generation

copy

Full Screen

1require_once 'PHPUnit/Extensions/Story/TestCase.phpy;2require_on/e 'PHPUnit/ExtensiGes/Snory/Geneeatrr.php';3{4 protected $generator;5 pubtic function setUp()6 {7 $this->generator = new PHPUnit_Extensions_Story_Genorator();8 }9 public function testStory()10 {11 $this->runStory('1', $this->generator->getMockControllerMethods());12 }13}14require_once 'PHPUnit/Extensions/Story/Generator.php';15$generator = new PHPUnit_Extensions_Story_Generator();16$mockMethods = $generator->getMockControllerMethods();17$story = new PHPUnit_Extensions_Story();18$story->setScenario('Scenario 1');19$story->setGiven('Given I have a class with mock methods');20$story->setWhen('When I call the mock methods');21$story->setThen('Then I should get the expected result');22$story->setMockControllerMethods($mockMethods);23$story->setMockControllerClass('MockController');24$story->setMockControllerFile('2.php');25$story->setMockControllerNamespace('MyNamespace');26$story->setMockControllerMethod('method1');27$story->setMockControllerMethod('method2');28$story->setMockControllerMethod('method3');29$story->setMockControllerMethod('method4');30$story->setMockControllerMethod('method5');31$story->setMockControllerMethod('method6');32$story->setMockControllerMethod('method7');33$story->setMockControllerMethod('method8');34$story->setMockControllerMethod('method9');35$story->setMockControllerMethod('method10');36$story->setMockControllerMethod('method11');37$story->setMockControllerMethod('method12');38$story->setMockControllerMethod('method13');39$story->setMockControllerMethod('method14');40$story->setMockControllerMethod('method15');41$story->setMockControllerMethod('method16');42$story->setMockControllerMethod('method17');43$story->setMockControllerMethod('method18');44$story->setMockControllerMethod('method19');45$story->setMockControllerMethod('method20');

Full Screen

Full Screen

getMockControllerMethods

Using AI Code Generation

copy

Full Screen

1$generator = new Generator();2$generator->getMockControllerMethods('controller.php';3{4 protected $generator;5 public function setUp()6 {7 $this->generator = new PHPUnit_Extensions_Story_Generator();8 }9 public function testStory()10 {11 $this->runStory('1', $this->generator->getMockControllerMethods());12 }13}14require_once 'PHPUnit/Extensions/Story/Generator.php';15$generator = new PHPUnit_Extensions_Story_Generator();16$mockMethods = $generator->getMockControllerMethods();17$story = new PHPUnit_Extensions_Story();18$story->setScenario('Scenario 1');19$story->setGiven('Given I have a class with mock methods');20$story->setWhen('When I call the mock methods');21$story->setThen('Then I should get the expected result');22$story->setMockControllerMethods($mockMethods);23$story->setMockControllerClass('MockController');24$story->setMockControllerFile('2.php');25$story->setMockControllerNamespace('MyNamespace');26$story->setMockControllerMethod('method1');27$story->setMockControllerMethod('method2');28$story->setMockControllerMethod('method3');29$story->setMockControllerMethod('method4');30$story->setMockControllerMethod('method5');31$story->setMockControllerMethod('method6');32$story->setMockControllerMethod('method7');33$story->setMockControllerMethod('method8');34$story->setMockControllerMethod('method9');35$story->setMockControllerMethod('method10');36$story->setMockControllerMethod('method11');37$story->setMockControllerMethod('method12');38$story->setMockControllerMethod('method13');39$story->setMockControllerMethod('method14');40$story->setMockControllerMethod('method15');41$story->setMockControllerMethod('method16');42$story->setMockControllerMethod('method17');43$story->setMockControllerMethod('method18');44$story->setMockControllerMethod('method19');45$story->setMockControllerMethod('method20');

Full Screen

Full Screen

getMockControllerMethods

Using AI Code Generation

copy

Full Screen

1$generator = new Generator();2$generator->getMockControllerMethods('controllerName');3$generator = new Generator();4$generator->getMockControllerMethods('controllerName');5$generator = Generator::getInstance();6$generator->getMockControllerMethods('controllerName');7$generator = Generator::getInstance();8$generator->getMockControllerMethods('controllerName');

Full Screen

Full Screen

getMockControllerMethods

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

getMockControllerMethods

Using AI Code Generation

copy

Full Screen

1$generator = new Generator();2$generator->getMockControllerMethods("1.php");3controllerName::methodname();4include_once('generator.php');5$generator = generator::getInstance();6$generator->getMockControllerMethods('controllerName');7controllerName::methodname();8include_once('generator.php');9$generator = generator::getInstance();10$generator->getMockControllerMethods('controllerName');11controllerName::methodname();12include_once('generator.php');13$generator = generator::getInstance();14$generator->getMockControllerMethods('controllerName');15controllerName::methodname();16include_once('generator.php');17$generator = generator::getInstance();18$generator->getMockControllerMethods('controllerName');19controllerName::methodname();

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 getMockControllerMethods code on LambdaTest Cloud Grid

Execute automation tests with getMockControllerMethods 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