How to use getMockedMethods method of generator class

Best Atoum code snippet using generator.getMockedMethods

generator.php

Source:generator.php Github

copy

Full Screen

...199 "\t\t" . '{' . PHP_EOL .200 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .201 "\t\t" . '}' . PHP_EOL .202 "\t" . '}' . PHP_EOL .203 "\t" . 'public static function getMockedMethods()' . PHP_EOL .204 "\t" . '{' . PHP_EOL .205 "\t\t" . 'return ' . var_export(['__call'], true) . ';' . PHP_EOL .206 "\t" . '}' . PHP_EOL .207 '}' . PHP_EOL .208 '}'209 )210 ->if($unknownClass = __NAMESPACE__ . '\dummy')211 ->and($generator->generate($unknownClass))212 ->and($mockedUnknownClass = '\mock\\' . $unknownClass)213 ->and($dummy = new $mockedUnknownClass())214 ->and($dummyController = new atoum\mock\controller())215 ->and($dummyController->notControlNextNewMock())216 ->and($calls = new \mock\mageekguy\atoum\test\adapter\calls())217 ->and($dummyController->setCalls($calls))218 ->and($dummyController->control($dummy))219 ->then220 ->when(function () use ($dummy) {221 $dummy->bar();222 })223 ->mock($calls)->call('addCall')->withArguments(new atoum\test\adapter\call('bar', [], new decorators\addClass($dummy)))->once()224 ->when(function () use ($dummy) {225 $dummy->bar();226 })227 ->mock($calls)->call('addCall')->withArguments(new atoum\test\adapter\call('bar', [], new decorators\addClass($dummy)))->twice()228 ;229 }230 public function testGetMockedClassCodeForRealClass()231 {232 $this233 ->if($generator = new testedClass())234 ->and($reflectionMethodController = new mock\controller())235 ->and($reflectionMethodController->__construct = function () {236 })237 ->and($reflectionMethodController->getName = '__construct')238 ->and($reflectionMethodController->isConstructor = true)239 ->and($reflectionMethodController->getParameters = [])240 ->and($reflectionMethodController->isPublic = true)241 ->and($reflectionMethodController->isProtected = false)242 ->and($reflectionMethodController->isPrivate = false)243 ->and($reflectionMethodController->isFinal = false)244 ->and($reflectionMethodController->isStatic = false)245 ->and($reflectionMethodController->isAbstract = false)246 ->and($reflectionMethodController->returnsReference = false)247 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))248 ->and($reflectionClassController = new mock\controller())249 ->and($reflectionClassController->__construct = function () {250 })251 ->and($reflectionClassController->getName = function () use (& $realClass) {252 return $realClass;253 })254 ->and($reflectionClassController->isFinal = false)255 ->and($reflectionClassController->isInterface = false)256 ->and($reflectionClassController->isAbstract = false)257 ->and($reflectionClassController->getMethods = [$reflectionMethod])258 ->and($reflectionClassController->getConstructor = $reflectionMethod)259 ->and($reflectionClass = new \mock\reflectionClass(null))260 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {261 return $reflectionClass;262 }))263 ->and($adapter = new atoum\test\adapter())264 ->and($adapter->class_exists = function ($class) use (& $realClass) {265 return ($class == '\\' . $realClass);266 })267 ->and($generator->setAdapter($adapter))268 ->then269 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(270 'namespace mock {' . PHP_EOL .271 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .272 '{' . PHP_EOL .273 $this->getMockControllerMethods() .274 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .275 "\t" . '{' . PHP_EOL .276 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .277 "\t\t" . 'if ($mockController === null)' . PHP_EOL .278 "\t\t" . '{' . PHP_EOL .279 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .280 "\t\t" . '}' . PHP_EOL .281 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .282 "\t\t" . '{' . PHP_EOL .283 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .284 "\t\t" . '}' . PHP_EOL .285 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .286 "\t\t" . '{' . PHP_EOL .287 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .288 "\t\t" . '}' . PHP_EOL .289 "\t\t" . 'else' . PHP_EOL .290 "\t\t" . '{' . PHP_EOL .291 "\t\t\t" . '$this->getMockController()->addCall(\'__construct\', $arguments);' . PHP_EOL .292 "\t\t\t" . 'call_user_func_array(\'parent::__construct\', $arguments);' . PHP_EOL .293 "\t\t" . '}' . PHP_EOL .294 "\t" . '}' . PHP_EOL .295 "\t" . 'public static function getMockedMethods()' . PHP_EOL .296 "\t" . '{' . PHP_EOL .297 "\t\t" . 'return ' . var_export(['__construct'], true) . ';' . PHP_EOL .298 "\t" . '}' . PHP_EOL .299 '}' . PHP_EOL .300 '}'301 )302 ;303 }304 public function testGetMockedClassCodeForRealClassWithDeprecatedConstructor()305 {306 $this307 ->if($generator = new testedClass())308 ->and($reflectionMethodController = new mock\controller())309 ->and($reflectionMethodController->__construct = function () {310 })311 ->and($reflectionMethodController->getName = $realClass = uniqid())312 ->and($reflectionMethodController->isConstructor = true)313 ->and($reflectionMethodController->getParameters = [])314 ->and($reflectionMethodController->isPublic = true)315 ->and($reflectionMethodController->isProtected = false)316 ->and($reflectionMethodController->isPrivate = false)317 ->and($reflectionMethodController->isFinal = false)318 ->and($reflectionMethodController->isStatic = false)319 ->and($reflectionMethodController->isAbstract = false)320 ->and($reflectionMethodController->returnsReference = false)321 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))322 ->and($reflectionClassController = new mock\controller())323 ->and($reflectionClassController->__construct = function () {324 })325 ->and($reflectionClassController->getName = $realClass)326 ->and($reflectionClassController->isFinal = false)327 ->and($reflectionClassController->isInterface = false)328 ->and($reflectionClassController->isAbstract = false)329 ->and($reflectionClassController->getMethods = [$reflectionMethod])330 ->and($reflectionClassController->getConstructor = $reflectionMethod)331 ->and($reflectionClass = new \mock\reflectionClass(null))332 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {333 return $reflectionClass;334 }))335 ->and($adapter = new atoum\test\adapter())336 ->and($adapter->class_exists = function ($class) use (& $realClass) {337 return ($class == '\\' . $realClass);338 })339 ->and($generator->setAdapter($adapter))340 ->then341 ->string($generator->getMockedClassCode($realClass))->isEqualTo(342 'namespace mock {' . PHP_EOL .343 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .344 '{' . PHP_EOL .345 $this->getMockControllerMethods() .346 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .347 "\t" . '{' . PHP_EOL .348 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .349 "\t\t" . 'if ($mockController === null)' . PHP_EOL .350 "\t\t" . '{' . PHP_EOL .351 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .352 "\t\t" . '}' . PHP_EOL .353 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .354 "\t\t" . '{' . PHP_EOL .355 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .356 "\t\t" . '}' . PHP_EOL .357 "\t\t" . 'if (isset($this->getMockController()->' . $realClass . ') === true)' . PHP_EOL .358 "\t\t" . '{' . PHP_EOL .359 "\t\t\t" . '$this->getMockController()->invoke(\'' . $realClass . '\', $arguments);' . PHP_EOL .360 "\t\t" . '}' . PHP_EOL .361 "\t\t" . 'else' . PHP_EOL .362 "\t\t" . '{' . PHP_EOL .363 "\t\t\t" . '$this->getMockController()->addCall(\'' . $realClass . '\', $arguments);' . PHP_EOL .364 "\t\t\t" . 'call_user_func_array(\'parent::' . $realClass . '\', $arguments);' . PHP_EOL .365 "\t\t" . '}' . PHP_EOL .366 "\t" . '}' . PHP_EOL .367 "\t" . 'public static function getMockedMethods()' . PHP_EOL .368 "\t" . '{' . PHP_EOL .369 "\t\t" . 'return ' . var_export([$realClass], true) . ';' . PHP_EOL .370 "\t" . '}' . PHP_EOL .371 '}' . PHP_EOL .372 '}'373 )374 ;375 }376 /** @php < 7.0 */377 public function testGetMockedClassCodeForRealClassWithCallsToParentClassShunted()378 {379 $this380 ->if($generator = new testedClass())381 ->and($reflectionMethodController = new mock\controller())382 ->and($reflectionMethodController->__construct = function () {383 })384 ->and($reflectionMethodController->getName = '__construct')385 ->and($reflectionMethodController->isConstructor = true)386 ->and($reflectionMethodController->getParameters = [])387 ->and($reflectionMethodController->isPublic = true)388 ->and($reflectionMethodController->isProtected = false)389 ->and($reflectionMethodController->isPrivate = false)390 ->and($reflectionMethodController->isFinal = false)391 ->and($reflectionMethodController->isStatic = false)392 ->and($reflectionMethodController->isAbstract = false)393 ->and($reflectionMethodController->returnsReference = false)394 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))395 ->and($otherReflectionMethodController = new mock\controller())396 ->and($otherReflectionMethodController->__construct = function () {397 })398 ->and($otherReflectionMethodController->getName = $otherMethod = uniqid())399 ->and($otherReflectionMethodController->isConstructor = false)400 ->and($otherReflectionMethodController->getParameters = [])401 ->and($otherReflectionMethodController->isPublic = true)402 ->and($otherReflectionMethodController->isProtected = false)403 ->and($otherReflectionMethodController->isPrivate = false)404 ->and($otherReflectionMethodController->isFinal = false)405 ->and($otherReflectionMethodController->isStatic = false)406 ->and($otherReflectionMethodController->isAbstract = false)407 ->and($otherReflectionMethodController->returnsReference = false)408 ->and($otherReflectionMethod = new \mock\reflectionMethod(null, null))409 ->and($reflectionClassController = new mock\controller())410 ->and($reflectionClassController->__construct = function () {411 })412 ->and($reflectionClassController->getName = function () use (& $realClass) {413 return $realClass;414 })415 ->and($reflectionClassController->isFinal = false)416 ->and($reflectionClassController->isInterface = false)417 ->and($reflectionClassController->isAbstract = false)418 ->and($reflectionClassController->getMethods = [$reflectionMethod, $otherReflectionMethod])419 ->and($reflectionClassController->getConstructor = $reflectionMethod)420 ->and($reflectionClass = new \mock\reflectionClass(null))421 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {422 return $reflectionClass;423 }))424 ->and($adapter = new atoum\test\adapter())425 ->and($adapter->class_exists = function ($class) use (& $realClass) {426 return ($class == '\\' . $realClass);427 })428 ->and($generator->setAdapter($adapter))429 ->and($generator->shuntParentClassCalls())430 ->then431 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(432 'namespace mock {' . PHP_EOL .433 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .434 '{' . PHP_EOL .435 $this->getMockControllerMethods() .436 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .437 "\t" . '{' . PHP_EOL .438 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .439 "\t\t" . 'if ($mockController === null)' . PHP_EOL .440 "\t\t" . '{' . PHP_EOL .441 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .442 "\t\t" . '}' . PHP_EOL .443 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .444 "\t\t" . '{' . PHP_EOL .445 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .446 "\t\t" . '}' . PHP_EOL .447 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .448 "\t\t" . '{' . PHP_EOL .449 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .450 "\t\t" . '}' . PHP_EOL .451 "\t\t" . 'else' . PHP_EOL .452 "\t\t" . '{' . PHP_EOL .453 "\t\t\t" . '$this->getMockController()->addCall(\'__construct\', $arguments);' . PHP_EOL .454 "\t\t" . '}' . PHP_EOL .455 "\t" . '}' . PHP_EOL .456 "\t" . 'public function ' . $otherMethod . '()' . PHP_EOL .457 "\t" . '{' . PHP_EOL .458 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .459 "\t\t" . 'if (isset($this->getMockController()->' . $otherMethod . ') === true)' . PHP_EOL .460 "\t\t" . '{' . PHP_EOL .461 "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $otherMethod . '\', $arguments);' . PHP_EOL .462 "\t\t\t" . 'return $return;' . PHP_EOL .463 "\t\t" . '}' . PHP_EOL .464 "\t\t" . 'else' . PHP_EOL .465 "\t\t" . '{' . PHP_EOL .466 "\t\t\t" . '$this->getMockController()->addCall(\'' . $otherMethod . '\', $arguments);' . PHP_EOL .467 "\t\t" . '}' . PHP_EOL .468 "\t" . '}' . PHP_EOL .469 "\t" . 'public static function getMockedMethods()' . PHP_EOL .470 "\t" . '{' . PHP_EOL .471 "\t\t" . 'return ' . var_export(['__construct', $otherMethod], true) . ';' . PHP_EOL .472 "\t" . '}' . PHP_EOL .473 '}' . PHP_EOL .474 '}'475 )476 ;477 }478 /** @php >= 7.0 */479 public function testGetMockedClassCodeForRealClassWithCallsToParentClassShuntedPhp7()480 {481 $this482 ->if($generator = new testedClass())483 ->and($reflectionMethodController = new mock\controller())484 ->and($reflectionMethodController->__construct = function () {485 })486 ->and($reflectionMethodController->getName = '__construct')487 ->and($reflectionMethodController->isConstructor = true)488 ->and($reflectionMethodController->getParameters = [])489 ->and($reflectionMethodController->isPublic = true)490 ->and($reflectionMethodController->isProtected = false)491 ->and($reflectionMethodController->isPrivate = false)492 ->and($reflectionMethodController->isFinal = false)493 ->and($reflectionMethodController->isStatic = false)494 ->and($reflectionMethodController->isAbstract = false)495 ->and($reflectionMethodController->returnsReference = false)496 ->and($reflectionMethodController->hasReturnType = false)497 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))498 ->and($otherReflectionMethodController = new mock\controller())499 ->and($otherReflectionMethodController->__construct = function () {500 })501 ->and($otherReflectionMethodController->getName = $otherMethod = uniqid())502 ->and($otherReflectionMethodController->isConstructor = false)503 ->and($otherReflectionMethodController->getParameters = [])504 ->and($otherReflectionMethodController->isPublic = true)505 ->and($otherReflectionMethodController->isProtected = false)506 ->and($otherReflectionMethodController->isPrivate = false)507 ->and($otherReflectionMethodController->isFinal = false)508 ->and($otherReflectionMethodController->isStatic = false)509 ->and($otherReflectionMethodController->isAbstract = false)510 ->and($otherReflectionMethodController->returnsReference = false)511 ->and($otherReflectionMethodController->hasReturnType = false)512 ->and($otherReflectionMethod = new \mock\reflectionMethod(null, null))513 ->and($reflectionClassController = new mock\controller())514 ->and($reflectionClassController->__construct = function () {515 })516 ->and($reflectionClassController->getName = function () use (& $realClass) {517 return $realClass;518 })519 ->and($reflectionClassController->isFinal = false)520 ->and($reflectionClassController->isInterface = false)521 ->and($reflectionClassController->isAbstract = false)522 ->and($reflectionClassController->getMethods = [$reflectionMethod, $otherReflectionMethod])523 ->and($reflectionClassController->getConstructor = $reflectionMethod)524 ->and($reflectionClass = new \mock\reflectionClass(null))525 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {526 return $reflectionClass;527 }))528 ->and($adapter = new atoum\test\adapter())529 ->and($adapter->class_exists = function ($class) use (& $realClass) {530 return ($class == '\\' . $realClass);531 })532 ->and($generator->setAdapter($adapter))533 ->and($generator->shuntParentClassCalls())534 ->then535 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(536 'namespace mock {' . PHP_EOL .537 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .538 '{' . PHP_EOL .539 $this->getMockControllerMethods() .540 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .541 "\t" . '{' . PHP_EOL .542 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .543 "\t\t" . 'if ($mockController === null)' . PHP_EOL .544 "\t\t" . '{' . PHP_EOL .545 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .546 "\t\t" . '}' . PHP_EOL .547 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .548 "\t\t" . '{' . PHP_EOL .549 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .550 "\t\t" . '}' . PHP_EOL .551 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .552 "\t\t" . '{' . PHP_EOL .553 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .554 "\t\t" . '}' . PHP_EOL .555 "\t\t" . 'else' . PHP_EOL .556 "\t\t" . '{' . PHP_EOL .557 "\t\t\t" . '$this->getMockController()->addCall(\'__construct\', $arguments);' . PHP_EOL .558 "\t\t" . '}' . PHP_EOL .559 "\t" . '}' . PHP_EOL .560 "\t" . 'public function ' . $otherMethod . '()' . PHP_EOL .561 "\t" . '{' . PHP_EOL .562 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .563 "\t\t" . 'if (isset($this->getMockController()->' . $otherMethod . ') === true)' . PHP_EOL .564 "\t\t" . '{' . PHP_EOL .565 "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $otherMethod . '\', $arguments);' . PHP_EOL .566 "\t\t\t" . 'return $return;' . PHP_EOL .567 "\t\t" . '}' . PHP_EOL .568 "\t\t" . 'else' . PHP_EOL .569 "\t\t" . '{' . PHP_EOL .570 "\t\t\t" . '$this->getMockController()->addCall(\'' . $otherMethod . '\', $arguments);' . PHP_EOL .571 "\t\t" . '}' . PHP_EOL .572 "\t" . '}' . PHP_EOL .573 "\t" . 'public static function getMockedMethods()' . PHP_EOL .574 "\t" . '{' . PHP_EOL .575 "\t\t" . 'return ' . var_export(['__construct', $otherMethod], true) . ';' . PHP_EOL .576 "\t" . '}' . PHP_EOL .577 '}' . PHP_EOL .578 '}'579 )580 ;581 }582 public function testGetMockedClassCodeWithOverloadMethod()583 {584 $this585 ->if($generator = new testedClass())586 ->and($reflectionMethodController = new mock\controller())587 ->and($reflectionMethodController->__construct = function () {588 })589 ->and($reflectionMethodController->getName = '__construct')590 ->and($reflectionMethodController->isConstructor = true)591 ->and($reflectionMethodController->getParameters = [])592 ->and($reflectionMethodController->isPublic = true)593 ->and($reflectionMethodController->isProtected = false)594 ->and($reflectionMethodController->isPrivate = false)595 ->and($reflectionMethodController->isFinal = false)596 ->and($reflectionMethodController->isAbstract = false)597 ->and($reflectionMethodController->isStatic = false)598 ->and($reflectionMethodController->returnsReference = false)599 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))600 ->and($reflectionClassController = new mock\controller())601 ->and($reflectionClassController->__construct = function () {602 })603 ->and($reflectionClassController->getName = function () use (& $realClass) {604 return $realClass;605 })606 ->and($reflectionClassController->isFinal = false)607 ->and($reflectionClassController->isInterface = false)608 ->and($reflectionClassController->getMethods = [$reflectionMethod])609 ->and($reflectionClassController->getConstructor = $reflectionMethod)610 ->and($reflectionClassController->isAbstract = false)611 ->and($reflectionClass = new \mock\reflectionClass(null))612 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {613 return $reflectionClass;614 }))615 ->and($adapter = new atoum\test\adapter())616 ->and($adapter->class_exists = function ($class) use (& $realClass) {617 return ($class == '\\' . $realClass);618 })619 ->and($generator->setAdapter($adapter))620 ->and($overloadedMethod = new mock\php\method('__construct'))621 ->and($overloadedMethod->addArgument($argument = new mock\php\method\argument(uniqid())))622 ->and($generator->overload($overloadedMethod))623 ->then624 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(625 'namespace mock {' . PHP_EOL .626 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .627 '{' . PHP_EOL .628 $this->getMockControllerMethods() .629 "\t" . '' . $overloadedMethod . PHP_EOL .630 "\t" . '{' . PHP_EOL .631 "\t\t" . '$arguments = array_merge(array(' . $argument . '), array_slice(func_get_args(), 1, -1));' . PHP_EOL .632 "\t\t" . 'if ($mockController === null)' . PHP_EOL .633 "\t\t" . '{' . PHP_EOL .634 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .635 "\t\t" . '}' . PHP_EOL .636 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .637 "\t\t" . '{' . PHP_EOL .638 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .639 "\t\t" . '}' . PHP_EOL .640 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .641 "\t\t" . '{' . PHP_EOL .642 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .643 "\t\t" . '}' . PHP_EOL .644 "\t\t" . 'else' . PHP_EOL .645 "\t\t" . '{' . PHP_EOL .646 "\t\t\t" . '$this->getMockController()->addCall(\'__construct\', $arguments);' . PHP_EOL .647 "\t\t\t" . 'call_user_func_array(\'parent::__construct\', $arguments);' . PHP_EOL .648 "\t\t" . '}' . PHP_EOL .649 "\t" . '}' . PHP_EOL .650 "\t" . 'public static function getMockedMethods()' . PHP_EOL .651 "\t" . '{' . PHP_EOL .652 "\t\t" . 'return ' . var_export(['__construct'], true) . ';' . PHP_EOL .653 "\t" . '}' . PHP_EOL .654 '}' . PHP_EOL .655 '}'656 )657 ;658 }659 public function testGetMockedClassCodeWithAbstractMethod()660 {661 $this662 ->if($generator = new testedClass())663 ->and($realClass = uniqid())664 ->and($reflectionMethodController = new mock\controller())665 ->and($reflectionMethodController->__construct = function () {666 })667 ->and($reflectionMethodController->getName = function () {668 return '__construct';669 })670 ->and($reflectionMethodController->isConstructor = true)671 ->and($reflectionMethodController->getParameters = [])672 ->and($reflectionMethodController->isPublic = true)673 ->and($reflectionMethodController->isProtected = false)674 ->and($reflectionMethodController->isPrivate = false)675 ->and($reflectionMethodController->isFinal = false)676 ->and($reflectionMethodController->isStatic = false)677 ->and($reflectionMethodController->isAbstract = true)678 ->and($reflectionMethodController->returnsReference = false)679 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))680 ->and($reflectionClassController = new mock\controller())681 ->and($reflectionClassController->__construct = function () {682 })683 ->and($reflectionClassController->getName = function () use ($realClass) {684 return $realClass;685 })686 ->and($reflectionClassController->isFinal = false)687 ->and($reflectionClassController->isInterface = false)688 ->and($reflectionClassController->getMethods = [$reflectionMethod])689 ->and($reflectionClassController->getConstructor = $reflectionMethod)690 ->and($reflectionClassController->isAbstract = false)691 ->and($reflectionClass = new \mock\reflectionClass(null))692 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {693 return $reflectionClass;694 }))695 ->and($adapter = new atoum\test\adapter())696 ->and($adapter->class_exists = function ($class) use ($realClass) {697 return ($class == '\\' . $realClass);698 })699 ->and($generator->setAdapter($adapter))700 ->then701 ->string($generator->getMockedClassCode($realClass))->isEqualTo(702 'namespace mock {' . PHP_EOL .703 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .704 '{' . PHP_EOL .705 $this->getMockControllerMethods() .706 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .707 "\t" . '{' . PHP_EOL .708 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .709 "\t\t" . 'if ($mockController === null)' . PHP_EOL .710 "\t\t" . '{' . PHP_EOL .711 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .712 "\t\t" . '}' . PHP_EOL .713 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .714 "\t\t" . '{' . PHP_EOL .715 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .716 "\t\t" . '}' . PHP_EOL .717 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .718 "\t\t" . '{' . PHP_EOL .719 "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .720 "\t\t" . '}' . PHP_EOL .721 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .722 "\t" . '}' . PHP_EOL .723 "\t" . 'public static function getMockedMethods()' . PHP_EOL .724 "\t" . '{' . PHP_EOL .725 "\t\t" . 'return ' . var_export(['__construct'], true) . ';' . PHP_EOL .726 "\t" . '}' . PHP_EOL .727 '}' . PHP_EOL .728 '}'729 )730 ;731 }732 public function testGetMockedClassCodeWithShuntedMethod()733 {734 $this735 ->if($generator = new testedClass())736 ->and($realClass = uniqid())737 ->and($reflectionMethodController = new mock\controller())738 ->and($reflectionMethodController->__construct = function () {739 })740 ->and($reflectionMethodController->getName = function () {741 return '__construct';742 })743 ->and($reflectionMethodController->isConstructor = true)744 ->and($reflectionMethodController->isAbstract = false)745 ->and($reflectionMethodController->getParameters = [])746 ->and($reflectionMethodController->isPublic = true)747 ->and($reflectionMethodController->isProtected = false)748 ->and($reflectionMethodController->isPrivate = false)749 ->and($reflectionMethodController->isFinal = false)750 ->and($reflectionMethodController->isStatic = false)751 ->and($reflectionMethodController->returnsReference = false)752 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))753 ->and($reflectionClassController = new mock\controller())754 ->and($reflectionClassController->__construct = function () {755 })756 ->and($reflectionClassController->getName = function () use ($realClass) {757 return $realClass;758 })759 ->and($reflectionClassController->isFinal = false)760 ->and($reflectionClassController->isInterface = false)761 ->and($reflectionClassController->getMethods = [$reflectionMethod])762 ->and($reflectionClassController->getConstructor = $reflectionMethod)763 ->and($reflectionClassController->isAbstract = false)764 ->and($reflectionClass = new \mock\reflectionClass(null))765 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {766 return $reflectionClass;767 }))768 ->and($adapter = new atoum\test\adapter())769 ->and($adapter->class_exists = function ($class) use ($realClass) {770 return ($class == '\\' . $realClass);771 })772 ->and($generator->setAdapter($adapter))773 ->and($generator->shunt('__construct'))774 ->then775 ->string($generator->getMockedClassCode($realClass))->isEqualTo(776 'namespace mock {' . PHP_EOL .777 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .778 '{' . PHP_EOL .779 $this->getMockControllerMethods() .780 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .781 "\t" . '{' . PHP_EOL .782 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .783 "\t\t" . 'if ($mockController === null)' . PHP_EOL .784 "\t\t" . '{' . PHP_EOL .785 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .786 "\t\t" . '}' . PHP_EOL .787 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .788 "\t\t" . '{' . PHP_EOL .789 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .790 "\t\t" . '}' . PHP_EOL .791 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .792 "\t\t" . '{' . PHP_EOL .793 "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .794 "\t\t" . '}' . PHP_EOL .795 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .796 "\t" . '}' . PHP_EOL .797 "\t" . 'public static function getMockedMethods()' . PHP_EOL .798 "\t" . '{' . PHP_EOL .799 "\t\t" . 'return ' . var_export(['__construct'], true) . ';' . PHP_EOL .800 "\t" . '}' . PHP_EOL .801 '}' . PHP_EOL .802 '}'803 )804 ;805 }806 /** @php < 7.0 */807 public function testGetMockedClassCodeWithAllIsInterface()808 {809 $this810 ->if($generator = new testedClass())811 ->and($realClass = uniqid())812 ->and($reflectionMethodController = new mock\controller())813 ->and($reflectionMethodController->__construct = function () {814 })815 ->and($reflectionMethodController->getName = 'foo')816 ->and($reflectionMethodController->isConstructor = false)817 ->and($reflectionMethodController->getParameters = [])818 ->and($reflectionMethodController->isPublic = true)819 ->and($reflectionMethodController->isProtected = false)820 ->and($reflectionMethodController->isPrivate = false)821 ->and($reflectionMethodController->isFinal = false)822 ->and($reflectionMethodController->isAbstract = false)823 ->and($reflectionMethodController->isStatic = false)824 ->and($reflectionMethodController->returnsReference = false)825 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))826 ->and($reflectionClassController = new mock\controller())827 ->and($reflectionClassController->__construct = function () {828 })829 ->and($reflectionClassController->getName = function () use ($realClass) {830 return $realClass;831 })832 ->and($reflectionClassController->isFinal = false)833 ->and($reflectionClassController->isInterface = false)834 ->and($reflectionClassController->getMethods = [$reflectionMethod])835 ->and($reflectionClassController->getConstructor = null)836 ->and($reflectionClassController->isAbstract = false)837 ->and($reflectionClass = new \mock\reflectionClass(null))838 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {839 return $reflectionClass;840 }))841 ->and($adapter = new atoum\test\adapter())842 ->and($adapter->class_exists = function ($class) use ($realClass) {843 return ($class == '\\' . $realClass);844 })845 ->and($generator->setAdapter($adapter))846 ->and($generator->shunt('__construct'))847 ->and($generator->allIsInterface())848 ->then849 ->string($generator->getMockedClassCode($realClass))->isEqualTo(850 'namespace mock {' . PHP_EOL .851 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .852 '{' . PHP_EOL .853 $this->getMockControllerMethods() .854 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .855 "\t" . '{' . PHP_EOL .856 "\t\t" . 'if ($mockController === null)' . PHP_EOL .857 "\t\t" . '{' . PHP_EOL .858 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .859 "\t\t" . '}' . PHP_EOL .860 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .861 "\t\t" . '{' . PHP_EOL .862 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .863 "\t\t" . '}' . PHP_EOL .864 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .865 "\t\t" . '{' . PHP_EOL .866 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .867 "\t\t" . '}' . PHP_EOL .868 "\t" . '}' . PHP_EOL .869 "\t" . 'public function foo()' . PHP_EOL .870 "\t" . '{' . PHP_EOL .871 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .872 "\t\t" . 'if (isset($this->getMockController()->foo) === false)' . PHP_EOL .873 "\t\t" . '{' . PHP_EOL .874 "\t\t\t" . '$this->getMockController()->foo = function() {};' . PHP_EOL .875 "\t\t" . '}' . PHP_EOL .876 "\t\t" . '$return = $this->getMockController()->invoke(\'foo\', $arguments);' . PHP_EOL .877 "\t\t" . 'return $return;' . PHP_EOL .878 "\t" . '}' . PHP_EOL .879 "\t" . 'public static function getMockedMethods()' . PHP_EOL .880 "\t" . '{' . PHP_EOL .881 "\t\t" . 'return ' . var_export(['__construct', 'foo'], true) . ';' . PHP_EOL .882 "\t" . '}' . PHP_EOL .883 '}' . PHP_EOL .884 '}'885 )886 ->if($generator->testedClassIs($realClass))887 ->then888 ->string($generator->getMockedClassCode($realClass))->isEqualTo(889 'namespace mock {' . PHP_EOL .890 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .891 '{' . PHP_EOL .892 $this->getMockControllerMethods() .893 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .894 "\t" . '{' . PHP_EOL .895 "\t\t" . 'if ($mockController === null)' . PHP_EOL .896 "\t\t" . '{' . PHP_EOL .897 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .898 "\t\t" . '}' . PHP_EOL .899 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .900 "\t\t" . '{' . PHP_EOL .901 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .902 "\t\t" . '}' . PHP_EOL .903 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .904 "\t\t" . '{' . PHP_EOL .905 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .906 "\t\t" . '}' . PHP_EOL .907 "\t" . '}' . PHP_EOL .908 "\t" . 'public function foo()' . PHP_EOL .909 "\t" . '{' . PHP_EOL .910 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .911 "\t\t" . 'if (isset($this->getMockController()->foo) === true)' . PHP_EOL .912 "\t\t" . '{' . PHP_EOL .913 "\t\t\t" . '$return = $this->getMockController()->invoke(\'foo\', $arguments);' . PHP_EOL .914 "\t\t\t" . 'return $return;' . PHP_EOL .915 "\t\t" . '}' . PHP_EOL .916 "\t\t" . 'else' . PHP_EOL .917 "\t\t" . '{' . PHP_EOL .918 "\t\t\t" . '$this->getMockController()->addCall(\'foo\', $arguments);' . PHP_EOL .919 "\t\t" . '}' . PHP_EOL .920 "\t" . '}' . PHP_EOL .921 "\t" . 'public static function getMockedMethods()' . PHP_EOL .922 "\t" . '{' . PHP_EOL .923 "\t\t" . 'return ' . var_export(['__construct', 'foo'], true) . ';' . PHP_EOL .924 "\t" . '}' . PHP_EOL .925 '}' . PHP_EOL .926 '}'927 )928 ;929 if (version_compare(PHP_VERSION, '5.6.0', '>=')) {930 $this931 ->given($generator = new testedClass())932 ->if($generator->allIsInterface())933 ->then934 ->string($generator->getMockedClassCode('mageekguy\atoum\tests\units\mock\classWithVariadicInConstructor'))->isEqualTo(935 'namespace mock\mageekguy\atoum\tests\units\mock {' . PHP_EOL .936 'final class classWithVariadicInConstructor extends \mageekguy\atoum\tests\units\mock\classWithVariadicInConstructor implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .937 '{' . PHP_EOL .938 $this->getMockControllerMethods() .939 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .940 "\t" . '{' . PHP_EOL .941 "\t\t" . 'if ($mockController === null)' . PHP_EOL .942 "\t\t" . '{' . PHP_EOL .943 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .944 "\t\t" . '}' . PHP_EOL .945 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .946 "\t\t" . '{' . PHP_EOL .947 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .948 "\t\t" . '}' . PHP_EOL .949 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .950 "\t\t" . '{' . PHP_EOL .951 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .952 "\t\t" . '}' . PHP_EOL .953 "\t" . '}' . PHP_EOL .954 "\t" . 'public static function getMockedMethods()' . PHP_EOL .955 "\t" . '{' . PHP_EOL .956 "\t\t" . 'return ' . var_export(['__construct'], true) . ';' . PHP_EOL .957 "\t" . '}' . PHP_EOL .958 '}' . PHP_EOL .959 '}'960 )961 ;962 }963 }964 /** @php >= 7.0 */965 public function testGetMockedClassCodeWithAllIsInterfacePhp7()966 {967 $this968 ->if($generator = new testedClass())969 ->and($realClass = uniqid())970 ->and($reflectionMethodController = new mock\controller())971 ->and($reflectionMethodController->__construct = function () {972 })973 ->and($reflectionMethodController->getName = 'foo')974 ->and($reflectionMethodController->isConstructor = false)975 ->and($reflectionMethodController->getParameters = [])976 ->and($reflectionMethodController->isPublic = true)977 ->and($reflectionMethodController->isProtected = false)978 ->and($reflectionMethodController->isPrivate = false)979 ->and($reflectionMethodController->isFinal = false)980 ->and($reflectionMethodController->isAbstract = false)981 ->and($reflectionMethodController->isStatic = false)982 ->and($reflectionMethodController->returnsReference = false)983 ->and($reflectionMethodController->hasReturnType = false)984 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))985 ->and($reflectionClassController = new mock\controller())986 ->and($reflectionClassController->__construct = function () {987 })988 ->and($reflectionClassController->getName = function () use ($realClass) {989 return $realClass;990 })991 ->and($reflectionClassController->isFinal = false)992 ->and($reflectionClassController->isInterface = false)993 ->and($reflectionClassController->getMethods = [$reflectionMethod])994 ->and($reflectionClassController->getConstructor = null)995 ->and($reflectionClassController->isAbstract = false)996 ->and($reflectionClass = new \mock\reflectionClass(null))997 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {998 return $reflectionClass;999 }))1000 ->and($adapter = new atoum\test\adapter())1001 ->and($adapter->class_exists = function ($class) use ($realClass) {1002 return ($class == '\\' . $realClass);1003 })1004 ->and($generator->setAdapter($adapter))1005 ->and($generator->shunt('__construct'))1006 ->and($generator->allIsInterface())1007 ->then1008 ->string($generator->getMockedClassCode($realClass))->isEqualTo(1009 'namespace mock {' . PHP_EOL .1010 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .1011 '{' . PHP_EOL .1012 $this->getMockControllerMethods() .1013 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1014 "\t" . '{' . PHP_EOL .1015 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1016 "\t\t" . '{' . PHP_EOL .1017 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1018 "\t\t" . '}' . PHP_EOL .1019 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1020 "\t\t" . '{' . PHP_EOL .1021 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1022 "\t\t" . '}' . PHP_EOL .1023 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .1024 "\t\t" . '{' . PHP_EOL .1025 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .1026 "\t\t" . '}' . PHP_EOL .1027 "\t" . '}' . PHP_EOL .1028 "\t" . 'public function foo()' . PHP_EOL .1029 "\t" . '{' . PHP_EOL .1030 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .1031 "\t\t" . 'if (isset($this->getMockController()->foo) === false)' . PHP_EOL .1032 "\t\t" . '{' . PHP_EOL .1033 "\t\t\t" . '$this->getMockController()->foo = function() {};' . PHP_EOL .1034 "\t\t" . '}' . PHP_EOL .1035 "\t\t" . '$return = $this->getMockController()->invoke(\'foo\', $arguments);' . PHP_EOL .1036 "\t\t" . 'return $return;' . PHP_EOL .1037 "\t" . '}' . PHP_EOL .1038 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1039 "\t" . '{' . PHP_EOL .1040 "\t\t" . 'return ' . var_export(['__construct', 'foo'], true) . ';' . PHP_EOL .1041 "\t" . '}' . PHP_EOL .1042 '}' . PHP_EOL .1043 '}'1044 )1045 ->if($generator->testedClassIs($realClass))1046 ->then1047 ->string($generator->getMockedClassCode($realClass))->isEqualTo(1048 'namespace mock {' . PHP_EOL .1049 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .1050 '{' . PHP_EOL .1051 $this->getMockControllerMethods() .1052 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1053 "\t" . '{' . PHP_EOL .1054 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1055 "\t\t" . '{' . PHP_EOL .1056 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1057 "\t\t" . '}' . PHP_EOL .1058 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1059 "\t\t" . '{' . PHP_EOL .1060 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1061 "\t\t" . '}' . PHP_EOL .1062 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .1063 "\t\t" . '{' . PHP_EOL .1064 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .1065 "\t\t" . '}' . PHP_EOL .1066 "\t" . '}' . PHP_EOL .1067 "\t" . 'public function foo()' . PHP_EOL .1068 "\t" . '{' . PHP_EOL .1069 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .1070 "\t\t" . 'if (isset($this->getMockController()->foo) === true)' . PHP_EOL .1071 "\t\t" . '{' . PHP_EOL .1072 "\t\t\t" . '$return = $this->getMockController()->invoke(\'foo\', $arguments);' . PHP_EOL .1073 "\t\t\t" . 'return $return;' . PHP_EOL .1074 "\t\t" . '}' . PHP_EOL .1075 "\t\t" . 'else' . PHP_EOL .1076 "\t\t" . '{' . PHP_EOL .1077 "\t\t\t" . '$this->getMockController()->addCall(\'foo\', $arguments);' . PHP_EOL .1078 "\t\t" . '}' . PHP_EOL .1079 "\t" . '}' . PHP_EOL .1080 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1081 "\t" . '{' . PHP_EOL .1082 "\t\t" . 'return ' . var_export(['__construct', 'foo'], true) . ';' . PHP_EOL .1083 "\t" . '}' . PHP_EOL .1084 '}' . PHP_EOL .1085 '}'1086 )1087 ->given($generator = new testedClass())1088 ->if($generator->allIsInterface())1089 ->then1090 ->string($generator->getMockedClassCode('mageekguy\atoum\tests\units\mock\classWithVariadicInConstructor'))->isEqualTo(1091 'namespace mock\mageekguy\atoum\tests\units\mock {' . PHP_EOL .1092 'final class classWithVariadicInConstructor extends \mageekguy\atoum\tests\units\mock\classWithVariadicInConstructor implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .1093 '{' . PHP_EOL .1094 $this->getMockControllerMethods() .1095 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1096 "\t" . '{' . PHP_EOL .1097 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1098 "\t\t" . '{' . PHP_EOL .1099 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1100 "\t\t" . '}' . PHP_EOL .1101 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1102 "\t\t" . '{' . PHP_EOL .1103 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1104 "\t\t" . '}' . PHP_EOL .1105 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .1106 "\t\t" . '{' . PHP_EOL .1107 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .1108 "\t\t" . '}' . PHP_EOL .1109 "\t" . '}' . PHP_EOL .1110 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1111 "\t" . '{' . PHP_EOL .1112 "\t\t" . 'return ' . var_export(['__construct'], true) . ';' . PHP_EOL .1113 "\t" . '}' . PHP_EOL .1114 '}' . PHP_EOL .1115 '}'1116 )1117 ;1118 }1119 /** @php < 7.0 */1120 public function testGetMockedClassCodeWithCloneMethod()1121 {1122 $this1123 ->if($generator = new testedClass())1124 ->and($realClass = uniqid())1125 ->and($reflectionMethodController = new mock\controller())1126 ->and($reflectionMethodController->__construct = function () {1127 })1128 ->and($reflectionMethodController->getName = 'clone')1129 ->and($reflectionMethodController->isConstructor = false)1130 ->and($reflectionMethodController->isAbstract = false)1131 ->and($reflectionMethodController->getParameters = [])1132 ->and($reflectionMethodController->isPublic = true)1133 ->and($reflectionMethodController->isProtected = false)1134 ->and($reflectionMethodController->isPrivate = false)1135 ->and($reflectionMethodController->isFinal = false)1136 ->and($reflectionMethodController->isStatic = false)1137 ->and($reflectionMethodController->returnsReference = false)1138 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))1139 ->and($reflectionClassController = new mock\controller())1140 ->and($reflectionClassController->__construct = function () {1141 })1142 ->and($reflectionClassController->getName = $realClass)1143 ->and($reflectionClassController->isFinal = false)1144 ->and($reflectionClassController->isInterface = false)1145 ->and($reflectionClassController->getMethods = [$reflectionMethod])1146 ->and($reflectionClassController->getConstructor = null)1147 ->and($reflectionClassController->isAbstract = false)1148 ->and($reflectionClass = new \mock\reflectionClass(null))1149 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {1150 return $reflectionClass;1151 }))1152 ->and($adapter = new atoum\test\adapter())1153 ->and($adapter->class_exists = function ($class) use ($realClass) {1154 return ($class == '\\' . $realClass);1155 })1156 ->and($generator->setAdapter($adapter))1157 ->then1158 ->string($generator->getMockedClassCode($realClass))->isEqualTo(1159 'namespace mock {' . PHP_EOL .1160 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .1161 '{' . PHP_EOL .1162 $this->getMockControllerMethods() .1163 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1164 "\t" . '{' . PHP_EOL .1165 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1166 "\t\t" . '{' . PHP_EOL .1167 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1168 "\t\t" . '}' . PHP_EOL .1169 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1170 "\t\t" . '{' . PHP_EOL .1171 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1172 "\t\t" . '}' . PHP_EOL .1173 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .1174 "\t\t" . '{' . PHP_EOL .1175 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .1176 "\t\t" . '}' . PHP_EOL .1177 "\t" . '}' . PHP_EOL .1178 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1179 "\t" . '{' . PHP_EOL .1180 "\t\t" . 'return ' . var_export(['__construct'], true) . ';' . PHP_EOL .1181 "\t" . '}' . PHP_EOL .1182 '}' . PHP_EOL .1183 '}'1184 )1185 ;1186 }1187 public function testGetMockedClassCodeWithShuntedDeprecatedConstructor()1188 {1189 $this1190 ->if($generator = new testedClass())1191 ->and($reflectionMethodController = new mock\controller())1192 ->and($reflectionMethodController->__construct = function () {1193 })1194 ->and($reflectionMethodController->getName = $realClass = uniqid())1195 ->and($reflectionMethodController->isConstructor = true)1196 ->and($reflectionMethodController->isAbstract = false)1197 ->and($reflectionMethodController->getParameters = [])1198 ->and($reflectionMethodController->isPublic = true)1199 ->and($reflectionMethodController->isProtected = false)1200 ->and($reflectionMethodController->isPrivate = false)1201 ->and($reflectionMethodController->isFinal = false)1202 ->and($reflectionMethodController->isStatic = false)1203 ->and($reflectionMethodController->returnsReference = false)1204 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))1205 ->and($reflectionClassController = new mock\controller())1206 ->and($reflectionClassController->__construct = function () {1207 })1208 ->and($reflectionClassController->getName = $realClass)1209 ->and($reflectionClassController->isFinal = false)1210 ->and($reflectionClassController->isInterface = false)1211 ->and($reflectionClassController->getMethods = [$reflectionMethod])1212 ->and($reflectionClassController->getConstructor = $reflectionMethod)1213 ->and($reflectionClassController->isAbstract = false)1214 ->and($reflectionClass = new \mock\reflectionClass(null))1215 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {1216 return $reflectionClass;1217 }))1218 ->and($adapter = new atoum\test\adapter())1219 ->and($adapter->class_exists = function ($class) use ($realClass) {1220 return ($class == '\\' . $realClass);1221 })1222 ->and($generator->setAdapter($adapter))1223 ->and($generator->shunt($realClass))1224 ->then1225 ->string($generator->getMockedClassCode($realClass))->isEqualTo(1226 'namespace mock {' . PHP_EOL .1227 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .1228 '{' . PHP_EOL .1229 $this->getMockControllerMethods() .1230 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1231 "\t" . '{' . PHP_EOL .1232 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .1233 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1234 "\t\t" . '{' . PHP_EOL .1235 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1236 "\t\t" . '}' . PHP_EOL .1237 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1238 "\t\t" . '{' . PHP_EOL .1239 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1240 "\t\t" . '}' . PHP_EOL .1241 "\t\t" . 'if (isset($this->getMockController()->' . $realClass . ') === false)' . PHP_EOL .1242 "\t\t" . '{' . PHP_EOL .1243 "\t\t\t" . '$this->getMockController()->' . $realClass . ' = function() {};' . PHP_EOL .1244 "\t\t" . '}' . PHP_EOL .1245 "\t\t" . '$this->getMockController()->invoke(\'' . $realClass . '\', $arguments);' . PHP_EOL .1246 "\t" . '}' . PHP_EOL .1247 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1248 "\t" . '{' . PHP_EOL .1249 "\t\t" . 'return ' . var_export([$realClass], true) . ';' . PHP_EOL .1250 "\t" . '}' . PHP_EOL .1251 '}' . PHP_EOL .1252 '}'1253 )1254 ;1255 }1256 /** @php < 7.0 */1257 public function testGetMockedClassCodeForInterface()1258 {1259 $this1260 ->if($generator = new testedClass())1261 ->and($reflectionMethodController = new mock\controller())1262 ->and($reflectionMethodController->__construct = function () {1263 })1264 ->and($reflectionMethodController->getName = '__construct')1265 ->and($reflectionMethodController->isConstructor = true)1266 ->and($reflectionMethodController->getParameters = [])1267 ->and($reflectionMethodController->isFinal = false)1268 ->and($reflectionMethodController->isStatic = false)1269 ->and($reflectionMethodController->returnsReference = false)1270 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))1271 ->and($reflectionClassController = new mock\controller())1272 ->and($reflectionClassController->__construct = function () {1273 })1274 ->and($reflectionClassController->getName = function () use (& $realClass) {1275 return $realClass;1276 })1277 ->and($reflectionClassController->isFinal = false)1278 ->and($reflectionClassController->isInterface = true)1279 ->and($reflectionClassController->getMethods = [$reflectionMethod])1280 ->and($reflectionClassController->isInstantiable = false)1281 ->and($reflectionClassController->implementsInterface = false)1282 ->and($reflectionClass = new \mock\reflectionClass(null))1283 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {1284 return $reflectionClass;1285 }))1286 ->and($adapter = new atoum\test\adapter())1287 ->and($adapter->class_exists = function ($class) use (& $realClass) {1288 return ($class == '\\' . $realClass);1289 })1290 ->and($generator->setAdapter($adapter))1291 ->then1292 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(1293 'namespace mock {' . PHP_EOL .1294 'final class ' . $realClass . ' implements \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .1295 '{' . PHP_EOL .1296 $this->getMockControllerMethods() .1297 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1298 "\t" . '{' . PHP_EOL .1299 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .1300 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1301 "\t\t" . '{' . PHP_EOL .1302 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1303 "\t\t" . '}' . PHP_EOL .1304 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1305 "\t\t" . '{' . PHP_EOL .1306 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1307 "\t\t" . '}' . PHP_EOL .1308 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .1309 "\t\t" . '{' . PHP_EOL .1310 "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .1311 "\t\t" . '}' . PHP_EOL .1312 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .1313 "\t" . '}' . PHP_EOL .1314 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .1315 "\t" . '{' . PHP_EOL .1316 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .1317 "\t\t" . '{' . PHP_EOL .1318 "\t\t\t" . '$return = $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .1319 "\t\t\t" . 'return $return;' . PHP_EOL .1320 "\t\t" . '}' . PHP_EOL .1321 "\t\t" . 'else' . PHP_EOL .1322 "\t\t" . '{' . PHP_EOL .1323 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .1324 "\t\t" . '}' . PHP_EOL .1325 "\t" . '}' . PHP_EOL .1326 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1327 "\t" . '{' . PHP_EOL .1328 "\t\t" . 'return ' . var_export(['__construct', '__call'], true) . ';' . PHP_EOL .1329 "\t" . '}' . PHP_EOL .1330 '}' . PHP_EOL .1331 '}'1332 )1333 ->if($reflectionClassController->implementsInterface = function ($interface) {1334 return ($interface == 'traversable' ? true : false);1335 })1336 ->and($generator->setReflectionClassFactory(function ($class) use ($reflectionClass) {1337 return ($class == 'iteratorAggregate' ? new \reflectionClass('iteratorAggregate') : $reflectionClass);1338 }))1339 ->then1340 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(1341 'namespace mock {' . PHP_EOL .1342 'final class ' . $realClass . ' implements \\iteratorAggregate, \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .1343 '{' . PHP_EOL .1344 $this->getMockControllerMethods() .1345 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1346 "\t" . '{' . PHP_EOL .1347 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .1348 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1349 "\t\t" . '{' . PHP_EOL .1350 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1351 "\t\t" . '}' . PHP_EOL .1352 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1353 "\t\t" . '{' . PHP_EOL .1354 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1355 "\t\t" . '}' . PHP_EOL .1356 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .1357 "\t\t" . '{' . PHP_EOL .1358 "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .1359 "\t\t" . '}' . PHP_EOL .1360 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .1361 "\t" . '}' . PHP_EOL .1362 "\t" . 'public function getIterator()' . PHP_EOL .1363 "\t" . '{' . PHP_EOL .1364 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .1365 "\t\t" . 'if (isset($this->getMockController()->getIterator) === false)' . PHP_EOL .1366 "\t\t" . '{' . PHP_EOL .1367 "\t\t\t" . '$this->getMockController()->getIterator = function() {};' . PHP_EOL .1368 "\t\t" . '}' . PHP_EOL .1369 "\t\t" . '$return = $this->getMockController()->invoke(\'getIterator\', $arguments);' . PHP_EOL .1370 "\t\t" . 'return $return;' . PHP_EOL .1371 "\t" . '}' . PHP_EOL .1372 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .1373 "\t" . '{' . PHP_EOL .1374 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .1375 "\t\t" . '{' . PHP_EOL .1376 "\t\t\t" . '$return = $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .1377 "\t\t\t" . 'return $return;' . PHP_EOL .1378 "\t\t" . '}' . PHP_EOL .1379 "\t\t" . 'else' . PHP_EOL .1380 "\t\t" . '{' . PHP_EOL .1381 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .1382 "\t\t" . '}' . PHP_EOL .1383 "\t" . '}' . PHP_EOL .1384 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1385 "\t" . '{' . PHP_EOL .1386 "\t\t" . 'return ' . var_export(['__construct', 'getiterator', '__call'], true) . ';' . PHP_EOL .1387 "\t" . '}' . PHP_EOL .1388 '}' . PHP_EOL .1389 '}'1390 )1391 ->if($generator = new testedClass())1392 ->and($reflectionMethodController = new mock\controller())1393 ->and($reflectionMethodController->__construct = function () {1394 })1395 ->and($reflectionMethodController->getName = '__construct')1396 ->and($reflectionMethodController->isConstructor = true)1397 ->and($reflectionMethodController->getParameters = [])1398 ->and($reflectionMethodController->isFinal = false)1399 ->and($reflectionMethodController->isStatic = false)1400 ->and($reflectionMethodController->returnsReference = false)1401 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))1402 ->and($reflectionClassController = new mock\controller())1403 ->and($reflectionClassController->__construct = function () {1404 })1405 ->and($reflectionClassController->getName = function () use (& $realClass) {1406 return $realClass;1407 })1408 ->and($reflectionClassController->isFinal = false)1409 ->and($reflectionClassController->isInterface = true)1410 ->and($reflectionClassController->getMethods = [$reflectionMethod])1411 ->and($reflectionClassController->isInstantiable = false)1412 ->and($reflectionClassController->implementsInterface = false)1413 ->and($reflectionClass = new \mock\reflectionClass(null))1414 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {1415 return $reflectionClass;1416 }))1417 ->and($adapter = new atoum\test\adapter())1418 ->and($adapter->class_exists = function ($class) use (& $realClass) {1419 return ($class == '\\' . $realClass);1420 })1421 ->and($generator->setAdapter($adapter))1422 ->and($generator->disallowUndefinedMethodUsage())1423 ->then1424 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(1425 'namespace mock {' . PHP_EOL .1426 'final class ' . $realClass . ' implements \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .1427 '{' . PHP_EOL .1428 $this->getMockControllerMethods() .1429 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1430 "\t" . '{' . PHP_EOL .1431 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .1432 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1433 "\t\t" . '{' . PHP_EOL .1434 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1435 "\t\t" . '}' . PHP_EOL .1436 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1437 "\t\t" . '{' . PHP_EOL .1438 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1439 "\t\t" . '}' . PHP_EOL .1440 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .1441 "\t\t" . '{' . PHP_EOL .1442 "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .1443 "\t\t" . '}' . PHP_EOL .1444 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .1445 "\t" . '}' . PHP_EOL .1446 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1447 "\t" . '{' . PHP_EOL .1448 "\t\t" . 'return ' . var_export(['__construct'], true) . ';' . PHP_EOL .1449 "\t" . '}' . PHP_EOL .1450 '}' . PHP_EOL .1451 '}'1452 )1453 ;1454 }1455 /** @php >= 7.0 */1456 public function testGetMockedClassCodeForInterfacePhp7()1457 {1458 $this1459 ->if($generator = new testedClass())1460 ->and($reflectionMethodController = new mock\controller())1461 ->and($reflectionMethodController->__construct = function () {1462 })1463 ->and($reflectionMethodController->getName = '__construct')1464 ->and($reflectionMethodController->isConstructor = true)1465 ->and($reflectionMethodController->getParameters = [])1466 ->and($reflectionMethodController->isFinal = false)1467 ->and($reflectionMethodController->isStatic = false)1468 ->and($reflectionMethodController->returnsReference = false)1469 ->and($reflectionMethodController->hasReturnType = false)1470 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))1471 ->and($reflectionClassController = new mock\controller())1472 ->and($reflectionClassController->__construct = function () {1473 })1474 ->and($reflectionClassController->getName = function () use (& $realClass) {1475 return $realClass;1476 })1477 ->and($reflectionClassController->isFinal = false)1478 ->and($reflectionClassController->isInterface = true)1479 ->and($reflectionClassController->getMethods = [$reflectionMethod])1480 ->and($reflectionClassController->isInstantiable = false)1481 ->and($reflectionClassController->implementsInterface = false)1482 ->and($reflectionClass = new \mock\reflectionClass(null))1483 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {1484 return $reflectionClass;1485 }))1486 ->and($adapter = new atoum\test\adapter())1487 ->and($adapter->class_exists = function ($class) use (& $realClass) {1488 return ($class == '\\' . $realClass);1489 })1490 ->and($generator->setAdapter($adapter))1491 ->then1492 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(1493 'namespace mock {' . PHP_EOL .1494 'final class ' . $realClass . ' implements \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .1495 '{' . PHP_EOL .1496 $this->getMockControllerMethods() .1497 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1498 "\t" . '{' . PHP_EOL .1499 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .1500 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1501 "\t\t" . '{' . PHP_EOL .1502 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1503 "\t\t" . '}' . PHP_EOL .1504 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1505 "\t\t" . '{' . PHP_EOL .1506 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1507 "\t\t" . '}' . PHP_EOL .1508 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .1509 "\t\t" . '{' . PHP_EOL .1510 "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .1511 "\t\t" . '}' . PHP_EOL .1512 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .1513 "\t" . '}' . PHP_EOL .1514 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .1515 "\t" . '{' . PHP_EOL .1516 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .1517 "\t\t" . '{' . PHP_EOL .1518 "\t\t\t" . '$return = $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .1519 "\t\t\t" . 'return $return;' . PHP_EOL .1520 "\t\t" . '}' . PHP_EOL .1521 "\t\t" . 'else' . PHP_EOL .1522 "\t\t" . '{' . PHP_EOL .1523 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .1524 "\t\t" . '}' . PHP_EOL .1525 "\t" . '}' . PHP_EOL .1526 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1527 "\t" . '{' . PHP_EOL .1528 "\t\t" . 'return ' . var_export(['__construct', '__call'], true) . ';' . PHP_EOL .1529 "\t" . '}' . PHP_EOL .1530 '}' . PHP_EOL .1531 '}'1532 )1533 ->if($reflectionClassController->implementsInterface = function ($interface) {1534 return ($interface == 'traversable' ? true : false);1535 })1536 ->and($generator->setReflectionClassFactory(function ($class) use ($reflectionClass) {1537 return ($class == 'iteratorAggregate' ? new \reflectionClass('iteratorAggregate') : $reflectionClass);1538 }))1539 ->then1540 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(1541 'namespace mock {' . PHP_EOL .1542 'final class ' . $realClass . ' implements \\iteratorAggregate, \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .1543 '{' . PHP_EOL .1544 $this->getMockControllerMethods() .1545 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1546 "\t" . '{' . PHP_EOL .1547 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .1548 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1549 "\t\t" . '{' . PHP_EOL .1550 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1551 "\t\t" . '}' . PHP_EOL .1552 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1553 "\t\t" . '{' . PHP_EOL .1554 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1555 "\t\t" . '}' . PHP_EOL .1556 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .1557 "\t\t" . '{' . PHP_EOL .1558 "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .1559 "\t\t" . '}' . PHP_EOL .1560 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .1561 "\t" . '}' . PHP_EOL .1562 "\t" . 'public function getIterator()' . PHP_EOL .1563 "\t" . '{' . PHP_EOL .1564 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .1565 "\t\t" . 'if (isset($this->getMockController()->getIterator) === false)' . PHP_EOL .1566 "\t\t" . '{' . PHP_EOL .1567 "\t\t\t" . '$this->getMockController()->getIterator = function() {};' . PHP_EOL .1568 "\t\t" . '}' . PHP_EOL .1569 "\t\t" . '$return = $this->getMockController()->invoke(\'getIterator\', $arguments);' . PHP_EOL .1570 "\t\t" . 'return $return;' . PHP_EOL .1571 "\t" . '}' . PHP_EOL .1572 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .1573 "\t" . '{' . PHP_EOL .1574 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .1575 "\t\t" . '{' . PHP_EOL .1576 "\t\t\t" . '$return = $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .1577 "\t\t\t" . 'return $return;' . PHP_EOL .1578 "\t\t" . '}' . PHP_EOL .1579 "\t\t" . 'else' . PHP_EOL .1580 "\t\t" . '{' . PHP_EOL .1581 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .1582 "\t\t" . '}' . PHP_EOL .1583 "\t" . '}' . PHP_EOL .1584 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1585 "\t" . '{' . PHP_EOL .1586 "\t\t" . 'return ' . var_export(['__construct', 'getiterator', '__call'], true) . ';' . PHP_EOL .1587 "\t" . '}' . PHP_EOL .1588 '}' . PHP_EOL .1589 '}'1590 )1591 ->if($generator = new testedClass())1592 ->and($reflectionMethodController = new mock\controller())1593 ->and($reflectionMethodController->__construct = function () {1594 })1595 ->and($reflectionMethodController->getName = '__construct')1596 ->and($reflectionMethodController->isConstructor = true)1597 ->and($reflectionMethodController->getParameters = [])1598 ->and($reflectionMethodController->isFinal = false)1599 ->and($reflectionMethodController->isStatic = false)1600 ->and($reflectionMethodController->returnsReference = false)1601 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))1602 ->and($reflectionClassController = new mock\controller())1603 ->and($reflectionClassController->__construct = function () {1604 })1605 ->and($reflectionClassController->getName = function () use (& $realClass) {1606 return $realClass;1607 })1608 ->and($reflectionClassController->isFinal = false)1609 ->and($reflectionClassController->isInterface = true)1610 ->and($reflectionClassController->getMethods = [$reflectionMethod])1611 ->and($reflectionClassController->isInstantiable = false)1612 ->and($reflectionClassController->implementsInterface = false)1613 ->and($reflectionClass = new \mock\reflectionClass(null))1614 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {1615 return $reflectionClass;1616 }))1617 ->and($adapter = new atoum\test\adapter())1618 ->and($adapter->class_exists = function ($class) use (& $realClass) {1619 return ($class == '\\' . $realClass);1620 })1621 ->and($generator->setAdapter($adapter))1622 ->and($generator->disallowUndefinedMethodUsage())1623 ->then1624 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(1625 'namespace mock {' . PHP_EOL .1626 'final class ' . $realClass . ' implements \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .1627 '{' . PHP_EOL .1628 $this->getMockControllerMethods() .1629 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1630 "\t" . '{' . PHP_EOL .1631 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .1632 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1633 "\t\t" . '{' . PHP_EOL .1634 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1635 "\t\t" . '}' . PHP_EOL .1636 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1637 "\t\t" . '{' . PHP_EOL .1638 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1639 "\t\t" . '}' . PHP_EOL .1640 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .1641 "\t\t" . '{' . PHP_EOL .1642 "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .1643 "\t\t" . '}' . PHP_EOL .1644 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .1645 "\t" . '}' . PHP_EOL .1646 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1647 "\t" . '{' . PHP_EOL .1648 "\t\t" . 'return ' . var_export(['__construct'], true) . ';' . PHP_EOL .1649 "\t" . '}' . PHP_EOL .1650 '}' . PHP_EOL .1651 '}'1652 )1653 ;1654 }1655 public function testGetMockedClassCodeForInterfaceWithConstructorArguments()1656 {1657 $this1658 ->if($generator = new testedClass())1659 ->and($reflectionParameterController = new mock\controller())1660 ->and($reflectionParameterController->__construct = function () {1661 })1662 ->and($reflectionParameterController->isArray = true)1663 ->and($reflectionParameterController->getName = 'param')1664 ->and($reflectionParameterController->isPassedByReference = false)1665 ->and($reflectionParameterController->isDefaultValueAvailable = false)1666 ->and($reflectionParameterController->isOptional = false)1667 ->and($reflectionParameterController->isVariadic = false)1668 ->and($reflectionParameter = new \mock\reflectionParameter(null, null))1669 ->and($reflectionMethodController = new mock\controller())1670 ->and($reflectionMethodController->__construct = function () {1671 })1672 ->and($reflectionMethodController->getName = '__construct')1673 ->and($reflectionMethodController->isConstructor = true)1674 ->and($reflectionMethodController->getParameters = [$reflectionParameter])1675 ->and($reflectionMethodController->isFinal = false)1676 ->and($reflectionMethodController->isStatic = false)1677 ->and($reflectionMethodController->returnsReference = false)1678 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))1679 ->and($reflectionClassController = new mock\controller())1680 ->and($reflectionClassController->__construct = function () {1681 })1682 ->and($reflectionClassController->getName = function () use (& $realClass) {1683 return $realClass;1684 })1685 ->and($reflectionClassController->isFinal = false)1686 ->and($reflectionClassController->isInterface = true)1687 ->and($reflectionClassController->getMethods = [$reflectionMethod])1688 ->and($reflectionClassController->isInstantiable = false)1689 ->and($reflectionClassController->implementsInterface = false)1690 ->and($reflectionClass = new \mock\reflectionClass(null))1691 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {1692 return $reflectionClass;1693 }))1694 ->and($adapter = new atoum\test\adapter())1695 ->and($adapter->class_exists = function ($class) use (& $realClass) {1696 return ($class == '\\' . $realClass);1697 })1698 ->and($generator->setAdapter($adapter))1699 ->then1700 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(1701 'namespace mock {' . PHP_EOL .1702 'final class ' . $realClass . ' implements \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .1703 '{' . PHP_EOL .1704 $this->getMockControllerMethods() .1705 "\t" . 'public function __construct(array $param, \mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1706 "\t" . '{' . PHP_EOL .1707 "\t\t" . '$arguments = array_merge(array($param), array_slice(func_get_args(), 1, -1));' . PHP_EOL .1708 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1709 "\t\t" . '{' . PHP_EOL .1710 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1711 "\t\t" . '}' . PHP_EOL .1712 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1713 "\t\t" . '{' . PHP_EOL .1714 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1715 "\t\t" . '}' . PHP_EOL .1716 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .1717 "\t\t" . '{' . PHP_EOL .1718 "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .1719 "\t\t" . '}' . PHP_EOL .1720 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .1721 "\t" . '}' . PHP_EOL .1722 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .1723 "\t" . '{' . PHP_EOL .1724 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .1725 "\t\t" . '{' . PHP_EOL .1726 "\t\t\t" . '$return = $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .1727 "\t\t\t" . 'return $return;' . PHP_EOL .1728 "\t\t" . '}' . PHP_EOL .1729 "\t\t" . 'else' . PHP_EOL .1730 "\t\t" . '{' . PHP_EOL .1731 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .1732 "\t\t" . '}' . PHP_EOL .1733 "\t" . '}' . PHP_EOL .1734 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1735 "\t" . '{' . PHP_EOL .1736 "\t\t" . 'return ' . var_export(['__construct', '__call'], true) . ';' . PHP_EOL .1737 "\t" . '}' . PHP_EOL .1738 '}' . PHP_EOL .1739 '}'1740 )1741 ;1742 }1743 /**1744 * @php < 7.01745 */1746 public function testGetMockedClassCodeForInterfaceWithConstructorArgumentsPhp56()1747 {1748 $this1749 ->if($generator = new testedClass())1750 ->and($reflectionParameterController = new mock\controller())1751 ->and($reflectionParameterController->__construct = function () {1752 })1753 ->and($reflectionParameterController->isArray = true)1754 ->and($reflectionParameterController->getName = 'param')1755 ->and($reflectionParameterController->isPassedByReference = false)1756 ->and($reflectionParameterController->isDefaultValueAvailable = false)1757 ->and($reflectionParameterController->isOptional = false)1758 ->and($reflectionParameterController->isVariadic = false)1759 ->and($reflectionParameter = new \mock\reflectionParameter(null, null))1760 ->and($reflectionMethodController = new mock\controller())1761 ->and($reflectionMethodController->__construct = function () {1762 })1763 ->and($reflectionMethodController->getName = '__construct')1764 ->and($reflectionMethodController->isConstructor = true)1765 ->and($reflectionMethodController->getParameters = [$reflectionParameter])1766 ->and($reflectionMethodController->isFinal = false)1767 ->and($reflectionMethodController->isStatic = false)1768 ->and($reflectionMethodController->returnsReference = false)1769 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))1770 ->and($reflectionClassController = new mock\controller())1771 ->and($reflectionClassController->__construct = function () {1772 })1773 ->and($reflectionClassController->getName = function () use (& $realClass) {1774 return $realClass;1775 })1776 ->and($reflectionClassController->isFinal = false)1777 ->and($reflectionClassController->isInterface = true)1778 ->and($reflectionClassController->getMethods = [$reflectionMethod])1779 ->and($reflectionClassController->isInstantiable = false)1780 ->and($reflectionClassController->implementsInterface = false)1781 ->and($reflectionClass = new \mock\reflectionClass(null))1782 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {1783 return $reflectionClass;1784 }))1785 ->and($adapter = new atoum\test\adapter())1786 ->and($adapter->class_exists = function ($class) use (& $realClass) {1787 return ($class == '\\' . $realClass);1788 })1789 ->and($generator->setAdapter($adapter))1790 ->then1791 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(1792 'namespace mock {' . PHP_EOL .1793 'final class ' . $realClass . ' implements \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .1794 '{' . PHP_EOL .1795 $this->getMockControllerMethods() .1796 "\t" . 'public function __construct(array $param, \mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1797 "\t" . '{' . PHP_EOL .1798 "\t\t" . '$arguments = array_merge(array($param), array_slice(func_get_args(), 1, -1));' . PHP_EOL .1799 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1800 "\t\t" . '{' . PHP_EOL .1801 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1802 "\t\t" . '}' . PHP_EOL .1803 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1804 "\t\t" . '{' . PHP_EOL .1805 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1806 "\t\t" . '}' . PHP_EOL .1807 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .1808 "\t\t" . '{' . PHP_EOL .1809 "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .1810 "\t\t" . '}' . PHP_EOL .1811 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .1812 "\t" . '}' . PHP_EOL .1813 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .1814 "\t" . '{' . PHP_EOL .1815 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .1816 "\t\t" . '{' . PHP_EOL .1817 "\t\t\t" . '$return = $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .1818 "\t\t\t" . 'return $return;' . PHP_EOL .1819 "\t\t" . '}' . PHP_EOL .1820 "\t\t" . 'else' . PHP_EOL .1821 "\t\t" . '{' . PHP_EOL .1822 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .1823 "\t\t" . '}' . PHP_EOL .1824 "\t" . '}' . PHP_EOL .1825 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1826 "\t" . '{' . PHP_EOL .1827 "\t\t" . 'return ' . var_export(['__construct', '__call'], true) . ';' . PHP_EOL .1828 "\t" . '}' . PHP_EOL .1829 '}' . PHP_EOL .1830 '}'1831 )1832 ;1833 }1834 public function testGetMockedClassCodeForInterfaceWithStaticMethod()1835 {1836 $this1837 ->if($generator = new testedClass())1838 ->and($reflectionMethodController = new mock\controller())1839 ->and($reflectionMethodController->__construct = function () {1840 })1841 ->and($reflectionMethodController->getName = $methodName = uniqid())1842 ->and($reflectionMethodController->isConstructor = false)1843 ->and($reflectionMethodController->getParameters = [])1844 ->and($reflectionMethodController->isFinal = false)1845 ->and($reflectionMethodController->isStatic = true)1846 ->and($reflectionMethodController->returnsReference = false)1847 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))1848 ->and($reflectionClassController = new mock\controller())1849 ->and($reflectionClassController->__construct = function () {1850 })1851 ->and($reflectionClassController->getName = function () use (& $realClass) {1852 return $realClass;1853 })1854 ->and($reflectionClassController->isFinal = false)1855 ->and($reflectionClassController->isInterface = true)1856 ->and($reflectionClassController->getMethods = [$reflectionMethod])1857 ->and($reflectionClassController->isInstantiable = false)1858 ->and($reflectionClassController->implementsInterface = false)1859 ->and($reflectionClass = new \mock\reflectionClass(null))1860 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {1861 return $reflectionClass;1862 }))1863 ->and($adapter = new atoum\test\adapter())1864 ->and($adapter->class_exists = function ($class) use (& $realClass) {1865 return ($class == '\\' . $realClass);1866 })1867 ->and($generator->setAdapter($adapter))1868 ->then1869 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(1870 'namespace mock {' . PHP_EOL .1871 'final class ' . $realClass . ' implements \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .1872 '{' . PHP_EOL .1873 $this->getMockControllerMethods() .1874 "\t" . 'public static function ' . $methodName . '()' . PHP_EOL .1875 "\t" . '{' . PHP_EOL .1876 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .1877 "\t\t" . 'return call_user_func_array(array(\'parent\', \'' . $methodName . '\'), $arguments);' . PHP_EOL .1878 "\t" . '}' . PHP_EOL .1879 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1880 "\t" . '{' . PHP_EOL .1881 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1882 "\t\t" . '{' . PHP_EOL .1883 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1884 "\t\t" . '}' . PHP_EOL .1885 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1886 "\t\t" . '{' . PHP_EOL .1887 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1888 "\t\t" . '}' . PHP_EOL .1889 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .1890 "\t\t" . '{' . PHP_EOL .1891 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .1892 "\t\t" . '}' . PHP_EOL .1893 "\t" . '}' . PHP_EOL .1894 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .1895 "\t" . '{' . PHP_EOL .1896 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .1897 "\t\t" . '{' . PHP_EOL .1898 "\t\t\t" . '$return = $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .1899 "\t\t\t" . 'return $return;' . PHP_EOL .1900 "\t\t" . '}' . PHP_EOL .1901 "\t\t" . 'else' . PHP_EOL .1902 "\t\t" . '{' . PHP_EOL .1903 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .1904 "\t\t" . '}' . PHP_EOL .1905 "\t" . '}' . PHP_EOL .1906 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1907 "\t" . '{' . PHP_EOL .1908 "\t\t" . 'return ' . var_export([$methodName, '__construct', '__call'], true) . ';' . PHP_EOL .1909 "\t" . '}' . PHP_EOL .1910 '}' . PHP_EOL .1911 '}'1912 )1913 ->if($reflectionClassController->implementsInterface = function ($interface) {1914 return ($interface == 'traversable' ? true : false);1915 })1916 ->and($generator->setReflectionClassFactory(function ($class) use ($reflectionClass) {1917 return ($class == 'iteratorAggregate' ? new \reflectionClass('iteratorAggregate') : $reflectionClass);1918 }))1919 ->then1920 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(1921 'namespace mock {' . PHP_EOL .1922 'final class ' . $realClass . ' implements \\iteratorAggregate, \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .1923 '{' . PHP_EOL .1924 $this->getMockControllerMethods() .1925 "\t" . 'public static function ' . $methodName . '()' . PHP_EOL .1926 "\t" . '{' . PHP_EOL .1927 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .1928 "\t\t" . 'return call_user_func_array(array(\'parent\', \'' . $methodName . '\'), $arguments);' . PHP_EOL .1929 "\t" . '}' . PHP_EOL .1930 "\t" . 'public function getIterator()' . PHP_EOL .1931 "\t" . '{' . PHP_EOL .1932 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .1933 "\t\t" . 'if (isset($this->getMockController()->getIterator) === false)' . PHP_EOL .1934 "\t\t" . '{' . PHP_EOL .1935 "\t\t\t" . '$this->getMockController()->getIterator = function() {};' . PHP_EOL .1936 "\t\t" . '}' . PHP_EOL .1937 "\t\t" . '$return = $this->getMockController()->invoke(\'getIterator\', $arguments);' . PHP_EOL .1938 "\t\t" . 'return $return;' . PHP_EOL .1939 "\t" . '}' . PHP_EOL .1940 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1941 "\t" . '{' . PHP_EOL .1942 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1943 "\t\t" . '{' . PHP_EOL .1944 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1945 "\t\t" . '}' . PHP_EOL .1946 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1947 "\t\t" . '{' . PHP_EOL .1948 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1949 "\t\t" . '}' . PHP_EOL .1950 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .1951 "\t\t" . '{' . PHP_EOL .1952 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .1953 "\t\t" . '}' . PHP_EOL .1954 "\t" . '}' . PHP_EOL .1955 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .1956 "\t" . '{' . PHP_EOL .1957 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .1958 "\t\t" . '{' . PHP_EOL .1959 "\t\t\t" . '$return = $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .1960 "\t\t\t" . 'return $return;' . PHP_EOL .1961 "\t\t" . '}' . PHP_EOL .1962 "\t\t" . 'else' . PHP_EOL .1963 "\t\t" . '{' . PHP_EOL .1964 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .1965 "\t\t" . '}' . PHP_EOL .1966 "\t" . '}' . PHP_EOL .1967 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1968 "\t" . '{' . PHP_EOL .1969 "\t\t" . 'return ' . var_export([$methodName, 'getiterator', '__construct', '__call'], true) . ';' . PHP_EOL .1970 "\t" . '}' . PHP_EOL .1971 '}' . PHP_EOL .1972 '}'1973 )1974 ;1975 }1976 /** @php >= 7.0 */1977 public function testGetMockedClassCodeForInterfaceWithTypeHint()1978 {1979 $this1980 ->if($generator = new testedClass())1981 ->and($reflectionParameterController = new mock\controller())1982 ->and($reflectionParameterController->__construct = function () {1983 })1984 ->and($reflectionParameterController->isArray = false)1985 ->and($reflectionParameterController->isCallable = false)1986 ->and($reflectionParameterController->getName = 'typeHint')1987 ->and($reflectionParameterController->isPassedByReference = false)1988 ->and($reflectionParameterController->isDefaultValueAvailable = false)1989 ->and($reflectionParameterController->isOptional = false)1990 ->and($reflectionParameterController->isVariadic = false)1991 ->and($reflectionParameterController->getClass = null)1992 ->and($reflectionParameterController->hasType = true)1993 ->and($reflectionParameterController->getType = 'string')1994 ->and($reflectionParameter = new \mock\reflectionParameter(null, null))1995 ->and($reflectionMethodController = new mock\controller())1996 ->and($reflectionMethodController->__construct = function () {1997 })1998 ->and($reflectionMethodController->getName = $methodName = uniqid())1999 ->and($reflectionMethodController->isConstructor = false)2000 ->and($reflectionMethodController->getParameters = [$reflectionParameter])2001 ->and($reflectionMethodController->isPublic = true)2002 ->and($reflectionMethodController->isProtected = false)2003 ->and($reflectionMethodController->isPrivate = false)2004 ->and($reflectionMethodController->isFinal = false)2005 ->and($reflectionMethodController->isStatic = false)2006 ->and($reflectionMethodController->isAbstract = false)2007 ->and($reflectionMethodController->returnsReference = false)2008 ->and($reflectionMethodController->hasReturnType = false)2009 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))2010 ->and($reflectionClassController = new mock\controller())2011 ->and($reflectionClassController->__construct = function () {2012 })2013 ->and($reflectionClassController->getName = function () use (& $realClass) {2014 return $realClass;2015 })2016 ->and($reflectionClassController->isFinal = false)2017 ->and($reflectionClassController->isInterface = false)2018 ->and($reflectionClassController->getMethods = [$reflectionMethod])2019 ->and($reflectionClassController->getConstructor = null)2020 ->and($reflectionClassController->isAbstract = false)2021 ->and($reflectionClass = new \mock\reflectionClass(null))2022 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {2023 return $reflectionClass;2024 }))2025 ->and($adapter = new atoum\test\adapter())2026 ->and($adapter->class_exists = function ($class) use (& $realClass) {2027 return ($class == '\\' . $realClass);2028 })2029 ->and($generator->setAdapter($adapter))2030 ->then2031 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(2032 'namespace mock {' . PHP_EOL .2033 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .2034 '{' . PHP_EOL .2035 $this->getMockControllerMethods() .2036 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .2037 "\t" . '{' . PHP_EOL .2038 "\t\t" . 'if ($mockController === null)' . PHP_EOL .2039 "\t\t" . '{' . PHP_EOL .2040 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .2041 "\t\t" . '}' . PHP_EOL .2042 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .2043 "\t\t" . '{' . PHP_EOL .2044 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .2045 "\t\t" . '}' . PHP_EOL .2046 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .2047 "\t\t" . '{' . PHP_EOL .2048 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .2049 "\t\t" . '}' . PHP_EOL .2050 "\t" . '}' . PHP_EOL .2051 "\t" . 'public function ' . $methodName . '(string $typeHint)' . PHP_EOL .2052 "\t" . '{' . PHP_EOL .2053 "\t\t" . '$arguments = array_merge(array($typeHint), array_slice(func_get_args(), 1));' . PHP_EOL .2054 "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL .2055 "\t\t" . '{' . PHP_EOL .2056 "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL .2057 "\t\t\t" . 'return $return;' . PHP_EOL .2058 "\t\t" . '}' . PHP_EOL .2059 "\t\t" . 'else' . PHP_EOL .2060 "\t\t" . '{' . PHP_EOL .2061 "\t\t\t" . '$this->getMockController()->addCall(\'' . $methodName . '\', $arguments);' . PHP_EOL .2062 "\t\t\t" . '$return = call_user_func_array(\'parent::' . $methodName . '\', $arguments);' . PHP_EOL .2063 "\t\t\t" . 'return $return;' . PHP_EOL .2064 "\t\t" . '}' . PHP_EOL .2065 "\t" . '}' . PHP_EOL .2066 "\t" . 'public static function getMockedMethods()' . PHP_EOL .2067 "\t" . '{' . PHP_EOL .2068 "\t\t" . 'return ' . var_export(['__construct', $methodName], true) . ';' . PHP_EOL .2069 "\t" . '}' . PHP_EOL .2070 '}' . PHP_EOL .2071 '}'2072 )2073 ;2074 }2075 /** @php >= 7.0 */2076 public function testGetMockedClassCodeForInterfaceWithReturnType()2077 {2078 $this2079 ->if($generator = new testedClass())2080 ->and($reflectionTypeController = new mock\controller())2081 ->and($reflectionTypeController->__construct = function () {2082 })2083 ->and($reflectionTypeController->isBuiltin = true)2084 ->and($reflectionTypeController->__toString = $returnType = 'string')2085 ->and($reflectionType = new \mock\reflectionType())2086 ->and($reflectionMethodController = new mock\controller())2087 ->and($reflectionMethodController->__construct = function () {2088 })2089 ->and($reflectionMethodController->getName = $methodName = uniqid())2090 ->and($reflectionMethodController->isConstructor = false)2091 ->and($reflectionMethodController->getParameters = [])2092 ->and($reflectionMethodController->isPublic = true)2093 ->and($reflectionMethodController->isProtected = false)2094 ->and($reflectionMethodController->isPrivate = false)2095 ->and($reflectionMethodController->isFinal = false)2096 ->and($reflectionMethodController->isStatic = false)2097 ->and($reflectionMethodController->isAbstract = false)2098 ->and($reflectionMethodController->returnsReference = false)2099 ->and($reflectionMethodController->hasReturnType = true)2100 ->and($reflectionMethodController->getReturnType = $reflectionType)2101 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))2102 ->and($reflectionClassController = new mock\controller())2103 ->and($reflectionClassController->__construct = function () {2104 })2105 ->and($reflectionClassController->getName = function () use (& $realClass) {2106 return $realClass;2107 })2108 ->and($reflectionClassController->isFinal = false)2109 ->and($reflectionClassController->isInterface = false)2110 ->and($reflectionClassController->getMethods = [$reflectionMethod])2111 ->and($reflectionClassController->getConstructor = null)2112 ->and($reflectionClassController->isAbstract = false)2113 ->and($reflectionClass = new \mock\reflectionClass(null))2114 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {2115 return $reflectionClass;2116 }))2117 ->and($adapter = new atoum\test\adapter())2118 ->and($adapter->class_exists = function ($class) use (& $realClass) {2119 return ($class == '\\' . $realClass);2120 })2121 ->and($generator->setAdapter($adapter))2122 ->then2123 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(2124 'namespace mock {' . PHP_EOL .2125 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .2126 '{' . PHP_EOL .2127 $this->getMockControllerMethods() .2128 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .2129 "\t" . '{' . PHP_EOL .2130 "\t\t" . 'if ($mockController === null)' . PHP_EOL .2131 "\t\t" . '{' . PHP_EOL .2132 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .2133 "\t\t" . '}' . PHP_EOL .2134 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .2135 "\t\t" . '{' . PHP_EOL .2136 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .2137 "\t\t" . '}' . PHP_EOL .2138 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .2139 "\t\t" . '{' . PHP_EOL .2140 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .2141 "\t\t" . '}' . PHP_EOL .2142 "\t" . '}' . PHP_EOL .2143 "\t" . 'public function ' . $methodName . '(): ' . $returnType . PHP_EOL .2144 "\t" . '{' . PHP_EOL .2145 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .2146 "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL .2147 "\t\t" . '{' . PHP_EOL .2148 "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL .2149 "\t\t\t" . 'return $return;' . PHP_EOL .2150 "\t\t" . '}' . PHP_EOL .2151 "\t\t" . 'else' . PHP_EOL .2152 "\t\t" . '{' . PHP_EOL .2153 "\t\t\t" . '$this->getMockController()->addCall(\'' . $methodName . '\', $arguments);' . PHP_EOL .2154 "\t\t\t" . '$return = call_user_func_array(\'parent::' . $methodName . '\', $arguments);' . PHP_EOL .2155 "\t\t\t" . 'return $return;' . PHP_EOL .2156 "\t\t" . '}' . PHP_EOL .2157 "\t" . '}' . PHP_EOL .2158 "\t" . 'public static function getMockedMethods()' . PHP_EOL .2159 "\t" . '{' . PHP_EOL .2160 "\t\t" . 'return ' . var_export(['__construct', $methodName], true) . ';' . PHP_EOL .2161 "\t" . '}' . PHP_EOL .2162 '}' . PHP_EOL .2163 '}'2164 )2165 ;2166 }2167 /** @php >= 7.0 */2168 public function testGetMockedClassCodeForInterfaceWithReturnTypeNotBuiltIn()2169 {2170 $this2171 ->if($generator = new testedClass())2172 ->and($reflectionTypeController = new mock\controller())2173 ->and($reflectionTypeController->__construct = function () {2174 })2175 ->and($reflectionTypeController->isBuiltin = false)2176 ->and($reflectionTypeController->__toString = $returnType = 'Mock\Foo')2177 ->and($reflectionType = new \mock\reflectionType())2178 ->and($reflectionMethodController = new mock\controller())2179 ->and($reflectionMethodController->__construct = function () {2180 })2181 ->and($reflectionMethodController->getName = $methodName = uniqid())2182 ->and($reflectionMethodController->isConstructor = false)2183 ->and($reflectionMethodController->getParameters = [])2184 ->and($reflectionMethodController->isPublic = true)2185 ->and($reflectionMethodController->isProtected = false)2186 ->and($reflectionMethodController->isPrivate = false)2187 ->and($reflectionMethodController->isFinal = false)2188 ->and($reflectionMethodController->isStatic = false)2189 ->and($reflectionMethodController->isAbstract = false)2190 ->and($reflectionMethodController->returnsReference = false)2191 ->and($reflectionMethodController->hasReturnType = true)2192 ->and($reflectionMethodController->getReturnType = $reflectionType)2193 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))2194 ->and($reflectionClassController = new mock\controller())2195 ->and($reflectionClassController->__construct = function () {2196 })2197 ->and($reflectionClassController->getName = function () use (& $realClass) {2198 return $realClass;2199 })2200 ->and($reflectionClassController->isFinal = false)2201 ->and($reflectionClassController->isInterface = false)2202 ->and($reflectionClassController->getMethods = [$reflectionMethod])2203 ->and($reflectionClassController->getConstructor = null)2204 ->and($reflectionClassController->isAbstract = false)2205 ->and($reflectionClass = new \mock\reflectionClass(null))2206 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {2207 return $reflectionClass;2208 }))2209 ->and($adapter = new atoum\test\adapter())2210 ->and($adapter->class_exists = function ($class) use (& $realClass) {2211 return ($class == '\\' . $realClass);2212 })2213 ->and($generator->setAdapter($adapter))2214 ->then2215 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(2216 'namespace mock {' . PHP_EOL .2217 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .2218 '{' . PHP_EOL .2219 $this->getMockControllerMethods() .2220 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .2221 "\t" . '{' . PHP_EOL .2222 "\t\t" . 'if ($mockController === null)' . PHP_EOL .2223 "\t\t" . '{' . PHP_EOL .2224 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .2225 "\t\t" . '}' . PHP_EOL .2226 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .2227 "\t\t" . '{' . PHP_EOL .2228 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .2229 "\t\t" . '}' . PHP_EOL .2230 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .2231 "\t\t" . '{' . PHP_EOL .2232 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .2233 "\t\t" . '}' . PHP_EOL .2234 "\t" . '}' . PHP_EOL .2235 "\t" . 'public function ' . $methodName . '(): \\' . $returnType . PHP_EOL .2236 "\t" . '{' . PHP_EOL .2237 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .2238 "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL .2239 "\t\t" . '{' . PHP_EOL .2240 "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL .2241 "\t\t\t" . 'return $return;' . PHP_EOL .2242 "\t\t" . '}' . PHP_EOL .2243 "\t\t" . 'else' . PHP_EOL .2244 "\t\t" . '{' . PHP_EOL .2245 "\t\t\t" . '$this->getMockController()->addCall(\'' . $methodName . '\', $arguments);' . PHP_EOL .2246 "\t\t\t" . '$return = call_user_func_array(\'parent::' . $methodName . '\', $arguments);' . PHP_EOL .2247 "\t\t\t" . 'return $return;' . PHP_EOL .2248 "\t\t" . '}' . PHP_EOL .2249 "\t" . '}' . PHP_EOL .2250 "\t" . 'public static function getMockedMethods()' . PHP_EOL .2251 "\t" . '{' . PHP_EOL .2252 "\t\t" . 'return ' . var_export(['__construct', $methodName], true) . ';' . PHP_EOL .2253 "\t" . '}' . PHP_EOL .2254 '}' . PHP_EOL .2255 '}'2256 )2257 ;2258 }2259 /** @php < 7.0 */2260 public function testGetMockedClassCodeForRealClassWithoutConstructor()2261 {2262 $this2263 ->if($generator = new testedClass())2264 ->and($reflectionMethodController = new mock\controller())2265 ->and($reflectionMethodController->__construct = function () {2266 })2267 ->and($reflectionMethodController->getName = $methodName = uniqid())2268 ->and($reflectionMethodController->isConstructor = false)2269 ->and($reflectionMethodController->getParameters = [])2270 ->and($reflectionMethodController->isPublic = true)2271 ->and($reflectionMethodController->isProtected = false)2272 ->and($reflectionMethodController->isPrivate = false)2273 ->and($reflectionMethodController->isFinal = false)2274 ->and($reflectionMethodController->isAbstract = false)2275 ->and($reflectionMethodController->isStatic = false)2276 ->and($reflectionMethodController->returnsReference = false)2277 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))2278 ->and($reflectionClassController = new mock\controller())2279 ->and($reflectionClassController->__construct = function () {2280 })2281 ->and($reflectionClassController->getName = function () use (& $realClass) {2282 return $realClass;2283 })2284 ->and($reflectionClassController->isFinal = false)2285 ->and($reflectionClassController->isInterface = false)2286 ->and($reflectionClassController->getMethods = [$reflectionMethod])2287 ->and($reflectionClassController->getConstructor = null)2288 ->and($reflectionClassController->isAbstract = false)2289 ->and($reflectionClass = new \mock\reflectionClass(null))2290 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {2291 return $reflectionClass;2292 }))2293 ->and($adapter = new atoum\test\adapter())2294 ->and($adapter->class_exists = function ($class) use (& $realClass) {2295 return ($class == '\\' . $realClass);2296 })2297 ->and($generator->setAdapter($adapter))2298 ->then2299 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(2300 'namespace mock {' . PHP_EOL .2301 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .2302 '{' . PHP_EOL .2303 $this->getMockControllerMethods() .2304 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .2305 "\t" . '{' . PHP_EOL .2306 "\t\t" . 'if ($mockController === null)' . PHP_EOL .2307 "\t\t" . '{' . PHP_EOL .2308 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .2309 "\t\t" . '}' . PHP_EOL .2310 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .2311 "\t\t" . '{' . PHP_EOL .2312 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .2313 "\t\t" . '}' . PHP_EOL .2314 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .2315 "\t\t" . '{' . PHP_EOL .2316 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .2317 "\t\t" . '}' . PHP_EOL .2318 "\t" . '}' . PHP_EOL .2319 "\t" . 'public function ' . $methodName . '()' . PHP_EOL .2320 "\t" . '{' . PHP_EOL .2321 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .2322 "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL .2323 "\t\t" . '{' . PHP_EOL .2324 "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL .2325 "\t\t\t" . 'return $return;' . PHP_EOL .2326 "\t\t" . '}' . PHP_EOL .2327 "\t\t" . 'else' . PHP_EOL .2328 "\t\t" . '{' . PHP_EOL .2329 "\t\t\t" . '$this->getMockController()->addCall(\'' . $methodName . '\', $arguments);' . PHP_EOL .2330 "\t\t\t" . '$return = call_user_func_array(\'parent::' . $methodName . '\', $arguments);' . PHP_EOL .2331 "\t\t\t" . 'return $return;' . PHP_EOL .2332 "\t\t" . '}' . PHP_EOL .2333 "\t" . '}' . PHP_EOL .2334 "\t" . 'public static function getMockedMethods()' . PHP_EOL .2335 "\t" . '{' . PHP_EOL .2336 "\t\t" . 'return ' . var_export(['__construct', $methodName], true) . ';' . PHP_EOL .2337 "\t" . '}' . PHP_EOL .2338 '}' . PHP_EOL .2339 '}'2340 )2341 ;2342 }2343 /** @php >= 7.0 */2344 public function testGetMockedClassCodeForRealClassWithoutConstructorPhp7()2345 {2346 $this2347 ->if($generator = new testedClass())2348 ->and($reflectionMethodController = new mock\controller())2349 ->and($reflectionMethodController->__construct = function () {2350 })2351 ->and($reflectionMethodController->getName = $methodName = uniqid())2352 ->and($reflectionMethodController->isConstructor = false)2353 ->and($reflectionMethodController->getParameters = [])2354 ->and($reflectionMethodController->isPublic = true)2355 ->and($reflectionMethodController->isProtected = false)2356 ->and($reflectionMethodController->isPrivate = false)2357 ->and($reflectionMethodController->isFinal = false)2358 ->and($reflectionMethodController->isAbstract = false)2359 ->and($reflectionMethodController->isStatic = false)2360 ->and($reflectionMethodController->returnsReference = false)2361 ->and($reflectionMethodController->hasReturnType = false)2362 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))2363 ->and($reflectionClassController = new mock\controller())2364 ->and($reflectionClassController->__construct = function () {2365 })2366 ->and($reflectionClassController->getName = function () use (& $realClass) {2367 return $realClass;2368 })2369 ->and($reflectionClassController->isFinal = false)2370 ->and($reflectionClassController->isInterface = false)2371 ->and($reflectionClassController->getMethods = [$reflectionMethod])2372 ->and($reflectionClassController->getConstructor = null)2373 ->and($reflectionClassController->isAbstract = false)2374 ->and($reflectionClass = new \mock\reflectionClass(null))2375 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {2376 return $reflectionClass;2377 }))2378 ->and($adapter = new atoum\test\adapter())2379 ->and($adapter->class_exists = function ($class) use (& $realClass) {2380 return ($class == '\\' . $realClass);2381 })2382 ->and($generator->setAdapter($adapter))2383 ->then2384 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(2385 'namespace mock {' . PHP_EOL .2386 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .2387 '{' . PHP_EOL .2388 $this->getMockControllerMethods() .2389 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .2390 "\t" . '{' . PHP_EOL .2391 "\t\t" . 'if ($mockController === null)' . PHP_EOL .2392 "\t\t" . '{' . PHP_EOL .2393 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .2394 "\t\t" . '}' . PHP_EOL .2395 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .2396 "\t\t" . '{' . PHP_EOL .2397 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .2398 "\t\t" . '}' . PHP_EOL .2399 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .2400 "\t\t" . '{' . PHP_EOL .2401 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .2402 "\t\t" . '}' . PHP_EOL .2403 "\t" . '}' . PHP_EOL .2404 "\t" . 'public function ' . $methodName . '()' . PHP_EOL .2405 "\t" . '{' . PHP_EOL .2406 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .2407 "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL .2408 "\t\t" . '{' . PHP_EOL .2409 "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL .2410 "\t\t\t" . 'return $return;' . PHP_EOL .2411 "\t\t" . '}' . PHP_EOL .2412 "\t\t" . 'else' . PHP_EOL .2413 "\t\t" . '{' . PHP_EOL .2414 "\t\t\t" . '$this->getMockController()->addCall(\'' . $methodName . '\', $arguments);' . PHP_EOL .2415 "\t\t\t" . '$return = call_user_func_array(\'parent::' . $methodName . '\', $arguments);' . PHP_EOL .2416 "\t\t\t" . 'return $return;' . PHP_EOL .2417 "\t\t" . '}' . PHP_EOL .2418 "\t" . '}' . PHP_EOL .2419 "\t" . 'public static function getMockedMethods()' . PHP_EOL .2420 "\t" . '{' . PHP_EOL .2421 "\t\t" . 'return ' . var_export(['__construct', $methodName], true) . ';' . PHP_EOL .2422 "\t" . '}' . PHP_EOL .2423 '}' . PHP_EOL .2424 '}'2425 )2426 ;2427 }2428 public function testGetMockedClassCodeForAbstractClassWithConstructorInInterface()2429 {2430 $this2431 ->if($generator = new testedClass())2432 ->and($publicMethodController = new mock\controller())2433 ->and($publicMethodController->__construct = function () {2434 })2435 ->and($publicMethodController->getName = '__construct')2436 ->and($publicMethodController->isConstructor = true)2437 ->and($publicMethodController->getParameters = [])2438 ->and($publicMethodController->isPublic = true)2439 ->and($publicMethodController->isProtected = false)2440 ->and($publicMethodController->isPrivate = false)2441 ->and($publicMethodController->isFinal = false)2442 ->and($publicMethodController->isStatic = false)2443 ->and($publicMethodController->isAbstract = true)2444 ->and($publicMethodController->returnsReference = false)2445 ->and($publicMethod = new \mock\reflectionMethod(null, null))2446 ->and($classController = new mock\controller())2447 ->and($classController->__construct = function () {2448 })2449 ->and($classController->getName = $className = uniqid())2450 ->and($classController->isFinal = false)2451 ->and($classController->isInterface = false)2452 ->and($classController->isAbstract = true)2453 ->and($classController->getMethods = [$publicMethod])2454 ->and($classController->getConstructor = $publicMethod)2455 ->and($class = new \mock\reflectionClass(null))2456 ->and($generator->setReflectionClassFactory(function () use ($class) {2457 return $class;2458 }))2459 ->and($adapter = new atoum\test\adapter())2460 ->and($adapter->class_exists = function ($class) use ($className) {2461 return ($class == '\\' . $className);2462 })2463 ->and($generator->setAdapter($adapter))2464 ->then2465 ->string($generator->getMockedClassCode($className))->isEqualTo(2466 'namespace mock {' . PHP_EOL .2467 'final class ' . $className . ' extends \\' . $className . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .2468 '{' . PHP_EOL .2469 $this->getMockControllerMethods() .2470 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .2471 "\t" . '{' . PHP_EOL .2472 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .2473 "\t\t" . 'if ($mockController === null)' . PHP_EOL .2474 "\t\t" . '{' . PHP_EOL .2475 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .2476 "\t\t" . '}' . PHP_EOL .2477 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .2478 "\t\t" . '{' . PHP_EOL .2479 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .2480 "\t\t" . '}' . PHP_EOL .2481 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .2482 "\t\t" . '{' . PHP_EOL .2483 "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .2484 "\t\t" . '}' . PHP_EOL .2485 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .2486 "\t" . '}' . PHP_EOL .2487 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .2488 "\t" . '{' . PHP_EOL .2489 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .2490 "\t\t" . '{' . PHP_EOL .2491 "\t\t\t" . '$return = $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .2492 "\t\t\t" . 'return $return;' . PHP_EOL .2493 "\t\t" . '}' . PHP_EOL .2494 "\t\t" . 'else' . PHP_EOL .2495 "\t\t" . '{' . PHP_EOL .2496 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .2497 "\t\t" . '}' . PHP_EOL .2498 "\t" . '}' . PHP_EOL .2499 "\t" . 'public static function getMockedMethods()' . PHP_EOL .2500 "\t" . '{' . PHP_EOL .2501 "\t\t" . 'return ' . var_export(['__construct', '__call'], true) . ';' . PHP_EOL .2502 "\t" . '}' . PHP_EOL .2503 '}' . PHP_EOL .2504 '}'2505 )2506 ;2507 }2508 public function testGenerate()2509 {2510 $this2511 ->if($generator = new testedClass())2512 ->then2513 ->exception(function () use ($generator) {2514 $generator->generate('');2515 })2516 ->isInstanceOf('mageekguy\atoum\exceptions\runtime')2517 ->hasMessage('Class name \'\' is invalid')2518 ->exception(function () use ($generator) {2519 $generator->generate('\\');2520 })2521 ->isInstanceOf('mageekguy\atoum\exceptions\runtime')2522 ->hasMessage('Class name \'\\\' is invalid')2523 ->exception(function () use ($generator, & $class) {2524 $generator->generate($class = ('\\' . uniqid() . '\\'));2525 })2526 ->isInstanceOf('mageekguy\atoum\exceptions\runtime')2527 ->hasMessage('Class name \'' . $class . '\' is invalid')2528 ->if($adapter = new atoum\test\adapter())2529 ->and($adapter->class_exists = false)2530 ->and($adapter->interface_exists = false)2531 ->and($generator->setAdapter($adapter))2532 ->and($class = uniqid('unknownClass'))2533 ->then2534 ->object($generator->generate($class))->isIdenticalTo($generator)2535 ->class('\mock\\' . $class)2536 ->hasNoParent()2537 ->hasInterface('mageekguy\atoum\mock\aggregator')2538 ->if($class = '\\' . uniqid('unknownClass'))2539 ->then2540 ->object($generator->generate($class))->isIdenticalTo($generator)2541 ->class('\mock' . $class)2542 ->hasNoParent()2543 ->hasInterface('mageekguy\atoum\mock\aggregator')2544 ->if($adapter->class_exists = true)2545 ->and($class = uniqid())2546 ->then2547 ->exception(function () use ($generator, $class) {2548 $generator->generate($class);2549 }2550 )2551 ->isInstanceOf('mageekguy\atoum\exceptions\logic')2552 ->hasMessage('Class \'\mock\\' . $class . '\' already exists')2553 ->if($class = '\\' . uniqid())2554 ->then2555 ->exception(function () use ($generator, $class) {2556 $generator->generate($class);2557 }2558 )2559 ->isInstanceOf('mageekguy\atoum\exceptions\logic')2560 ->hasMessage('Class \'\mock' . $class . '\' already exists')2561 ->if($class = uniqid())2562 ->and($adapter->class_exists = function ($arg) use ($class) {2563 return $arg === '\\' . $class;2564 })2565 ->and($reflectionClassController = new mock\controller())2566 ->and($reflectionClassController->__construct = function () {2567 })2568 ->and($reflectionClassController->isFinal = true)2569 ->and($reflectionClassController->isInterface = false)2570 ->and($reflectionClass = new \mock\reflectionClass(uniqid(), $reflectionClassController))2571 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {2572 return $reflectionClass;2573 }))2574 ->then2575 ->exception(function () use ($generator, $class) {2576 $generator->generate($class);2577 }2578 )2579 ->isInstanceOf('mageekguy\atoum\exceptions\logic')2580 ->hasMessage('Class \'\\' . $class . '\' is final, unable to mock it')2581 ->if($class = '\\' . uniqid())2582 ->and($adapter->class_exists = function ($arg) use ($class) {2583 return $arg === $class;2584 })2585 ->then2586 ->exception(function () use ($generator, $class) {2587 $generator->generate($class);2588 }2589 )2590 ->isInstanceOf('mageekguy\atoum\exceptions\logic')2591 ->hasMessage('Class \'' . $class . '\' is final, unable to mock it')2592 ->if($reflectionClassController->isFinal = false)2593 ->and($generator = new testedClass())2594 ->then2595 ->object($generator->generate(__CLASS__))->isIdenticalTo($generator)2596 ->class('\mock\\' . __CLASS__)2597 ->hasParent(__CLASS__)2598 ->hasInterface('mageekguy\atoum\mock\aggregator')2599 ->if($generator = new testedClass())2600 ->and($generator->shunt('__construct'))2601 ->then2602 ->boolean($generator->isShunted('__construct'))->isTrue()2603 ->object($generator->generate('reflectionMethod'))->isIdenticalTo($generator)2604 ->boolean($generator->isShunted('__construct'))->isFalse()2605 ->if($generator = new testedClass())2606 ->and($generator->shuntParentClassCalls())2607 ->then2608 ->object($generator->generate('reflectionParameter'))->isIdenticalTo($generator)2609 ->boolean($generator->callsToParentClassAreShunted())->isFalse()2610 ;2611 }2612 public function testMethodIsMockable()2613 {2614 $this2615 ->if($generator = new testedClass())2616 ->and($this->mockGenerator->orphanize('__construct'))2617 ->and($method = new \mock\reflectionMethod($this, $methodName = uniqid()))2618 ->and($this->calling($method)->getName = $methodName)2619 ->and($this->calling($method)->isFinal = false)2620 ->and($this->calling($method)->isStatic = false)2621 ->and($this->calling($method)->isAbstract = false)2622 ->and($this->calling($method)->isPrivate = false)2623 ->and($this->calling($method)->isProtected = false)2624 ->then2625 ->boolean($generator->methodIsMockable($method))->isTrue()2626 ->if($this->calling($method)->isFinal = true)2627 ->then2628 ->boolean($generator->methodIsMockable($method))->isFalse()2629 ->if($this->calling($method)->isFinal = false)2630 ->and($this->calling($method)->isStatic = true)2631 ->then2632 ->boolean($generator->methodIsMockable($method))->isFalse()2633 ->if($this->calling($method)->isStatic = false)2634 ->and($this->calling($method)->isPrivate = true)2635 ->then2636 ->boolean($generator->methodIsMockable($method))->isFalse()2637 ->if($this->calling($method)->isPrivate = false)2638 ->and($this->calling($method)->isProtected = true)2639 ->then2640 ->boolean($generator->methodIsMockable($method))->isFalse()2641 ->if($generator->overload(new mock\php\method($methodName)))2642 ->then2643 ->boolean($generator->methodIsMockable($method))->isTrue()2644 ;2645 }2646 /** @php < 7.0 */2647 public function testMethodIsMockableWithReservedWord($reservedWord)2648 {2649 $this2650 ->if($generator = new testedClass())2651 ->and($this->mockGenerator->orphanize('__construct'))2652 ->and($method = new \mock\reflectionMethod($this, $reservedWord))2653 ->and($this->calling($method)->getName = $reservedWord)2654 ->and($this->calling($method)->isFinal = false)2655 ->and($this->calling($method)->isStatic = false)2656 ->and($this->calling($method)->isAbstract = false)2657 ->and($this->calling($method)->isPrivate = false)2658 ->and($this->calling($method)->isProtected = false)2659 ->then2660 ->boolean($generator->methodIsMockable($method))->isFalse()2661 ;2662 }2663 /** @php >= 7.0 */2664 public function testMethodIsMockableWithReservedWordPhp7($reservedWord)2665 {2666 $this2667 ->if($generator = new testedClass())2668 ->and($this->mockGenerator->orphanize('__construct'))2669 ->and($method = new \mock\reflectionMethod($this, $reservedWord))2670 ->and($this->calling($method)->getName = $reservedWord)2671 ->and($this->calling($method)->isFinal = false)2672 ->and($this->calling($method)->isStatic = false)2673 ->and($this->calling($method)->isAbstract = false)2674 ->and($this->calling($method)->isPrivate = false)2675 ->and($this->calling($method)->isProtected = false)2676 ->then2677 ->boolean($generator->methodIsMockable($method))->isFalse()2678 ;2679 }2680 /**2681 * @php < 7.02682 */2683 public function testGetMockedClassCodeWithOrphanizedMethod()2684 {2685 $this2686 ->if->mockGenerator->orphanize('__construct')2687 ->and($a = new \mock\reflectionParameter())2688 ->and($this->calling($a)->getName = 'a')2689 ->and($this->calling($a)->isArray = false)2690 ->and($this->calling($a)->isCallable = false)2691 ->and($this->calling($a)->getClass = null)2692 ->and($this->calling($a)->isPassedByReference = false)2693 ->and($this->calling($a)->isDefaultValueAvailable = false)2694 ->and($this->calling($a)->isOptional = false)2695 ->and($this->calling($a)->isVariadic = false)2696 ->and($b = new \mock\reflectionParameter())2697 ->and($this->calling($b)->getName = 'b')2698 ->and($this->calling($b)->isArray = false)2699 ->and($this->calling($b)->isCallable = false)2700 ->and($this->calling($b)->getClass = null)2701 ->and($this->calling($b)->isPassedByReference = false)2702 ->and($this->calling($b)->isDefaultValueAvailable = false)2703 ->and($this->calling($b)->isOptional = false)2704 ->and($this->calling($b)->isVariadic = false)2705 ->and($c = new \mock\reflectionParameter())2706 ->and($this->calling($c)->getName = 'c')2707 ->and($this->calling($c)->isArray = false)2708 ->and($this->calling($c)->isCallable = false)2709 ->and($this->calling($c)->getClass = null)2710 ->and($this->calling($c)->isPassedByReference = false)2711 ->and($this->calling($c)->isDefaultValueAvailable = false)2712 ->and($this->calling($c)->isOptional = false)2713 ->and($this->calling($c)->isVariadic = false)2714 ->and->mockGenerator->orphanize('__construct')2715 ->and($constructor = new \mock\reflectionMethod())2716 ->and($this->calling($constructor)->getName = '__construct')2717 ->and($this->calling($constructor)->isConstructor = true)2718 ->and($this->calling($constructor)->getParameters = [$a, $b, $c])2719 ->and($this->calling($constructor)->isPublic = true)2720 ->and($this->calling($constructor)->isProtected = false)2721 ->and($this->calling($constructor)->isPrivate = false)2722 ->and($this->calling($constructor)->isFinal = false)2723 ->and($this->calling($constructor)->isStatic = false)2724 ->and($this->calling($constructor)->isAbstract = false)2725 ->and($this->calling($constructor)->returnsReference = false)2726 ->and->mockGenerator->orphanize('__construct')2727 ->and($class = new \mock\reflectionClass())2728 ->and($this->calling($class)->getName = $className = uniqid())2729 ->and($this->calling($class)->isFinal = false)2730 ->and($this->calling($class)->isInterface = false)2731 ->and($this->calling($class)->isAbstract = false)2732 ->and($this->calling($class)->getMethods = [$constructor])2733 ->and($this->calling($class)->getConstructor = $constructor)2734 ->and($adapter = new atoum\test\adapter())2735 ->and($adapter->class_exists = function ($class) use ($className) {2736 return ($class == '\\' . $className);2737 })2738 ->and($generator = new testedClass())2739 ->and($generator->setReflectionClassFactory(function () use ($class) {2740 return $class;2741 }))2742 ->and($generator->setAdapter($adapter))2743 ->and($generator->orphanize('__construct'))2744 ->then2745 ->string($generator->getMockedClassCode($className))->isEqualTo(2746 'namespace mock {' . PHP_EOL .2747 'final class ' . $className . ' extends \\' . $className . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .2748 '{' . PHP_EOL .2749 $this->getMockControllerMethods() .2750 "\t" . 'public function __construct($a = null, $b = null, $c = null, \mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .2751 "\t" . '{' . PHP_EOL .2752 "\t\t" . '$arguments = array_merge(array($a, $b, $c), array_slice(func_get_args(), 3, -1));' . PHP_EOL .2753 "\t\t" . 'if ($mockController === null)' . PHP_EOL .2754 "\t\t" . '{' . PHP_EOL .2755 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .2756 "\t\t" . '}' . PHP_EOL .2757 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .2758 "\t\t" . '{' . PHP_EOL .2759 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .2760 "\t\t" . '}' . PHP_EOL .2761 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .2762 "\t\t" . '{' . PHP_EOL .2763 "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .2764 "\t\t" . '}' . PHP_EOL .2765 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .2766 "\t" . '}' . PHP_EOL .2767 "\t" . 'public static function getMockedMethods()' . PHP_EOL .2768 "\t" . '{' . PHP_EOL .2769 "\t\t" . 'return ' . var_export(['__construct'], true) . ';' . PHP_EOL .2770 "\t" . '}' . PHP_EOL .2771 '}' . PHP_EOL .2772 '}'2773 )2774 ;2775 }2776 /**2777 * @php >= 7.02778 */2779 public function testGetMockedClassCodeWithOrphanizedMethodPhp7()2780 {2781 $this2782 ->if->mockGenerator->orphanize('__construct')2783 ->and($a = new \mock\reflectionParameter())2784 ->and($this->calling($a)->getName = 'a')2785 ->and($this->calling($a)->isArray = false)2786 ->and($this->calling($a)->isCallable = false)2787 ->and($this->calling($a)->getClass = null)2788 ->and($this->calling($a)->isPassedByReference = false)2789 ->and($this->calling($a)->isDefaultValueAvailable = false)2790 ->and($this->calling($a)->isOptional = false)2791 ->and($this->calling($a)->isVariadic = false)2792 ->and($this->calling($a)->hasType = false)2793 ->and($b = new \mock\reflectionParameter())2794 ->and($this->calling($b)->getName = 'b')2795 ->and($this->calling($b)->isArray = false)2796 ->and($this->calling($b)->isCallable = false)2797 ->and($this->calling($b)->getClass = null)2798 ->and($this->calling($b)->isPassedByReference = false)2799 ->and($this->calling($b)->isDefaultValueAvailable = false)2800 ->and($this->calling($b)->isOptional = false)2801 ->and($this->calling($b)->isVariadic = false)2802 ->and($this->calling($b)->hasType = false)2803 ->and($c = new \mock\reflectionParameter())2804 ->and($this->calling($c)->getName = 'c')2805 ->and($this->calling($c)->isArray = false)2806 ->and($this->calling($c)->isCallable = false)2807 ->and($this->calling($c)->getClass = null)2808 ->and($this->calling($c)->isPassedByReference = false)2809 ->and($this->calling($c)->isDefaultValueAvailable = false)2810 ->and($this->calling($c)->isOptional = false)2811 ->and($this->calling($c)->isVariadic = false)2812 ->and($this->calling($c)->hasType = false)2813 ->and->mockGenerator->orphanize('__construct')2814 ->and($constructor = new \mock\reflectionMethod())2815 ->and($this->calling($constructor)->getName = '__construct')2816 ->and($this->calling($constructor)->isConstructor = true)2817 ->and($this->calling($constructor)->getParameters = [$a, $b, $c])2818 ->and($this->calling($constructor)->isPublic = true)2819 ->and($this->calling($constructor)->isProtected = false)2820 ->and($this->calling($constructor)->isPrivate = false)2821 ->and($this->calling($constructor)->isFinal = false)2822 ->and($this->calling($constructor)->isStatic = false)2823 ->and($this->calling($constructor)->isAbstract = false)2824 ->and($this->calling($constructor)->returnsReference = false)2825 ->and->mockGenerator->orphanize('__construct')2826 ->and($class = new \mock\reflectionClass())2827 ->and($this->calling($class)->getName = $className = uniqid())2828 ->and($this->calling($class)->isFinal = false)2829 ->and($this->calling($class)->isInterface = false)2830 ->and($this->calling($class)->isAbstract = false)2831 ->and($this->calling($class)->getMethods = [$constructor])2832 ->and($this->calling($class)->getConstructor = $constructor)2833 ->and($adapter = new atoum\test\adapter())2834 ->and($adapter->class_exists = function ($class) use ($className) {2835 return ($class == '\\' . $className);2836 })2837 ->and($generator = new testedClass())2838 ->and($generator->setReflectionClassFactory(function () use ($class) {2839 return $class;2840 }))2841 ->and($generator->setAdapter($adapter))2842 ->and($generator->orphanize('__construct'))2843 ->then2844 ->string($generator->getMockedClassCode($className))->isEqualTo(2845 'namespace mock {' . PHP_EOL .2846 'final class ' . $className . ' extends \\' . $className . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .2847 '{' . PHP_EOL .2848 $this->getMockControllerMethods() .2849 "\t" . 'public function __construct($a = null, $b = null, $c = null, \mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .2850 "\t" . '{' . PHP_EOL .2851 "\t\t" . '$arguments = array_merge(array($a, $b, $c), array_slice(func_get_args(), 3, -1));' . PHP_EOL .2852 "\t\t" . 'if ($mockController === null)' . PHP_EOL .2853 "\t\t" . '{' . PHP_EOL .2854 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .2855 "\t\t" . '}' . PHP_EOL .2856 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .2857 "\t\t" . '{' . PHP_EOL .2858 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .2859 "\t\t" . '}' . PHP_EOL .2860 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .2861 "\t\t" . '{' . PHP_EOL .2862 "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .2863 "\t\t" . '}' . PHP_EOL .2864 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .2865 "\t" . '}' . PHP_EOL .2866 "\t" . 'public static function getMockedMethods()' . PHP_EOL .2867 "\t" . '{' . PHP_EOL .2868 "\t\t" . 'return ' . var_export(['__construct'], true) . ';' . PHP_EOL .2869 "\t" . '}' . PHP_EOL .2870 '}' . PHP_EOL .2871 '}'2872 )2873 ;2874 }2875 /**2876 * @php < 7.02877 */2878 public function testGetMockedClassCodeWithProtectedAbstractMethod()2879 {2880 $this2881 ->if($generator = new testedClass())2882 ->and($parameterController1 = new mock\controller())2883 ->and($parameterController1->__construct = function () {2884 })2885 ->and($parameterController1->isArray = false)2886 ->and($parameterController1->isCallable = false)2887 ->and($parameterController1->getClass = null)2888 ->and($parameterController1->getName = 'arg1')2889 ->and($parameterController1->isPassedByReference = false)2890 ->and($parameterController1->isDefaultValueAvailable = false)2891 ->and($parameterController1->isOptional = false)2892 ->and($parameterController1->isVariadic = false)2893 ->and($parameter1 = new \mock\reflectionParameter(null, null))2894 ->and($parameterController2 = new mock\controller())2895 ->and($parameterController2->__construct = function () {2896 })2897 ->and($parameterController2->isArray = true)2898 ->and($parameterController2->isCallable = false)2899 ->and($parameterController2->getClass = null)2900 ->and($parameterController2->getName = 'arg2')2901 ->and($parameterController2->isPassedByReference = true)2902 ->and($parameterController2->isDefaultValueAvailable = false)2903 ->and($parameterController2->isOptional = false)2904 ->and($parameterController2->isVariadic = false)2905 ->and($parameter2 = new \mock\reflectionParameter(null, null))2906 ->and($publicMethodController = new mock\controller())2907 ->and($publicMethodController->__construct = function () {2908 })2909 ->and($publicMethodController->getName = $publicMethodName = uniqid())2910 ->and($publicMethodController->isConstructor = false)2911 ->and($publicMethodController->getParameters = [$parameter1, $parameter2])2912 ->and($publicMethodController->isPublic = true)2913 ->and($publicMethodController->isProtected = false)2914 ->and($publicMethodController->isPrivate = false)2915 ->and($publicMethodController->isFinal = false)2916 ->and($publicMethodController->isStatic = false)2917 ->and($publicMethodController->isAbstract = true)2918 ->and($publicMethodController->returnsReference = false)2919 ->and($publicMethod = new \mock\reflectionMethod(null, null))2920 ->and($protectedMethodController = new mock\controller())2921 ->and($protectedMethodController->__construct = function () {2922 })2923 ->and($protectedMethodController->getName = $protectedMethodName = uniqid())2924 ->and($protectedMethodController->isConstructor = false)2925 ->and($protectedMethodController->getParameters = [])2926 ->and($protectedMethodController->isPublic = false)2927 ->and($protectedMethodController->isProtected = true)2928 ->and($protectedMethodController->isPrivate = false)2929 ->and($protectedMethodController->isFinal = false)2930 ->and($protectedMethodController->isStatic = false)2931 ->and($protectedMethodController->isAbstract = true)2932 ->and($protectedMethodController->returnsReference = false)2933 ->and($protectedMethod = new \mock\reflectionMethod(null, null))2934 ->and($classController = new mock\controller())2935 ->and($classController->__construct = function () {2936 })2937 ->and($classController->getName = $className = uniqid())2938 ->and($classController->isFinal = false)2939 ->and($classController->isInterface = false)2940 ->and($classController->getMethods = [$publicMethod, $protectedMethod])2941 ->and($classController->getConstructor = null)2942 ->and($classController->isAbstract = false)2943 ->and($class = new \mock\reflectionClass(null))2944 ->and($generator->setReflectionClassFactory(function () use ($class) {2945 return $class;2946 }))2947 ->and($adapter = new atoum\test\adapter())2948 ->and($adapter->class_exists = function ($class) use ($className) {2949 return ($class == '\\' . $className);2950 })2951 ->and($generator->setAdapter($adapter))2952 ->then2953 ->string($generator->getMockedClassCode($className))->isEqualTo(2954 'namespace mock {' . PHP_EOL .2955 'final class ' . $className . ' extends \\' . $className . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .2956 '{' . PHP_EOL .2957 $this->getMockControllerMethods() .2958 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .2959 "\t" . '{' . PHP_EOL .2960 "\t\t" . 'if ($mockController === null)' . PHP_EOL .2961 "\t\t" . '{' . PHP_EOL .2962 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .2963 "\t\t" . '}' . PHP_EOL .2964 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .2965 "\t\t" . '{' . PHP_EOL .2966 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .2967 "\t\t" . '}' . PHP_EOL .2968 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .2969 "\t\t" . '{' . PHP_EOL .2970 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .2971 "\t\t" . '}' . PHP_EOL .2972 "\t" . '}' . PHP_EOL .2973 "\t" . 'public function ' . $publicMethodName . '($arg1, array & $arg2)' . PHP_EOL .2974 "\t" . '{' . PHP_EOL .2975 "\t\t" . '$arguments = array_merge(array($arg1, & $arg2), array_slice(func_get_args(), 2));' . PHP_EOL .2976 "\t\t" . 'if (isset($this->getMockController()->' . $publicMethodName . ') === false)' . PHP_EOL .2977 "\t\t" . '{' . PHP_EOL .2978 "\t\t\t" . '$this->getMockController()->' . $publicMethodName . ' = function() {};' . PHP_EOL .2979 "\t\t" . '}' . PHP_EOL .2980 "\t\t" . '$return = $this->getMockController()->invoke(\'' . $publicMethodName . '\', $arguments);' . PHP_EOL .2981 "\t\t" . 'return $return;' . PHP_EOL .2982 "\t" . '}' . PHP_EOL .2983 "\t" . 'protected function ' . $protectedMethodName . '()' . PHP_EOL .2984 "\t" . '{' . PHP_EOL .2985 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .2986 "\t\t" . 'if (isset($this->getMockController()->' . $protectedMethodName . ') === false)' . PHP_EOL .2987 "\t\t" . '{' . PHP_EOL .2988 "\t\t\t" . '$this->getMockController()->' . $protectedMethodName . ' = function() {};' . PHP_EOL .2989 "\t\t" . '}' . PHP_EOL .2990 "\t\t" . '$return = $this->getMockController()->invoke(\'' . $protectedMethodName . '\', $arguments);' . PHP_EOL .2991 "\t\t" . 'return $return;' . PHP_EOL .2992 "\t" . '}' . PHP_EOL .2993 "\t" . 'public static function getMockedMethods()' . PHP_EOL .2994 "\t" . '{' . PHP_EOL .2995 "\t\t" . 'return ' . var_export(['__construct', $publicMethodName, $protectedMethodName], true) . ';' . PHP_EOL .2996 "\t" . '}' . PHP_EOL .2997 '}' . PHP_EOL .2998 '}'2999 )3000 ;3001 }3002 /**3003 * @php >= 7.03004 */3005 public function testGetMockedClassCodeWithProtectedAbstractMethodPhp7()3006 {3007 $this3008 ->if($generator = new testedClass())3009 ->and($parameterController1 = new mock\controller())3010 ->and($parameterController1->__construct = function () {3011 })3012 ->and($parameterController1->isArray = false)3013 ->and($parameterController1->isCallable = false)3014 ->and($parameterController1->getClass = null)3015 ->and($parameterController1->getName = 'arg1')3016 ->and($parameterController1->isPassedByReference = false)3017 ->and($parameterController1->isDefaultValueAvailable = false)3018 ->and($parameterController1->isOptional = false)3019 ->and($parameterController1->isVariadic = false)3020 ->and($parameterController1->hasType = false)3021 ->and($parameter1 = new \mock\reflectionParameter(null, null))3022 ->and($parameterController2 = new mock\controller())3023 ->and($parameterController2->__construct = function () {3024 })3025 ->and($parameterController2->isArray = true)3026 ->and($parameterController2->isCallable = false)3027 ->and($parameterController2->getClass = null)3028 ->and($parameterController2->getName = 'arg2')3029 ->and($parameterController2->isPassedByReference = true)3030 ->and($parameterController2->isDefaultValueAvailable = false)3031 ->and($parameterController2->isOptional = false)3032 ->and($parameterController2->isVariadic = false)3033 ->and($parameterController2->hasType = false)3034 ->and($parameter2 = new \mock\reflectionParameter(null, null))3035 ->and($publicMethodController = new mock\controller())3036 ->and($publicMethodController->__construct = function () {3037 })3038 ->and($publicMethodController->getName = $publicMethodName = uniqid())3039 ->and($publicMethodController->isConstructor = false)3040 ->and($publicMethodController->getParameters = [$parameter1, $parameter2])3041 ->and($publicMethodController->isPublic = true)3042 ->and($publicMethodController->isProtected = false)3043 ->and($publicMethodController->isPrivate = false)3044 ->and($publicMethodController->isFinal = false)3045 ->and($publicMethodController->isStatic = false)3046 ->and($publicMethodController->isAbstract = true)3047 ->and($publicMethodController->returnsReference = false)3048 ->and($publicMethodController->hasReturnType = false)3049 ->and($publicMethod = new \mock\reflectionMethod(null, null))3050 ->and($protectedMethodController = new mock\controller())3051 ->and($protectedMethodController->__construct = function () {3052 })3053 ->and($protectedMethodController->getName = $protectedMethodName = uniqid())3054 ->and($protectedMethodController->isConstructor = false)3055 ->and($protectedMethodController->getParameters = [])3056 ->and($protectedMethodController->isPublic = false)3057 ->and($protectedMethodController->isProtected = true)3058 ->and($protectedMethodController->isPrivate = false)3059 ->and($protectedMethodController->isFinal = false)3060 ->and($protectedMethodController->isStatic = false)3061 ->and($protectedMethodController->isAbstract = true)3062 ->and($protectedMethodController->returnsReference = false)3063 ->and($protectedMethodController->hasReturnType = false)3064 ->and($protectedMethod = new \mock\reflectionMethod(null, null))3065 ->and($classController = new mock\controller())3066 ->and($classController->__construct = function () {3067 })3068 ->and($classController->getName = $className = uniqid())3069 ->and($classController->isFinal = false)3070 ->and($classController->isInterface = false)3071 ->and($classController->getMethods = [$publicMethod, $protectedMethod])3072 ->and($classController->getConstructor = null)3073 ->and($classController->isAbstract = false)3074 ->and($class = new \mock\reflectionClass(null))3075 ->and($generator->setReflectionClassFactory(function () use ($class) {3076 return $class;3077 }))3078 ->and($adapter = new atoum\test\adapter())3079 ->and($adapter->class_exists = function ($class) use ($className) {3080 return ($class == '\\' . $className);3081 })3082 ->and($generator->setAdapter($adapter))3083 ->then3084 ->string($generator->getMockedClassCode($className))->isEqualTo(3085 'namespace mock {' . PHP_EOL .3086 'final class ' . $className . ' extends \\' . $className . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .3087 '{' . PHP_EOL .3088 $this->getMockControllerMethods() .3089 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .3090 "\t" . '{' . PHP_EOL .3091 "\t\t" . 'if ($mockController === null)' . PHP_EOL .3092 "\t\t" . '{' . PHP_EOL .3093 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .3094 "\t\t" . '}' . PHP_EOL .3095 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .3096 "\t\t" . '{' . PHP_EOL .3097 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .3098 "\t\t" . '}' . PHP_EOL .3099 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .3100 "\t\t" . '{' . PHP_EOL .3101 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .3102 "\t\t" . '}' . PHP_EOL .3103 "\t" . '}' . PHP_EOL .3104 "\t" . 'public function ' . $publicMethodName . '($arg1, array & $arg2)' . PHP_EOL .3105 "\t" . '{' . PHP_EOL .3106 "\t\t" . '$arguments = array_merge(array($arg1, & $arg2), array_slice(func_get_args(), 2));' . PHP_EOL .3107 "\t\t" . 'if (isset($this->getMockController()->' . $publicMethodName . ') === false)' . PHP_EOL .3108 "\t\t" . '{' . PHP_EOL .3109 "\t\t\t" . '$this->getMockController()->' . $publicMethodName . ' = function() {};' . PHP_EOL .3110 "\t\t" . '}' . PHP_EOL .3111 "\t\t" . '$return = $this->getMockController()->invoke(\'' . $publicMethodName . '\', $arguments);' . PHP_EOL .3112 "\t\t" . 'return $return;' . PHP_EOL .3113 "\t" . '}' . PHP_EOL .3114 "\t" . 'protected function ' . $protectedMethodName . '()' . PHP_EOL .3115 "\t" . '{' . PHP_EOL .3116 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .3117 "\t\t" . 'if (isset($this->getMockController()->' . $protectedMethodName . ') === false)' . PHP_EOL .3118 "\t\t" . '{' . PHP_EOL .3119 "\t\t\t" . '$this->getMockController()->' . $protectedMethodName . ' = function() {};' . PHP_EOL .3120 "\t\t" . '}' . PHP_EOL .3121 "\t\t" . '$return = $this->getMockController()->invoke(\'' . $protectedMethodName . '\', $arguments);' . PHP_EOL .3122 "\t\t" . 'return $return;' . PHP_EOL .3123 "\t" . '}' . PHP_EOL .3124 "\t" . 'public static function getMockedMethods()' . PHP_EOL .3125 "\t" . '{' . PHP_EOL .3126 "\t\t" . 'return ' . var_export(['__construct', $publicMethodName, $protectedMethodName], true) . ';' . PHP_EOL .3127 "\t" . '}' . PHP_EOL .3128 '}' . PHP_EOL .3129 '}'3130 )3131 ;3132 }3133 public function testGetMockedClassCodeForClassWithCallableTypeHint()3134 {3135 $this3136 ->if($generator = new testedClass())3137 ->and($reflectionParameterController = new mock\controller())3138 ->and($reflectionParameterController->__construct = function () {3139 })3140 ->and($reflectionParameterController->isArray = false)3141 ->and($reflectionParameterController->isCallable = true)3142 ->and($reflectionParameterController->getName = 'callback')3143 ->and($reflectionParameterController->isPassedByReference = false)3144 ->and($reflectionParameterController->isDefaultValueAvailable = false)3145 ->and($reflectionParameterController->isOptional = false)3146 ->and($reflectionParameterController->isVariadic = false)3147 ->and($reflectionParameter = new \mock\reflectionParameter(null, null))3148 ->and($reflectionMethodController = new mock\controller())3149 ->and($reflectionMethodController->__construct = function () {3150 })3151 ->and($reflectionMethodController->getName = '__construct')3152 ->and($reflectionMethodController->isConstructor = true)3153 ->and($reflectionMethodController->getParameters = [$reflectionParameter])3154 ->and($reflectionMethodController->isPublic = true)3155 ->and($reflectionMethodController->isProtected = false)3156 ->and($reflectionMethodController->isPrivate = false)3157 ->and($reflectionMethodController->isFinal = false)3158 ->and($reflectionMethodController->isStatic = false)3159 ->and($reflectionMethodController->isAbstract = false)3160 ->and($reflectionMethodController->returnsReference = false)3161 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))3162 ->and($reflectionClassController = new mock\controller())3163 ->and($reflectionClassController->__construct = function () {3164 })3165 ->and($reflectionClassController->getName = function () use (& $realClass) {3166 return $realClass;3167 })3168 ->and($reflectionClassController->isFinal = false)3169 ->and($reflectionClassController->isInterface = false)3170 ->and($reflectionClassController->getMethods = [$reflectionMethod])3171 ->and($reflectionClassController->getConstructor = $reflectionMethod)3172 ->and($reflectionClassController->isAbstract = false)3173 ->and($reflectionClass = new \mock\reflectionClass(null))3174 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {3175 return $reflectionClass;3176 }))3177 ->and($adapter = new atoum\test\adapter())3178 ->and($adapter->class_exists = function ($class) use (& $realClass) {3179 return ($class == '\\' . $realClass);3180 })3181 ->and($generator->setAdapter($adapter))3182 ->then3183 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(3184 'namespace mock {' . PHP_EOL .3185 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .3186 '{' . PHP_EOL .3187 $this->getMockControllerMethods() .3188 "\t" . 'public function __construct(callable $callback, \mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .3189 "\t" . '{' . PHP_EOL .3190 "\t\t" . '$arguments = array_merge(array($callback), array_slice(func_get_args(), 1, -1));' . PHP_EOL .3191 "\t\t" . 'if ($mockController === null)' . PHP_EOL .3192 "\t\t" . '{' . PHP_EOL .3193 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .3194 "\t\t" . '}' . PHP_EOL .3195 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .3196 "\t\t" . '{' . PHP_EOL .3197 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .3198 "\t\t" . '}' . PHP_EOL .3199 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .3200 "\t\t" . '{' . PHP_EOL .3201 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .3202 "\t\t" . '}' . PHP_EOL .3203 "\t\t" . 'else' . PHP_EOL .3204 "\t\t" . '{' . PHP_EOL .3205 "\t\t\t" . '$this->getMockController()->addCall(\'__construct\', $arguments);' . PHP_EOL .3206 "\t\t\t" . 'call_user_func_array(\'parent::__construct\', $arguments);' . PHP_EOL .3207 "\t\t" . '}' . PHP_EOL .3208 "\t" . '}' . PHP_EOL .3209 "\t" . 'public static function getMockedMethods()' . PHP_EOL .3210 "\t" . '{' . PHP_EOL .3211 "\t\t" . 'return ' . var_export(['__construct'], true) . ';' . PHP_EOL .3212 "\t" . '}' . PHP_EOL .3213 '}' . PHP_EOL .3214 '}'3215 )3216 ;3217 }3218 /**3219 * @php < 7.03220 */3221 public function testGetMockedClassCodeForClassWithVariadicArgumentsInConstruct()3222 {3223 $this3224 ->if($generator = new testedClass())3225 ->and($reflectionParameterController = new mock\controller())3226 ->and($reflectionParameterController->__construct = function () {3227 })3228 ->and($reflectionParameterController->isArray = false)3229 ->and($reflectionParameterController->isCallable = false)3230 ->and($reflectionParameterController->getName = 'variadic')3231 ->and($reflectionParameterController->isPassedByReference = false)3232 ->and($reflectionParameterController->isDefaultValueAvailable = false)3233 ->and($reflectionParameterController->isOptional = false)3234 ->and($reflectionParameterController->isVariadic = true)3235 ->and($reflectionParameterController->getClass = null)3236 ->and($reflectionParameter = new \mock\reflectionParameter(null, null))3237 ->and($reflectionMethodController = new mock\controller())3238 ->and($reflectionMethodController->__construct = function () {3239 })3240 ->and($reflectionMethodController->getName = '__construct')3241 ->and($reflectionMethodController->isConstructor = true)3242 ->and($reflectionMethodController->getParameters = [$reflectionParameter])3243 ->and($reflectionMethodController->isPublic = true)3244 ->and($reflectionMethodController->isProtected = false)3245 ->and($reflectionMethodController->isPrivate = false)3246 ->and($reflectionMethodController->isFinal = false)3247 ->and($reflectionMethodController->isStatic = false)3248 ->and($reflectionMethodController->isAbstract = false)3249 ->and($reflectionMethodController->returnsReference = false)3250 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))3251 ->and($reflectionClassController = new mock\controller())3252 ->and($reflectionClassController->__construct = function () {3253 })3254 ->and($reflectionClassController->getName = function () use (& $realClass) {3255 return $realClass;3256 })3257 ->and($reflectionClassController->isFinal = false)3258 ->and($reflectionClassController->isInterface = false)3259 ->and($reflectionClassController->getMethods = [$reflectionMethod])3260 ->and($reflectionClassController->getConstructor = $reflectionMethod)3261 ->and($reflectionClassController->isAbstract = false)3262 ->and($reflectionClass = new \mock\reflectionClass(null))3263 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {3264 return $reflectionClass;3265 }))3266 ->and($adapter = new atoum\test\adapter())3267 ->and($adapter->class_exists = function ($class) use (& $realClass) {3268 return ($class == '\\' . $realClass);3269 })3270 ->and($generator->setAdapter($adapter))3271 ->then3272 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(3273 'namespace mock {' . PHP_EOL .3274 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .3275 '{' . PHP_EOL .3276 $this->getMockControllerMethods() .3277 "\t" . 'public function __construct(... $variadic)' . PHP_EOL .3278 "\t" . '{' . PHP_EOL .3279 "\t\t" . '$arguments = func_get_args();' . PHP_EOL .3280 "\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . 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\', $arguments);' . PHP_EOL .3288 "\t\t" . '}' . PHP_EOL .3289 "\t\t" . 'else' . PHP_EOL .3290 "\t\t" . '{' . PHP_EOL .3291 "\t\t\t" . '$this->getMockController()->addCall(\'__construct\', $arguments);' . PHP_EOL .3292 "\t\t\t" . 'call_user_func_array(\'parent::__construct\', $arguments);' . PHP_EOL .3293 "\t\t" . '}' . PHP_EOL .3294 "\t" . '}' . PHP_EOL .3295 "\t" . 'public static function getMockedMethods()' . PHP_EOL .3296 "\t" . '{' . PHP_EOL .3297 "\t\t" . 'return ' . var_export(['__construct'], true) . ';' . PHP_EOL .3298 "\t" . '}' . PHP_EOL .3299 '}' . PHP_EOL .3300 '}'3301 )3302 ;3303 }3304 /**3305 * @php < 7.03306 */3307 public function testGetMockedClassCodeForClassWithOnlyVariadicArgumentsInMethod()3308 {3309 $this3310 ->if($generator = new testedClass())3311 ->and($reflectionParameterController = new mock\controller())3312 ->and($reflectionParameterController->__construct = function () {3313 })3314 ->and($reflectionParameterController->isArray = false)3315 ->and($reflectionParameterController->isCallable = false)3316 ->and($reflectionParameterController->getName = 'variadic')3317 ->and($reflectionParameterController->isPassedByReference = false)3318 ->and($reflectionParameterController->isDefaultValueAvailable = false)3319 ->and($reflectionParameterController->isOptional = false)3320 ->and($reflectionParameterController->isVariadic = true)3321 ->and($reflectionParameterController->getClass = null)3322 ->and($reflectionParameter = new \mock\reflectionParameter(null, null))3323 ->and($reflectionMethodController = new mock\controller())3324 ->and($reflectionMethodController->__construct = function () {3325 })3326 ->and($reflectionMethodController->getName = $methodName = uniqid())3327 ->and($reflectionMethodController->isConstructor = false)3328 ->and($reflectionMethodController->getParameters = [$reflectionParameter])3329 ->and($reflectionMethodController->isPublic = true)3330 ->and($reflectionMethodController->isProtected = false)3331 ->and($reflectionMethodController->isPrivate = false)3332 ->and($reflectionMethodController->isFinal = false)3333 ->and($reflectionMethodController->isStatic = false)3334 ->and($reflectionMethodController->isAbstract = false)3335 ->and($reflectionMethodController->returnsReference = false)3336 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))3337 ->and($reflectionClassController = new mock\controller())3338 ->and($reflectionClassController->__construct = function () {3339 })3340 ->and($reflectionClassController->getName = function () use (& $realClass) {3341 return $realClass;3342 })3343 ->and($reflectionClassController->isFinal = false)3344 ->and($reflectionClassController->isInterface = false)3345 ->and($reflectionClassController->getMethods = [$reflectionMethod])3346 ->and($reflectionClassController->getConstructor = null)3347 ->and($reflectionClassController->isAbstract = false)3348 ->and($reflectionClass = new \mock\reflectionClass(null))3349 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {3350 return $reflectionClass;3351 }))3352 ->and($adapter = new atoum\test\adapter())3353 ->and($adapter->class_exists = function ($class) use (& $realClass) {3354 return ($class == '\\' . $realClass);3355 })3356 ->and($generator->setAdapter($adapter))3357 ->then3358 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(3359 'namespace mock {' . PHP_EOL .3360 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .3361 '{' . PHP_EOL .3362 $this->getMockControllerMethods() .3363 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .3364 "\t" . '{' . PHP_EOL .3365 "\t\t" . 'if ($mockController === null)' . PHP_EOL .3366 "\t\t" . '{' . PHP_EOL .3367 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .3368 "\t\t" . '}' . PHP_EOL .3369 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .3370 "\t\t" . '{' . PHP_EOL .3371 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .3372 "\t\t" . '}' . PHP_EOL .3373 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .3374 "\t\t" . '{' . PHP_EOL .3375 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .3376 "\t\t" . '}' . PHP_EOL .3377 "\t" . '}' . PHP_EOL .3378 "\t" . 'public function ' . $methodName . '(... $variadic)' . PHP_EOL .3379 "\t" . '{' . PHP_EOL .3380 "\t\t" . '$arguments = func_get_args();' . PHP_EOL .3381 "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL .3382 "\t\t" . '{' . PHP_EOL .3383 "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL .3384 "\t\t\t" . 'return $return;' . PHP_EOL .3385 "\t\t" . '}' . PHP_EOL .3386 "\t\t" . 'else' . PHP_EOL .3387 "\t\t" . '{' . PHP_EOL .3388 "\t\t\t" . '$this->getMockController()->addCall(\'' . $methodName . '\', $arguments);' . PHP_EOL .3389 "\t\t\t" . '$return = call_user_func_array(\'parent::' . $methodName . '\', $arguments);' . PHP_EOL .3390 "\t\t\t" . 'return $return;' . PHP_EOL .3391 "\t\t" . '}' . PHP_EOL .3392 "\t" . '}' . PHP_EOL .3393 "\t" . 'public static function getMockedMethods()' . PHP_EOL .3394 "\t" . '{' . PHP_EOL .3395 "\t\t" . 'return ' . var_export(['__construct', $methodName], true) . ';' . PHP_EOL .3396 "\t" . '}' . PHP_EOL .3397 '}' . PHP_EOL .3398 '}'3399 )3400 ;3401 }3402 /** @php >= 7.0 */3403 public function testGetMockedClassCodeForMethodWithTypeHint()3404 {3405 $this3406 ->if($generator = new testedClass())3407 ->and($reflectionParameterController = new mock\controller())3408 ->and($reflectionParameterController->__construct = function () {3409 })3410 ->and($reflectionParameterController->isArray = false)3411 ->and($reflectionParameterController->isCallable = false)3412 ->and($reflectionParameterController->getName = 'typeHint')3413 ->and($reflectionParameterController->isPassedByReference = false)3414 ->and($reflectionParameterController->isDefaultValueAvailable = false)3415 ->and($reflectionParameterController->isOptional = false)3416 ->and($reflectionParameterController->isVariadic = false)3417 ->and($reflectionParameterController->getClass = null)3418 ->and($reflectionParameterController->hasType = true)3419 ->and($reflectionParameterController->getType = 'string')3420 ->and($reflectionParameter = new \mock\reflectionParameter(null, null))3421 ->and($reflectionMethodController = new mock\controller())3422 ->and($reflectionMethodController->__construct = function () {3423 })3424 ->and($reflectionMethodController->getName = $methodName = uniqid())3425 ->and($reflectionMethodController->isConstructor = false)3426 ->and($reflectionMethodController->getParameters = [$reflectionParameter])3427 ->and($reflectionMethodController->isPublic = true)3428 ->and($reflectionMethodController->isProtected = false)3429 ->and($reflectionMethodController->isPrivate = false)3430 ->and($reflectionMethodController->isFinal = false)3431 ->and($reflectionMethodController->isStatic = false)3432 ->and($reflectionMethodController->isAbstract = false)3433 ->and($reflectionMethodController->returnsReference = false)3434 ->and($reflectionMethodController->hasReturnType = false)3435 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))3436 ->and($reflectionClassController = new mock\controller())3437 ->and($reflectionClassController->__construct = function () {3438 })3439 ->and($reflectionClassController->getName = function () use (& $realClass) {3440 return $realClass;3441 })3442 ->and($reflectionClassController->isFinal = false)3443 ->and($reflectionClassController->isInterface = false)3444 ->and($reflectionClassController->getMethods = [$reflectionMethod])3445 ->and($reflectionClassController->getConstructor = null)3446 ->and($reflectionClassController->isAbstract = false)3447 ->and($reflectionClass = new \mock\reflectionClass(null))3448 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {3449 return $reflectionClass;3450 }))3451 ->and($adapter = new atoum\test\adapter())3452 ->and($adapter->class_exists = function ($class) use (& $realClass) {3453 return ($class == '\\' . $realClass);3454 })3455 ->and($generator->setAdapter($adapter))3456 ->then3457 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(3458 'namespace mock {' . PHP_EOL .3459 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .3460 '{' . PHP_EOL .3461 $this->getMockControllerMethods() .3462 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .3463 "\t" . '{' . PHP_EOL .3464 "\t\t" . 'if ($mockController === null)' . PHP_EOL .3465 "\t\t" . '{' . PHP_EOL .3466 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .3467 "\t\t" . '}' . PHP_EOL .3468 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .3469 "\t\t" . '{' . PHP_EOL .3470 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .3471 "\t\t" . '}' . PHP_EOL .3472 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .3473 "\t\t" . '{' . PHP_EOL .3474 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .3475 "\t\t" . '}' . PHP_EOL .3476 "\t" . '}' . PHP_EOL .3477 "\t" . 'public function ' . $methodName . '(string $typeHint)' . PHP_EOL .3478 "\t" . '{' . PHP_EOL .3479 "\t\t" . '$arguments = array_merge(array($typeHint), array_slice(func_get_args(), 1));' . PHP_EOL .3480 "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL .3481 "\t\t" . '{' . PHP_EOL .3482 "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL .3483 "\t\t\t" . 'return $return;' . PHP_EOL .3484 "\t\t" . '}' . PHP_EOL .3485 "\t\t" . 'else' . PHP_EOL .3486 "\t\t" . '{' . PHP_EOL .3487 "\t\t\t" . '$this->getMockController()->addCall(\'' . $methodName . '\', $arguments);' . PHP_EOL .3488 "\t\t\t" . '$return = call_user_func_array(\'parent::' . $methodName . '\', $arguments);' . PHP_EOL .3489 "\t\t\t" . 'return $return;' . PHP_EOL .3490 "\t\t" . '}' . PHP_EOL .3491 "\t" . '}' . PHP_EOL .3492 "\t" . 'public static function getMockedMethods()' . PHP_EOL .3493 "\t" . '{' . PHP_EOL .3494 "\t\t" . 'return ' . var_export(['__construct', $methodName], true) . ';' . PHP_EOL .3495 "\t" . '}' . PHP_EOL .3496 '}' . PHP_EOL .3497 '}'3498 )3499 ;3500 }3501 /** @php >= 7.0 */3502 public function testGetMockedClassCodeForMethodWithReturnType()3503 {3504 $this3505 ->if($generator = new testedClass())3506 ->and($reflectionTypeController = new mock\controller())3507 ->and($reflectionTypeController->__construct = function () {3508 })3509 ->and($reflectionTypeController->isBuiltin = true)3510 ->and($reflectionTypeController->__toString = $returnType = 'string')3511 ->and($reflectionType = new \mock\reflectionType())3512 ->and($reflectionMethodController = new mock\controller())3513 ->and($reflectionMethodController->__construct = function () {3514 })3515 ->and($reflectionMethodController->getName = $methodName = uniqid())3516 ->and($reflectionMethodController->isConstructor = false)3517 ->and($reflectionMethodController->getParameters = [])3518 ->and($reflectionMethodController->isPublic = true)3519 ->and($reflectionMethodController->isProtected = false)3520 ->and($reflectionMethodController->isPrivate = false)3521 ->and($reflectionMethodController->isFinal = false)3522 ->and($reflectionMethodController->isStatic = false)3523 ->and($reflectionMethodController->isAbstract = false)3524 ->and($reflectionMethodController->returnsReference = false)3525 ->and($reflectionMethodController->hasReturnType = true)3526 ->and($reflectionMethodController->getReturnType = $reflectionType)3527 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))3528 ->and($reflectionClassController = new mock\controller())3529 ->and($reflectionClassController->__construct = function () {3530 })3531 ->and($reflectionClassController->getName = function () use (& $realClass) {3532 return $realClass;3533 })3534 ->and($reflectionClassController->isFinal = false)3535 ->and($reflectionClassController->isInterface = false)3536 ->and($reflectionClassController->getMethods = [$reflectionMethod])3537 ->and($reflectionClassController->getConstructor = null)3538 ->and($reflectionClassController->isAbstract = false)3539 ->and($reflectionClass = new \mock\reflectionClass(null))3540 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {3541 return $reflectionClass;3542 }))3543 ->and($adapter = new atoum\test\adapter())3544 ->and($adapter->class_exists = function ($class) use (& $realClass) {3545 return ($class == '\\' . $realClass);3546 })3547 ->and($generator->setAdapter($adapter))3548 ->then3549 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(3550 'namespace mock {' . PHP_EOL .3551 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .3552 '{' . PHP_EOL .3553 $this->getMockControllerMethods() .3554 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .3555 "\t" . '{' . PHP_EOL .3556 "\t\t" . 'if ($mockController === null)' . PHP_EOL .3557 "\t\t" . '{' . PHP_EOL .3558 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .3559 "\t\t" . '}' . PHP_EOL .3560 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .3561 "\t\t" . '{' . PHP_EOL .3562 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .3563 "\t\t" . '}' . PHP_EOL .3564 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .3565 "\t\t" . '{' . PHP_EOL .3566 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .3567 "\t\t" . '}' . PHP_EOL .3568 "\t" . '}' . PHP_EOL .3569 "\t" . 'public function ' . $methodName . '(): ' . $returnType . PHP_EOL .3570 "\t" . '{' . PHP_EOL .3571 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .3572 "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL .3573 "\t\t" . '{' . PHP_EOL .3574 "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL .3575 "\t\t\t" . 'return $return;' . PHP_EOL .3576 "\t\t" . '}' . PHP_EOL .3577 "\t\t" . 'else' . PHP_EOL .3578 "\t\t" . '{' . PHP_EOL .3579 "\t\t\t" . '$this->getMockController()->addCall(\'' . $methodName . '\', $arguments);' . PHP_EOL .3580 "\t\t\t" . '$return = call_user_func_array(\'parent::' . $methodName . '\', $arguments);' . PHP_EOL .3581 "\t\t\t" . 'return $return;' . PHP_EOL .3582 "\t\t" . '}' . PHP_EOL .3583 "\t" . '}' . PHP_EOL .3584 "\t" . 'public static function getMockedMethods()' . PHP_EOL .3585 "\t" . '{' . PHP_EOL .3586 "\t\t" . 'return ' . var_export(['__construct', $methodName], true) . ';' . PHP_EOL .3587 "\t" . '}' . PHP_EOL .3588 '}' . PHP_EOL .3589 '}'3590 )3591 ;3592 }3593 /** @php >= 7.0 */3594 public function testGetMockedClassCodeForMethodWithReservedWord()3595 {3596 $this3597 ->if($generator = new testedClass())3598 ->and($reflectionMethodController = new mock\controller())3599 ->and($reflectionMethodController->__construct = function () {3600 })3601 ->and($reflectionMethodController->getName = $methodName = 'list')3602 ->and($reflectionMethodController->isConstructor = false)3603 ->and($reflectionMethodController->getParameters = [])3604 ->and($reflectionMethodController->isPublic = true)3605 ->and($reflectionMethodController->isProtected = false)3606 ->and($reflectionMethodController->isPrivate = false)3607 ->and($reflectionMethodController->isFinal = false)3608 ->and($reflectionMethodController->isStatic = false)3609 ->and($reflectionMethodController->isAbstract = false)3610 ->and($reflectionMethodController->returnsReference = false)3611 ->and($reflectionMethodController->hasReturnType = false)3612 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))3613 ->and($reflectionClassController = new mock\controller())3614 ->and($reflectionClassController->__construct = function () {3615 })3616 ->and($reflectionClassController->getName = function () use (& $realClass) {3617 return $realClass;3618 })3619 ->and($reflectionClassController->isFinal = false)3620 ->and($reflectionClassController->isInterface = false)3621 ->and($reflectionClassController->getMethods = [$reflectionMethod])3622 ->and($reflectionClassController->getConstructor = null)3623 ->and($reflectionClassController->isAbstract = false)3624 ->and($reflectionClass = new \mock\reflectionClass(null))3625 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {3626 return $reflectionClass;3627 }))3628 ->and($adapter = new atoum\test\adapter())3629 ->and($adapter->class_exists = function ($class) use (& $realClass) {3630 return ($class == '\\' . $realClass);3631 })3632 ->and($generator->setAdapter($adapter))3633 ->then3634 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(3635 'namespace mock {' . PHP_EOL .3636 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .3637 '{' . PHP_EOL .3638 $this->getMockControllerMethods() .3639 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .3640 "\t" . '{' . PHP_EOL .3641 "\t\t" . 'if ($mockController === null)' . PHP_EOL .3642 "\t\t" . '{' . PHP_EOL .3643 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .3644 "\t\t" . '}' . PHP_EOL .3645 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .3646 "\t\t" . '{' . PHP_EOL .3647 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .3648 "\t\t" . '}' . PHP_EOL .3649 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .3650 "\t\t" . '{' . PHP_EOL .3651 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .3652 "\t\t" . '}' . PHP_EOL .3653 "\t" . '}' . PHP_EOL .3654 "\t" . 'public function ' . $methodName . '()' . PHP_EOL .3655 "\t" . '{' . PHP_EOL .3656 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .3657 "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL .3658 "\t\t" . '{' . PHP_EOL .3659 "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL .3660 "\t\t\t" . 'return $return;' . PHP_EOL .3661 "\t\t" . '}' . PHP_EOL .3662 "\t\t" . 'else' . PHP_EOL .3663 "\t\t" . '{' . PHP_EOL .3664 "\t\t\t" . '$this->getMockController()->addCall(\'' . $methodName . '\', $arguments);' . PHP_EOL .3665 "\t\t\t" . '$return = call_user_func_array(\'parent::' . $methodName . '\', $arguments);' . PHP_EOL .3666 "\t\t\t" . 'return $return;' . PHP_EOL .3667 "\t\t" . '}' . PHP_EOL .3668 "\t" . '}' . PHP_EOL .3669 "\t" . 'public static function getMockedMethods()' . PHP_EOL .3670 "\t" . '{' . PHP_EOL .3671 "\t\t" . 'return ' . var_export(['__construct', $methodName], true) . ';' . PHP_EOL .3672 "\t" . '}' . PHP_EOL .3673 '}' . PHP_EOL .3674 '}'3675 )3676 ;3677 }3678 /** @php >= 7.0 */3679 public function testGetMockedClassCodeForMethodWithSelfReturnType()3680 {3681 $this3682 ->if($generator = new testedClass())3683 ->and($reflectionTypeController = new mock\controller())3684 ->and($reflectionTypeController->__construct = function () {3685 })3686 ->and($reflectionTypeController->__toString = 'self')3687 ->and($reflectionTypeController->isBuiltIn = false)3688 ->and($reflectionType = new \mock\reflectionType())3689 ->and($reflectionMethodController = new mock\controller())3690 ->and($reflectionMethodController->__construct = function () {3691 })3692 ->and($reflectionMethodController->getName = $methodName = 'returnSelf')3693 ->and($reflectionMethodController->isConstructor = false)3694 ->and($reflectionMethodController->getParameters = [])3695 ->and($reflectionMethodController->isPublic = true)3696 ->and($reflectionMethodController->isProtected = false)3697 ->and($reflectionMethodController->isPrivate = false)3698 ->and($reflectionMethodController->isFinal = false)3699 ->and($reflectionMethodController->isStatic = false)3700 ->and($reflectionMethodController->isAbstract = false)3701 ->and($reflectionMethodController->returnsReference = false)3702 ->and($reflectionMethodController->hasReturnType = true)3703 ->and($reflectionMethodController->getReturnType = $reflectionType)3704 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))3705 ->and($reflectionClassController = new mock\controller())3706 ->and($reflectionClassController->__construct = function () {3707 })3708 ->and($reflectionClassController->getName = function () use (& $realClass) {3709 return $realClass;3710 })3711 ->and($reflectionClassController->isFinal = false)3712 ->and($reflectionClassController->isInterface = false)3713 ->and($reflectionClassController->getMethods = [$reflectionMethod])3714 ->and($reflectionClassController->getConstructor = null)3715 ->and($reflectionClassController->isAbstract = false)3716 ->and($reflectionClass = new \mock\reflectionClass(null))3717 ->and($reflectionMethodController->getDeclaringClass = $reflectionClass)3718 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {3719 return $reflectionClass;3720 }))3721 ->and($adapter = new atoum\test\adapter())3722 ->and($adapter->class_exists = function ($class) use (& $realClass) {3723 return ($class == '\\' . $realClass);3724 })3725 ->and($generator->setAdapter($adapter))3726 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(3727 'namespace mock {' . PHP_EOL .3728 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .3729 '{' . PHP_EOL .3730 $this->getMockControllerMethods() .3731 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .3732 "\t" . '{' . PHP_EOL .3733 "\t\t" . 'if ($mockController === null)' . PHP_EOL .3734 "\t\t" . '{' . PHP_EOL .3735 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .3736 "\t\t" . '}' . PHP_EOL .3737 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .3738 "\t\t" . '{' . PHP_EOL .3739 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .3740 "\t\t" . '}' . PHP_EOL .3741 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .3742 "\t\t" . '{' . PHP_EOL .3743 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .3744 "\t\t" . '}' . PHP_EOL .3745 "\t" . '}' . PHP_EOL .3746 "\t" . 'public function ' . $methodName . '(): \\' . $realClass . PHP_EOL .3747 "\t" . '{' . PHP_EOL .3748 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .3749 "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL .3750 "\t\t" . '{' . PHP_EOL .3751 "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL .3752 "\t\t\t" . 'return $return;' . PHP_EOL .3753 "\t\t" . '}' . PHP_EOL .3754 "\t\t" . 'else' . PHP_EOL .3755 "\t\t" . '{' . PHP_EOL .3756 "\t\t\t" . '$this->getMockController()->addCall(\'' . $methodName . '\', $arguments);' . PHP_EOL .3757 "\t\t\t" . '$return = call_user_func_array(\'parent::' . $methodName . '\', $arguments);' . PHP_EOL .3758 "\t\t\t" . 'return $return;' . PHP_EOL .3759 "\t\t" . '}' . PHP_EOL .3760 "\t" . '}' . PHP_EOL .3761 "\t" . 'public static function getMockedMethods()' . PHP_EOL .3762 "\t" . '{' . PHP_EOL .3763 "\t\t" . 'return ' . var_export(['__construct', strtolower($methodName)], true) . ';' . PHP_EOL .3764 "\t" . '}' . PHP_EOL .3765 '}' . PHP_EOL .3766 '}'3767 )3768 ;3769 }3770 public function testGenerateWithEachInstanceIsUnique()3771 {3772 $this3773 ->if($generator = new testedClass())3774 ->and($generator->eachInstanceIsUnique())3775 ->then3776 ->string($generator->getMockedClassCode(__NAMESPACE__ . '\mockable'))->isEqualTo(3777 'namespace mock\\' . __NAMESPACE__ . ' {' . PHP_EOL .3778 'final class mockable extends \\' . __NAMESPACE__ . '\mockable implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .3779 '{' . PHP_EOL .3780 $this->getMockControllerMethods() .3781 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .3782 "\t" . '{' . PHP_EOL .3783 "\t\t" . '$this->{\'mock\' . uniqid()} = true;' . PHP_EOL .3784 "\t\t" . 'if ($mockController === null)' . PHP_EOL .3785 "\t\t" . '{' . PHP_EOL .3786 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .3787 "\t\t" . '}' . PHP_EOL .3788 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .3789 "\t\t" . '{' . PHP_EOL .3790 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .3791 "\t\t" . '}' . PHP_EOL .3792 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .3793 "\t\t" . '{' . PHP_EOL .3794 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .3795 "\t\t" . '}' . PHP_EOL .3796 "\t" . '}' . PHP_EOL .3797 "\t" . 'public static function getMockedMethods()' . PHP_EOL .3798 "\t" . '{' . PHP_EOL .3799 "\t\t" . 'return ' . var_export(['__construct'], true) . ';' . PHP_EOL .3800 "\t" . '}' . PHP_EOL .3801 '}' . PHP_EOL .3802 '}'3803 )3804 ;3805 }3806 protected function getMockControllerMethods()3807 {3808 return3809 "\t" . 'public function getMockController()' . PHP_EOL .3810 "\t" . '{' . PHP_EOL .3811 "\t\t" . '$mockController = \mageekguy\atoum\mock\controller::getForMock($this);' . PHP_EOL ....

Full Screen

Full Screen

getMockedMethods

Using AI Code Generation

copy

Full Screen

1require_once 'PHPUnit/Util/Filter.php';2PHPUnit_Util_Filter::addFileToFilter(__FILE__);3require_once 'PHPUnit/Framework/MockObject/Generator.php';4$generator = new PHPUnit_Framework_MockObject_Generator();5$methods = $generator->getMockedMethods('MyClass');6print_r($methods);7require_once 'PHPUnit/Util/Filter.php';8PHPUnit_Util_Filter::addFileToFilter(__FILE__);9require_once 'PHPUnit/Framework/MockObject/Generator.php';10$generator = new PHPUnit_Framework_MockObject_Generator();11$methods = $generator->getMockedMethods('MyClass');12print_r($methods);13require_once 'PHPUnit/Util/Filter.php';14PHPUnit_Util_Filter::addFileToFilter(__FILE__);15require_once 'PHPUnit/Framework/MockObject/Generator.php';16$generator = new PHPUnit_Framework_MockObject_Generator();17$methods = $generator->getMockedMethods('MyClass');18print_r($methods);19require_once 'PHPUnit/Util/Filter.php';20PHPUnit_Util_Filter::addFileToFilter(__FILE__);21require_once 'PHPUnit/Framework/MockObject/Generator.php';22$generator = new PHPUnit_Framework_MockObject_Generator();23$methods = $generator->getMockedMethods('MyClass');24print_r($methods);25require_once 'PHPUnit/Util/Filter.php';26PHPUnit_Util_Filter::addFileToFilter(__FILE__);27require_once 'PHPUnit/Framework/MockObject/Generator.php';28$generator = new PHPUnit_Framework_MockObject_Generator();29$methods = $generator->getMockedMethods('MyClass');30print_r($methods);31require_once 'PHPUnit/Util/Filter.php';32PHPUnit_Util_Filter::addFileToFilter(__FILE__);33require_once 'PHPUnit/Framework/MockObject/Generator.php';34$generator = new PHPUnit_Framework_MockObject_Generator();35$methods = $generator->getMockedMethods('MyClass');36print_r($methods);

Full Screen

Full Screen

getMockedMethods

Using AI Code Generation

copy

Full Screen

1require_once 'PHPUnit/Autoload.php';2require_once 'PHPUnit/Framework/MockObject/Generator.php';3require_once 'PHPUnit/Framework/MockObject/Matcher/InvokedRecorder.php';4require_once 'PHPUnit/Framework/MockObject/Matcher/Parameters.php';5require_once 'PHPUnit/Framework/MockObject/Matcher/MethodName.php';6require_once 'PHPUnit/Framework/MockObject/Matcher/AnyInvokedCount.php';7require_once 'PHPUnit/Framework/MockObject/Invocation.php';8require_once 'PHPUnit/Framework/MockObject/InvocationMocker.php';9require_once 'PHPUnit/Framework/MockObject/Stub/Return.php';10require_once 'PHPUnit/Framework/MockObject/Stub/ReturnArgument.php';11require_once 'PHPUnit/Framework/MockObject/Stub/ReturnCallback.php';12require_once 'PHPUnit/Framework/MockObject/Stub/ReturnSelf.php';13require_once 'PHPUnit/Framework/MockObject/Stub/ReturnReference.php';14require_once 'PHPUnit/Framework/MockObject/Stub/ConsecutiveCalls.php';15require_once 'PHPUnit/Framework/MockObject/Stub/Exception.php';16require_once 'PHPUnit/Framework/MockObject/Stub.php';17require_once 'PHPUnit/Framework/MockObject/Matcher.php';18require_once 'PHPUnit/Framework/MockObject/Matcher/StatelessInvocation.php';19require_once 'PHPUnit/Framework/MockObject/Matcher/Invocation.php';20require_once 'PHPUnit/Framework/MockObject/Matcher/InvokedAtIndex.php';21require_once 'PHPUnit/Framework/MockObject/Matcher/InvokedAtLeastOnce.php';22require_once 'PHPUnit/Framework/MockObject/Matcher/InvokedAtMostOnce.php';23require_once 'PHPUnit/Framework/MockObject/Matcher/InvokedCount.php';24require_once 'PHPUnit/Framework/MockObject/Matcher/InvokedAtIndex.php';25require_once 'PHPUnit/Framework/MockObject/Matcher/InvokedAtLeastOnce.php';26require_once 'PHPUnit/Framework/MockObject/Matcher/InvokedAtMostOnce.php';27require_once 'PHPUnit/Framework/MockObject/Matcher/InvokedCount.php';28require_once 'PHPUnit/Framework/MockObject/Matcher/InvokedRecorder.php';29require_once 'PHPUnit/Framework/MockObject/Matcher/Parameters.php';30require_once 'PHPUnit/Framework/MockObject/Matcher/MethodName.php';31require_once 'PHPUnit/Framework/MockObject/Matcher/AnyInvokedCount.php';32require_once 'PHPUnit/Framework/MockObject/Invocation.php';33require_once 'PHPUnit/Framework/MockObject/InvocationMocker.php';

Full Screen

Full Screen

getMockedMethods

Using AI Code Generation

copy

Full Screen

1require_once 'PHPUnit/Autoload.php';2require_once 'PHPUnit/Framework/MockObject/Generator.php';3$generator = new PHPUnit_Framework_MockObject_Generator();4$methods = $generator->getMockedMethods('PHPUnit_Framework_TestCase');5foreach($methods as $method)6{7";8}

Full Screen

Full Screen

getMockedMethods

Using AI Code Generation

copy

Full Screen

1{2 public function foo()3 {4 return 'foo';5 }6}7$gen = new ReflectionGenerator('A', 'foo');8$methods = $gen->getMockedMethods();9var_dump($methods);10array(1) {11 string(3) "foo"12}13Example 2: Using ReflectionGenerator::getExecutingFile() and ReflectionGenerator::getExecutingLine() methods14function gen()15{16 yield 'foo';17}18$gen = gen();19$gen->current();20$gen->next();21$ref = new ReflectionGenerator($gen);22echo $ref->getExecutingFile();23echo $ref->getExecutingLine();24Example 3: Using ReflectionGenerator::getTrace() method25function gen()26{27 yield 'foo';28}29$gen = gen();30$gen->current();31$gen->next();32$ref = new ReflectionGenerator($gen);33var_dump($ref->getTrace());34array(1) {35 array(5) {36 string(5) "1.php"37 int(7)38 string(3) "gen"39 string(0) ""40 string(0) ""41 }42}43Example 4: Using ReflectionGenerator::getFunction() method44function gen()45{46 yield 'foo';47}48$gen = gen();49$gen->current();50$gen->next();51$ref = new ReflectionGenerator($gen);52var_dump($ref->getFunction());53class ReflectionFunction#1 (1) {54 string(3) "gen"55}56Example 5: Using ReflectionGenerator::getThis() method57{58 public function foo()59 {60 yield 'foo';61 }62}63$gen = new ReflectionGenerator('A',

Full Screen

Full Screen

getMockedMethods

Using AI Code Generation

copy

Full Screen

1$reflector = new ReflectionClass('Generator');2$methods = $reflector->getMethods();3foreach($methods as $method) {4";5}6$reflector = new ReflectionClass('Generator');7$methods = $reflector->getMethods();8foreach($methods as $method) {9";10}11$reflector = new ReflectionClass('Generator');12$methods = $reflector->getMethods();13foreach($methods as $method) {14";15}16$reflector = new ReflectionClass('Generator');17$methods = $reflector->getMethods();18foreach($methods as $method) {19";20}21$reflector = new ReflectionClass('Generator');22$methods = $reflector->getMethods();23foreach($methods as $method) {24";25}26$reflector = new ReflectionClass('Generator');27$methods = $reflector->getMethods();28foreach($methods as $method) {29";30}

Full Screen

Full Screen

getMockedMethods

Using AI Code Generation

copy

Full Screen

1{2 public function getMockedMethods($class)3 {4 $reflector = new ReflectionClass($class);5 $methods = $reflector->getMethods(ReflectionMethod::IS_PUBLIC);6 $mockedMethods = array();7 foreach ($methods as $method) {8 if ($method->class == $class) {9 $mockedMethods[] = $method->name;10 }11 }12 return $mockedMethods;13 }14}15$genObj = new Generator();16$methods = $genObj->getMockedMethods('Sample');17print_r($methods);

Full Screen

Full Screen

getMockedMethods

Using AI Code Generation

copy

Full Screen

1$generator = new Generator();2$generator->setClass('TestClass');3$generator->setMethods(getMockedMethods('TestClass'));4$generator->generateClass();5function getMockedMethods($class)6{7 $methods = array();8 $reflection = new ReflectionClass($class);9 $methods = $reflection->getMethods(ReflectionMethod::IS_PUBLIC);10 $mocked_methods = array();11 foreach($methods as $method)12 {13 $mocked_methods[] = $method->name;14 }15 return $mocked_methods;16}17$generator = new Generator();18$generator->setClass('TestClass');19$generator->setMethods(getMockedMethods('TestClass'));20$generator->generateClass();21function getMockedMethods($class)22{23 $methods = array();24 $reflection = new ReflectionClass($class);25 $methods = $reflection->getMethods(ReflectionMethod::IS_PUBLIC);26 $mocked_methods = array();27 foreach($methods as $method)28 {29 $mocked_methods[] = $method->name;30 }31 return $mocked_methods;32}33$generator = new Generator();34$generator->setClass('TestClass');35$generator->setMethods(getMockedMethods('TestClass'));36$generator->generateClass();37function getMockedMethods($class)38{39 $methods = array();40 $reflection = new ReflectionClass($class);41 $methods = $reflection->getMethods(ReflectionMethod::IS_PUBLIC);42 $mocked_methods = array();43 foreach($methods as $method)44 {45 $mocked_methods[] = $method->name;46 }47 return $mocked_methods;48}49$generator = new Generator();50$generator->setClass('TestClass');51$generator->setMethods(getMockedMethods('TestClass'));52$generator->generateClass();53function getMockedMethods($class)54{55 $methods = array();

Full Screen

Full Screen

getMockedMethods

Using AI Code Generation

copy

Full Screen

1require_once("generator.php");2$g = new generator();3$g->getMockedMethods("stdclass");4require_once("generator.php");5$g = new generator();6$g->getMockedMethods("stdclass");7$g->generate("stdclass");8{9 public function __construct()10 {11 }12 public function __destruct()13 {14 }15 public function __call($name, $arguments)16 {17 }18 public function __callStatic($name, $arguments)19 {20 }21 public function __get($name)22 {23 }24 public function __set($name, $value)25 {26 }27 public function __isset($name)28 {29 }30 public function __unset($name)31 {32 }33 public function __sleep()34 {35 }36 public function __wakeup()37 {38 }

Full Screen

Full Screen

getMockedMethods

Using AI Code Generation

copy

Full Screen

1$generator = new Generator;2$generator->getMockedMethods('TestClass');3class TestClass {4 public function __construct() {5 }6 public function __destruct() {7 }8 public function __set($name, $value) {9 }10 public function __get($name) {11 }12 public function __call($name, $arguments) {13 }14 public function __callStatic($name, $arguments) {15 }16 public function __isset($name) {17 }18 public function __unset($name) {19 }20 public function __sleep() {21 }22 public function __wakeup() {23 }24 public function __toString() {25 }26 public function __invoke() {27 }28 public function __set_state($an_array) {29 }30 public function __clone() {31 }32 public function __debugInfo() {33 }34 public function method1($arg1, $arg2) {35 }36 public function method2($arg1, $arg2) {37 }38 public function method3($arg1, $arg2) {39 }40 public function method4($arg1, $arg2) {41 }42 public function method5($arg1, $arg2) {43 }44 public function method6($arg1, $arg2) {45 }46 public function method7($arg1, $arg2) {47 }48 public function method8($arg1, $arg2) {49 }50 public function method9($arg1, $arg2) {51 }52 public function method10($arg1, $arg2) {53 }54 public function method11($arg1, $arg2) {55 }56 public function method12($arg1, $arg2) {57 }58 public function method13($arg1, $arg2) {59 }60 public function method14($arg1, $arg2) {61 }62 public function method15($arg1, $arg2) {63 }64 public function method16($arg1, $arg2) {65 }66 public function method17($arg1, $arg2) {67 }68 public function method18($arg1, $arg2) {69 }70 public function method19($arg1, $arg2) {71 }

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

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