Best Atoum code snippet using controller.__construct
generator.php
Source:generator.php
...6use mageekguy\atoum\test\adapter\call\decorators;7require_once __DIR__ . '/../../runner.php';8class generator extends atoum\test9{10 public function test__construct()11 {12 $this13 ->if($generator = new testedClass())14 ->then15 ->object($generator->getAdapter())->isEqualTo(new atoum\adapter())16 ->boolean($generator->callsToParentClassAreShunted())->isFalse()17 ;18 }19 public function testSetAdapter()20 {21 $this22 ->if($generator = new testedClass())23 ->then24 ->object($generator->setAdapter($adapter = new atoum\adapter()))->isIdenticalTo($generator)25 ->object($generator->getAdapter())->isIdenticalTo($adapter)26 ->object($generator->setAdapter())->isIdenticalTo($generator)27 ->object($generator->getAdapter())28 ->isInstanceOf(atoum\adapter::class)29 ->isNotIdenticalTo($adapter)30 ->isEqualTo(new atoum\adapter())31 ;32 }33 public function testSetReflectionClassFactory()34 {35 $this36 ->if($generator = new testedClass())37 ->then38 ->object($generator->setReflectionClassFactory($factory = function () {39 }))->isIdenticalTo($generator)40 ->object($generator->getReflectionClassFactory())->isIdenticalTo($factory)41 ->object($generator->setReflectionClassFactory())->isIdenticalTo($generator)42 ->object($defaultReflectionClassFactory = $generator->getReflectionClassFactory())43 ->isInstanceOf(\closure::class)44 ->isNotIdenticalTo($factory)45 ->object($defaultReflectionClassFactory($this))->isEqualTo(new \reflectionClass($this))46 ;47 }48 public function testSetDefaultNamespace()49 {50 $this51 ->if($generator = new testedClass())52 ->then53 ->object($generator->setDefaultNamespace($namespace = uniqid()))->isIdenticalTo($generator)54 ->string($generator->getDefaultNamespace())->isEqualTo($namespace)55 ->object($generator->setDefaultNamespace('\\' . $namespace))->isIdenticalTo($generator)56 ->string($generator->getDefaultNamespace())->isEqualTo($namespace)57 ->object($generator->setDefaultNamespace('\\' . $namespace . '\\'))->isIdenticalTo($generator)58 ->string($generator->getDefaultNamespace())->isEqualTo($namespace)59 ->object($generator->setDefaultNamespace($namespace . '\\'))->isIdenticalTo($generator)60 ->string($generator->getDefaultNamespace())->isEqualTo($namespace)61 ;62 }63 public function testShuntCallsToParentClass()64 {65 $this66 ->if($generator = new testedClass())67 ->then68 ->object($generator->shuntParentClassCalls())->isIdenticalTo($generator)69 ->boolean($generator->callsToParentClassAreShunted())->isTrue()70 ;71 }72 public function testUnshuntParentClassCalls()73 {74 $this75 ->if($generator = new testedClass())76 ->then77 ->object($generator->unshuntParentClassCalls())->isIdenticalTo($generator)78 ->boolean($generator->callsToParentClassAreShunted())->isFalse()79 ->if($generator->shuntParentClassCalls())80 ->then81 ->object($generator->unshuntParentClassCalls())->isIdenticalTo($generator)82 ->boolean($generator->callsToParentClassAreShunted())->isFalse()83 ;84 }85 public function testAllIsInterface()86 {87 $this88 ->if($generator = new testedClass())89 ->then90 ->object($generator->allIsInterface())->isIdenticalTo($generator)91 ;92 }93 public function testTestedClassIs()94 {95 $this96 ->if($generator = new testedClass())97 ->then98 ->object($generator->testedClassIs(uniqid()))->isIdenticalTo($generator)99 ;100 }101 public function testOverload()102 {103 $this104 ->if($generator = new testedClass())105 ->then106 ->object($generator->overload(new mock\php\method($method = uniqid())))->isIdenticalTo($generator)107 ->boolean($generator->isOverloaded($method))->isTrue()108 ;109 }110 public function testIsOverloaded()111 {112 $this113 ->if($generator = new testedClass())114 ->then115 ->boolean($generator->isOverloaded(uniqid()))->isFalse()116 ->if($generator->overload(new mock\php\method($method = uniqid())))117 ->then118 ->boolean($generator->isOverloaded($method))->isTrue()119 ;120 }121 public function testGetOverload()122 {123 $this124 ->if($generator = new testedClass())125 ->then126 ->variable($generator->getOverload(uniqid()))->isNull()127 ->if($generator->overload($overload = new mock\php\method(uniqid())))128 ->then129 ->object($generator->getOverload($overload->getName()))->isIdenticalTo($overload)130 ;131 }132 public function testShunt()133 {134 $this135 ->if($generator = new testedClass())136 ->then137 ->object($generator->shunt($method = uniqid()))->isIdenticalTo($generator)138 ->boolean($generator->isShunted($method))->isTrue()139 ->boolean($generator->isShunted(strtoupper($method)))->isTrue()140 ->boolean($generator->isShunted(strtolower($method)))->isTrue()141 ->boolean($generator->isShunted(uniqid()))->isFalse()142 ;143 }144 public function testDisallowUndefinedMethodUsage()145 {146 $this147 ->if($generator = new testedClass())148 ->then149 ->object($generator->disallowUndefinedMethodUsage())->isIdenticalTo($generator)150 ;151 }152 public function testOrphanize()153 {154 $this155 ->if($generator = new testedClass())156 ->then157 ->object($generator->orphanize($method = uniqid()))->isIdenticalTo($generator)158 ->boolean($generator->isOrphanized($method))->isTrue()159 ->boolean($generator->isShunted($method))->isTrue()160 ;161 }162 public function testGetMockedClassCodeForUnknownClass()163 {164 $this165 ->if($generator = new testedClass())166 ->and($adapter = new atoum\test\adapter())167 ->and($adapter->class_exists = false)168 ->and($generator->setAdapter($adapter))169 ->then170 ->string($generator->getMockedClassCode($unknownClass = uniqid()))->isEqualTo(171 'namespace mock {' . PHP_EOL .172 'final class ' . $unknownClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .173 '{' . PHP_EOL .174 $this->getMockControllerMethods() .175 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .176 "\t" . '{' . PHP_EOL .177 "\t\t" . 'if ($mockController === null)' . PHP_EOL .178 "\t\t" . '{' . PHP_EOL .179 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .180 "\t\t" . '}' . PHP_EOL .181 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .182 "\t\t" . '{' . PHP_EOL .183 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .184 "\t\t" . '}' . PHP_EOL .185 "\t\t" . '$this->getMockController()->disableMethodChecking();' . PHP_EOL .186 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .187 "\t\t" . '{' . PHP_EOL .188 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .189 "\t\t" . '}' . PHP_EOL .190 "\t" . '}' . PHP_EOL .191 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .192 "\t" . '{' . PHP_EOL .193 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .194 "\t\t" . '{' . PHP_EOL .195 "\t\t\t" . '$return = $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .196 "\t\t\t" . 'return $return;' . PHP_EOL .197 "\t\t" . '}' . PHP_EOL .198 "\t\t" . 'else' . PHP_EOL .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\t" . '};' . PHP_EOL .876 "\t\t" . '}' . PHP_EOL .877 "\t\t" . '$return = $this->getMockController()->invoke(\'foo\', $arguments);' . PHP_EOL .878 "\t\t" . 'return $return;' . PHP_EOL .879 "\t" . '}' . PHP_EOL .880 "\t" . 'public static function getMockedMethods()' . PHP_EOL .881 "\t" . '{' . PHP_EOL .882 "\t\t" . 'return ' . var_export(['__construct', 'foo'], true) . ';' . PHP_EOL .883 "\t" . '}' . PHP_EOL .884 '}' . PHP_EOL .885 '}'886 )887 ->if($generator->testedClassIs($realClass))888 ->then889 ->string($generator->getMockedClassCode($realClass))->isEqualTo(890 'namespace mock {' . PHP_EOL .891 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .892 '{' . PHP_EOL .893 $this->getMockControllerMethods() .894 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .895 "\t" . '{' . PHP_EOL .896 "\t\t" . 'if ($mockController === null)' . PHP_EOL .897 "\t\t" . '{' . PHP_EOL .898 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .899 "\t\t" . '}' . PHP_EOL .900 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .901 "\t\t" . '{' . PHP_EOL .902 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .903 "\t\t" . '}' . PHP_EOL .904 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .905 "\t\t" . '{' . PHP_EOL .906 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .907 "\t\t" . '}' . PHP_EOL .908 "\t" . '}' . PHP_EOL .909 "\t" . 'public function foo()' . PHP_EOL .910 "\t" . '{' . PHP_EOL .911 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .912 "\t\t" . 'if (isset($this->getMockController()->foo) === true)' . PHP_EOL .913 "\t\t" . '{' . PHP_EOL .914 "\t\t\t" . '$return = $this->getMockController()->invoke(\'foo\', $arguments);' . PHP_EOL .915 "\t\t\t" . 'return $return;' . PHP_EOL .916 "\t\t" . '}' . PHP_EOL .917 "\t\t" . 'else' . PHP_EOL .918 "\t\t" . '{' . PHP_EOL .919 "\t\t\t" . '$this->getMockController()->addCall(\'foo\', $arguments);' . PHP_EOL .920 "\t\t" . '}' . PHP_EOL .921 "\t" . '}' . PHP_EOL .922 "\t" . 'public static function getMockedMethods()' . PHP_EOL .923 "\t" . '{' . PHP_EOL .924 "\t\t" . 'return ' . var_export(['__construct', 'foo'], true) . ';' . PHP_EOL .925 "\t" . '}' . PHP_EOL .926 '}' . PHP_EOL .927 '}'928 )929 ;930 if (version_compare(PHP_VERSION, '5.6.0', '>=')) {931 $this932 ->given($generator = new testedClass())933 ->if($generator->allIsInterface())934 ->then935 ->string($generator->getMockedClassCode('mageekguy\atoum\tests\units\mock\classWithVariadicInConstructor'))->isEqualTo(936 'namespace mock\mageekguy\atoum\tests\units\mock {' . PHP_EOL .937 'final class classWithVariadicInConstructor extends \mageekguy\atoum\tests\units\mock\classWithVariadicInConstructor implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .938 '{' . PHP_EOL .939 $this->getMockControllerMethods() .940 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .941 "\t" . '{' . PHP_EOL .942 "\t\t" . 'if ($mockController === null)' . PHP_EOL .943 "\t\t" . '{' . PHP_EOL .944 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .945 "\t\t" . '}' . PHP_EOL .946 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .947 "\t\t" . '{' . PHP_EOL .948 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .949 "\t\t" . '}' . PHP_EOL .950 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .951 "\t\t" . '{' . PHP_EOL .952 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .953 "\t\t" . '}' . PHP_EOL .954 "\t" . '}' . PHP_EOL .955 "\t" . 'public static function getMockedMethods()' . PHP_EOL .956 "\t" . '{' . PHP_EOL .957 "\t\t" . 'return ' . var_export(['__construct'], true) . ';' . PHP_EOL .958 "\t" . '}' . PHP_EOL .959 '}' . PHP_EOL .960 '}'961 )962 ;963 }964 }965 /** @php >= 7.0 */966 public function testGetMockedClassCodeWithAllIsInterfacePhp7()967 {968 $this969 ->if($generator = new testedClass())970 ->and($realClass = uniqid())971 ->and($reflectionMethodController = new mock\controller())972 ->and($reflectionMethodController->__construct = function () {973 })974 ->and($reflectionMethodController->getName = 'foo')975 ->and($reflectionMethodController->isConstructor = false)976 ->and($reflectionMethodController->getParameters = [])977 ->and($reflectionMethodController->isPublic = true)978 ->and($reflectionMethodController->isProtected = false)979 ->and($reflectionMethodController->isPrivate = false)980 ->and($reflectionMethodController->isFinal = false)981 ->and($reflectionMethodController->isAbstract = false)982 ->and($reflectionMethodController->isStatic = false)983 ->and($reflectionMethodController->returnsReference = false)984 ->and($reflectionMethodController->hasReturnType = false)985 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))986 ->and($reflectionClassController = new mock\controller())987 ->and($reflectionClassController->__construct = function () {988 })989 ->and($reflectionClassController->getName = function () use ($realClass) {990 return $realClass;991 })992 ->and($reflectionClassController->isFinal = false)993 ->and($reflectionClassController->isInterface = false)994 ->and($reflectionClassController->getMethods = [$reflectionMethod])995 ->and($reflectionClassController->getConstructor = null)996 ->and($reflectionClassController->isAbstract = false)997 ->and($reflectionClass = new \mock\reflectionClass(null))998 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {999 return $reflectionClass;1000 }))1001 ->and($adapter = new atoum\test\adapter())1002 ->and($adapter->class_exists = function ($class) use ($realClass) {1003 return ($class == '\\' . $realClass);1004 })1005 ->and($generator->setAdapter($adapter))1006 ->and($generator->shunt('__construct'))1007 ->and($generator->allIsInterface())1008 ->then1009 ->string($generator->getMockedClassCode($realClass))->isEqualTo(1010 'namespace mock {' . PHP_EOL .1011 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .1012 '{' . PHP_EOL .1013 $this->getMockControllerMethods() .1014 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1015 "\t" . '{' . PHP_EOL .1016 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1017 "\t\t" . '{' . PHP_EOL .1018 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1019 "\t\t" . '}' . PHP_EOL .1020 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1021 "\t\t" . '{' . PHP_EOL .1022 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1023 "\t\t" . '}' . PHP_EOL .1024 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .1025 "\t\t" . '{' . PHP_EOL .1026 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .1027 "\t\t" . '}' . PHP_EOL .1028 "\t" . '}' . PHP_EOL .1029 "\t" . 'public function foo()' . PHP_EOL .1030 "\t" . '{' . PHP_EOL .1031 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .1032 "\t\t" . 'if (isset($this->getMockController()->foo) === false)' . PHP_EOL .1033 "\t\t" . '{' . PHP_EOL .1034 "\t\t\t" . '$this->getMockController()->foo = function() {' . PHP_EOL .1035 "\t\t\t" . '};' . PHP_EOL .1036 "\t\t" . '}' . PHP_EOL .1037 "\t\t" . '$return = $this->getMockController()->invoke(\'foo\', $arguments);' . PHP_EOL .1038 "\t\t" . 'return $return;' . PHP_EOL .1039 "\t" . '}' . PHP_EOL .1040 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1041 "\t" . '{' . PHP_EOL .1042 "\t\t" . 'return ' . var_export(['__construct', 'foo'], true) . ';' . PHP_EOL .1043 "\t" . '}' . PHP_EOL .1044 '}' . PHP_EOL .1045 '}'1046 )1047 ->if($generator->testedClassIs($realClass))1048 ->then1049 ->string($generator->getMockedClassCode($realClass))->isEqualTo(1050 'namespace mock {' . PHP_EOL .1051 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .1052 '{' . PHP_EOL .1053 $this->getMockControllerMethods() .1054 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1055 "\t" . '{' . PHP_EOL .1056 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1057 "\t\t" . '{' . PHP_EOL .1058 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1059 "\t\t" . '}' . PHP_EOL .1060 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1061 "\t\t" . '{' . PHP_EOL .1062 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1063 "\t\t" . '}' . PHP_EOL .1064 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .1065 "\t\t" . '{' . PHP_EOL .1066 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .1067 "\t\t" . '}' . PHP_EOL .1068 "\t" . '}' . PHP_EOL .1069 "\t" . 'public function foo()' . PHP_EOL .1070 "\t" . '{' . PHP_EOL .1071 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .1072 "\t\t" . 'if (isset($this->getMockController()->foo) === true)' . PHP_EOL .1073 "\t\t" . '{' . PHP_EOL .1074 "\t\t\t" . '$return = $this->getMockController()->invoke(\'foo\', $arguments);' . PHP_EOL .1075 "\t\t\t" . 'return $return;' . PHP_EOL .1076 "\t\t" . '}' . PHP_EOL .1077 "\t\t" . 'else' . PHP_EOL .1078 "\t\t" . '{' . PHP_EOL .1079 "\t\t\t" . '$this->getMockController()->addCall(\'foo\', $arguments);' . PHP_EOL .1080 "\t\t" . '}' . PHP_EOL .1081 "\t" . '}' . PHP_EOL .1082 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1083 "\t" . '{' . PHP_EOL .1084 "\t\t" . 'return ' . var_export(['__construct', 'foo'], true) . ';' . PHP_EOL .1085 "\t" . '}' . PHP_EOL .1086 '}' . PHP_EOL .1087 '}'1088 )1089 ->given($generator = new testedClass())1090 ->if($generator->allIsInterface())1091 ->then1092 ->string($generator->getMockedClassCode('mageekguy\atoum\tests\units\mock\classWithVariadicInConstructor'))->isEqualTo(1093 'namespace mock\mageekguy\atoum\tests\units\mock {' . PHP_EOL .1094 'final class classWithVariadicInConstructor extends \mageekguy\atoum\tests\units\mock\classWithVariadicInConstructor implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .1095 '{' . PHP_EOL .1096 $this->getMockControllerMethods() .1097 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1098 "\t" . '{' . PHP_EOL .1099 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1100 "\t\t" . '{' . PHP_EOL .1101 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1102 "\t\t" . '}' . PHP_EOL .1103 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1104 "\t\t" . '{' . PHP_EOL .1105 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1106 "\t\t" . '}' . PHP_EOL .1107 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .1108 "\t\t" . '{' . PHP_EOL .1109 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .1110 "\t\t" . '}' . PHP_EOL .1111 "\t" . '}' . PHP_EOL .1112 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1113 "\t" . '{' . PHP_EOL .1114 "\t\t" . 'return ' . var_export(['__construct'], true) . ';' . PHP_EOL .1115 "\t" . '}' . PHP_EOL .1116 '}' . PHP_EOL .1117 '}'1118 )1119 ;1120 }1121 /** @php < 7.0 */1122 public function testGetMockedClassCodeWithCloneMethod()1123 {1124 $this1125 ->if($generator = new testedClass())1126 ->and($realClass = uniqid())1127 ->and($reflectionMethodController = new mock\controller())1128 ->and($reflectionMethodController->__construct = function () {1129 })1130 ->and($reflectionMethodController->getName = 'clone')1131 ->and($reflectionMethodController->isConstructor = false)1132 ->and($reflectionMethodController->isAbstract = false)1133 ->and($reflectionMethodController->getParameters = [])1134 ->and($reflectionMethodController->isPublic = true)1135 ->and($reflectionMethodController->isProtected = false)1136 ->and($reflectionMethodController->isPrivate = false)1137 ->and($reflectionMethodController->isFinal = false)1138 ->and($reflectionMethodController->isStatic = false)1139 ->and($reflectionMethodController->returnsReference = false)1140 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))1141 ->and($reflectionClassController = new mock\controller())1142 ->and($reflectionClassController->__construct = function () {1143 })1144 ->and($reflectionClassController->getName = $realClass)1145 ->and($reflectionClassController->isFinal = false)1146 ->and($reflectionClassController->isInterface = false)1147 ->and($reflectionClassController->getMethods = [$reflectionMethod])1148 ->and($reflectionClassController->getConstructor = null)1149 ->and($reflectionClassController->isAbstract = false)1150 ->and($reflectionClass = new \mock\reflectionClass(null))1151 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {1152 return $reflectionClass;1153 }))1154 ->and($adapter = new atoum\test\adapter())1155 ->and($adapter->class_exists = function ($class) use ($realClass) {1156 return ($class == '\\' . $realClass);1157 })1158 ->and($generator->setAdapter($adapter))1159 ->then1160 ->string($generator->getMockedClassCode($realClass))->isEqualTo(1161 'namespace mock {' . PHP_EOL .1162 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .1163 '{' . PHP_EOL .1164 $this->getMockControllerMethods() .1165 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1166 "\t" . '{' . PHP_EOL .1167 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1168 "\t\t" . '{' . PHP_EOL .1169 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1170 "\t\t" . '}' . PHP_EOL .1171 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1172 "\t\t" . '{' . PHP_EOL .1173 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1174 "\t\t" . '}' . PHP_EOL .1175 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .1176 "\t\t" . '{' . PHP_EOL .1177 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .1178 "\t\t" . '}' . PHP_EOL .1179 "\t" . '}' . PHP_EOL .1180 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1181 "\t" . '{' . PHP_EOL .1182 "\t\t" . 'return ' . var_export(['__construct'], true) . ';' . PHP_EOL .1183 "\t" . '}' . PHP_EOL .1184 '}' . PHP_EOL .1185 '}'1186 )1187 ;1188 }1189 public function testGetMockedClassCodeWithShuntedDeprecatedConstructor()1190 {1191 $this1192 ->if($generator = new testedClass())1193 ->and($reflectionMethodController = new mock\controller())1194 ->and($reflectionMethodController->__construct = function () {1195 })1196 ->and($reflectionMethodController->getName = $realClass = uniqid())1197 ->and($reflectionMethodController->isConstructor = true)1198 ->and($reflectionMethodController->isAbstract = false)1199 ->and($reflectionMethodController->getParameters = [])1200 ->and($reflectionMethodController->isPublic = true)1201 ->and($reflectionMethodController->isProtected = false)1202 ->and($reflectionMethodController->isPrivate = false)1203 ->and($reflectionMethodController->isFinal = false)1204 ->and($reflectionMethodController->isStatic = false)1205 ->and($reflectionMethodController->returnsReference = false)1206 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))1207 ->and($reflectionClassController = new mock\controller())1208 ->and($reflectionClassController->__construct = function () {1209 })1210 ->and($reflectionClassController->getName = $realClass)1211 ->and($reflectionClassController->isFinal = false)1212 ->and($reflectionClassController->isInterface = false)1213 ->and($reflectionClassController->getMethods = [$reflectionMethod])1214 ->and($reflectionClassController->getConstructor = $reflectionMethod)1215 ->and($reflectionClassController->isAbstract = false)1216 ->and($reflectionClass = new \mock\reflectionClass(null))1217 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {1218 return $reflectionClass;1219 }))1220 ->and($adapter = new atoum\test\adapter())1221 ->and($adapter->class_exists = function ($class) use ($realClass) {1222 return ($class == '\\' . $realClass);1223 })1224 ->and($generator->setAdapter($adapter))1225 ->and($generator->shunt($realClass))1226 ->then1227 ->string($generator->getMockedClassCode($realClass))->isEqualTo(1228 'namespace mock {' . PHP_EOL .1229 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .1230 '{' . PHP_EOL .1231 $this->getMockControllerMethods() .1232 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1233 "\t" . '{' . PHP_EOL .1234 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .1235 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1236 "\t\t" . '{' . PHP_EOL .1237 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1238 "\t\t" . '}' . PHP_EOL .1239 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1240 "\t\t" . '{' . PHP_EOL .1241 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1242 "\t\t" . '}' . PHP_EOL .1243 "\t\t" . 'if (isset($this->getMockController()->' . $realClass . ') === false)' . PHP_EOL .1244 "\t\t" . '{' . PHP_EOL .1245 "\t\t\t" . '$this->getMockController()->' . $realClass . ' = function() {};' . PHP_EOL .1246 "\t\t" . '}' . PHP_EOL .1247 "\t\t" . '$this->getMockController()->invoke(\'' . $realClass . '\', $arguments);' . PHP_EOL .1248 "\t" . '}' . PHP_EOL .1249 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1250 "\t" . '{' . PHP_EOL .1251 "\t\t" . 'return ' . var_export([$realClass], true) . ';' . PHP_EOL .1252 "\t" . '}' . PHP_EOL .1253 '}' . PHP_EOL .1254 '}'1255 )1256 ;1257 }1258 /** @php < 7.0 */1259 public function testGetMockedClassCodeForInterface()1260 {1261 $this1262 ->if($generator = new testedClass())1263 ->and($reflectionMethodController = new mock\controller())1264 ->and($reflectionMethodController->__construct = function () {1265 })1266 ->and($reflectionMethodController->getName = '__construct')1267 ->and($reflectionMethodController->isConstructor = true)1268 ->and($reflectionMethodController->getParameters = [])1269 ->and($reflectionMethodController->isFinal = false)1270 ->and($reflectionMethodController->isStatic = false)1271 ->and($reflectionMethodController->returnsReference = false)1272 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))1273 ->and($reflectionClassController = new mock\controller())1274 ->and($reflectionClassController->__construct = function () {1275 })1276 ->and($reflectionClassController->getName = function () use (& $realClass) {1277 return $realClass;1278 })1279 ->and($reflectionClassController->isFinal = false)1280 ->and($reflectionClassController->isInterface = true)1281 ->and($reflectionClassController->getMethods = [$reflectionMethod])1282 ->and($reflectionClassController->isInstantiable = false)1283 ->and($reflectionClassController->implementsInterface = false)1284 ->and($reflectionClass = new \mock\reflectionClass(null))1285 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {1286 return $reflectionClass;1287 }))1288 ->and($adapter = new atoum\test\adapter())1289 ->and($adapter->class_exists = function ($class) use (& $realClass) {1290 return ($class == '\\' . $realClass);1291 })1292 ->and($generator->setAdapter($adapter))1293 ->then1294 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(1295 'namespace mock {' . PHP_EOL .1296 'final class ' . $realClass . ' implements \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .1297 '{' . PHP_EOL .1298 $this->getMockControllerMethods() .1299 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1300 "\t" . '{' . PHP_EOL .1301 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .1302 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1303 "\t\t" . '{' . PHP_EOL .1304 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1305 "\t\t" . '}' . PHP_EOL .1306 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1307 "\t\t" . '{' . PHP_EOL .1308 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1309 "\t\t" . '}' . PHP_EOL .1310 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .1311 "\t\t" . '{' . PHP_EOL .1312 "\t\t\t" . '$this->getMockController()->__construct = function() {' . PHP_EOL .1313 "\t\t\t" . '};' . PHP_EOL .1314 "\t\t" . '}' . PHP_EOL .1315 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .1316 "\t" . '}' . PHP_EOL .1317 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .1318 "\t" . '{' . PHP_EOL .1319 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .1320 "\t\t" . '{' . PHP_EOL .1321 "\t\t\t" . '$return = $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .1322 "\t\t\t" . 'return $return;' . PHP_EOL .1323 "\t\t" . '}' . PHP_EOL .1324 "\t\t" . 'else' . PHP_EOL .1325 "\t\t" . '{' . PHP_EOL .1326 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .1327 "\t\t" . '}' . PHP_EOL .1328 "\t" . '}' . PHP_EOL .1329 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1330 "\t" . '{' . PHP_EOL .1331 "\t\t" . 'return ' . var_export(['__construct', '__call'], true) . ';' . PHP_EOL .1332 "\t" . '}' . PHP_EOL .1333 '}' . PHP_EOL .1334 '}'1335 )1336 ->if($reflectionClassController->implementsInterface = function ($interface) {1337 return ($interface == 'traversable' ? true : false);1338 })1339 ->and($generator->setReflectionClassFactory(function ($class) use ($reflectionClass) {1340 return ($class == 'iteratorAggregate' ? new \reflectionClass('iteratorAggregate') : $reflectionClass);1341 }))1342 ->then1343 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(1344 'namespace mock {' . PHP_EOL .1345 'final class ' . $realClass . ' implements \\iteratorAggregate, \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .1346 '{' . PHP_EOL .1347 $this->getMockControllerMethods() .1348 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1349 "\t" . '{' . PHP_EOL .1350 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .1351 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1352 "\t\t" . '{' . PHP_EOL .1353 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1354 "\t\t" . '}' . PHP_EOL .1355 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1356 "\t\t" . '{' . PHP_EOL .1357 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1358 "\t\t" . '}' . PHP_EOL .1359 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .1360 "\t\t" . '{' . PHP_EOL .1361 "\t\t\t" . '$this->getMockController()->__construct = function() {' . PHP_EOL .1362 "\t\t\t" . '};' . PHP_EOL .1363 "\t\t" . '}' . PHP_EOL .1364 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .1365 "\t" . '}' . PHP_EOL .1366 "\t" . 'public function getIterator()' . PHP_EOL .1367 "\t" . '{' . PHP_EOL .1368 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .1369 "\t\t" . 'if (isset($this->getMockController()->getIterator) === false)' . PHP_EOL .1370 "\t\t" . '{' . PHP_EOL .1371 "\t\t\t" . '$this->getMockController()->getIterator = function() {' . PHP_EOL .1372 "\t\t\t" . '};' . PHP_EOL .1373 "\t\t" . '}' . PHP_EOL .1374 "\t\t" . '$return = $this->getMockController()->invoke(\'getIterator\', $arguments);' . PHP_EOL .1375 "\t\t" . 'return $return;' . PHP_EOL .1376 "\t" . '}' . PHP_EOL .1377 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .1378 "\t" . '{' . PHP_EOL .1379 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .1380 "\t\t" . '{' . PHP_EOL .1381 "\t\t\t" . '$return = $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .1382 "\t\t\t" . 'return $return;' . PHP_EOL .1383 "\t\t" . '}' . PHP_EOL .1384 "\t\t" . 'else' . PHP_EOL .1385 "\t\t" . '{' . PHP_EOL .1386 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .1387 "\t\t" . '}' . PHP_EOL .1388 "\t" . '}' . PHP_EOL .1389 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1390 "\t" . '{' . PHP_EOL .1391 "\t\t" . 'return ' . var_export(['__construct', 'getiterator', '__call'], true) . ';' . PHP_EOL .1392 "\t" . '}' . PHP_EOL .1393 '}' . PHP_EOL .1394 '}'1395 )1396 ->if($generator = new testedClass())1397 ->and($reflectionMethodController = new mock\controller())1398 ->and($reflectionMethodController->__construct = function () {1399 })1400 ->and($reflectionMethodController->getName = '__construct')1401 ->and($reflectionMethodController->isConstructor = true)1402 ->and($reflectionMethodController->getParameters = [])1403 ->and($reflectionMethodController->isFinal = false)1404 ->and($reflectionMethodController->isStatic = false)1405 ->and($reflectionMethodController->returnsReference = false)1406 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))1407 ->and($reflectionClassController = new mock\controller())1408 ->and($reflectionClassController->__construct = function () {1409 })1410 ->and($reflectionClassController->getName = function () use (& $realClass) {1411 return $realClass;1412 })1413 ->and($reflectionClassController->isFinal = false)1414 ->and($reflectionClassController->isInterface = true)1415 ->and($reflectionClassController->getMethods = [$reflectionMethod])1416 ->and($reflectionClassController->isInstantiable = false)1417 ->and($reflectionClassController->implementsInterface = false)1418 ->and($reflectionClass = new \mock\reflectionClass(null))1419 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {1420 return $reflectionClass;1421 }))1422 ->and($adapter = new atoum\test\adapter())1423 ->and($adapter->class_exists = function ($class) use (& $realClass) {1424 return ($class == '\\' . $realClass);1425 })1426 ->and($generator->setAdapter($adapter))1427 ->and($generator->disallowUndefinedMethodUsage())1428 ->then1429 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(1430 'namespace mock {' . PHP_EOL .1431 'final class ' . $realClass . ' implements \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .1432 '{' . PHP_EOL .1433 $this->getMockControllerMethods() .1434 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1435 "\t" . '{' . PHP_EOL .1436 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .1437 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1438 "\t\t" . '{' . PHP_EOL .1439 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1440 "\t\t" . '}' . PHP_EOL .1441 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1442 "\t\t" . '{' . PHP_EOL .1443 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1444 "\t\t" . '}' . PHP_EOL .1445 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .1446 "\t\t" . '{' . PHP_EOL .1447 "\t\t\t" . '$this->getMockController()->__construct = function() {' . PHP_EOL .1448 "\t\t\t" . '};' . PHP_EOL .1449 "\t\t" . '}' . PHP_EOL .1450 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .1451 "\t" . '}' . PHP_EOL .1452 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1453 "\t" . '{' . PHP_EOL .1454 "\t\t" . 'return ' . var_export(['__construct'], true) . ';' . PHP_EOL .1455 "\t" . '}' . PHP_EOL .1456 '}' . PHP_EOL .1457 '}'1458 )1459 ;1460 }1461 /** @php >= 7.0 */1462 public function testGetMockedClassCodeForInterfacePhp7()1463 {1464 $this1465 ->if($generator = new testedClass())1466 ->and($reflectionMethodController = new mock\controller())1467 ->and($reflectionMethodController->__construct = function () {1468 })1469 ->and($reflectionMethodController->getName = '__construct')1470 ->and($reflectionMethodController->isConstructor = true)1471 ->and($reflectionMethodController->getParameters = [])1472 ->and($reflectionMethodController->isFinal = false)1473 ->and($reflectionMethodController->isStatic = false)1474 ->and($reflectionMethodController->returnsReference = false)1475 ->and($reflectionMethodController->hasReturnType = false)1476 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))1477 ->and($reflectionClassController = new mock\controller())1478 ->and($reflectionClassController->__construct = function () {1479 })1480 ->and($reflectionClassController->getName = function () use (& $realClass) {1481 return $realClass;1482 })1483 ->and($reflectionClassController->isFinal = false)1484 ->and($reflectionClassController->isInterface = true)1485 ->and($reflectionClassController->getMethods = [$reflectionMethod])1486 ->and($reflectionClassController->isInstantiable = false)1487 ->and($reflectionClassController->implementsInterface = false)1488 ->and($reflectionClass = new \mock\reflectionClass(null))1489 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {1490 return $reflectionClass;1491 }))1492 ->and($adapter = new atoum\test\adapter())1493 ->and($adapter->class_exists = function ($class) use (& $realClass) {1494 return ($class == '\\' . $realClass);1495 })1496 ->and($generator->setAdapter($adapter))1497 ->then1498 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(1499 'namespace mock {' . PHP_EOL .1500 'final class ' . $realClass . ' implements \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .1501 '{' . PHP_EOL .1502 $this->getMockControllerMethods() .1503 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1504 "\t" . '{' . PHP_EOL .1505 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .1506 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1507 "\t\t" . '{' . PHP_EOL .1508 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1509 "\t\t" . '}' . PHP_EOL .1510 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1511 "\t\t" . '{' . PHP_EOL .1512 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1513 "\t\t" . '}' . PHP_EOL .1514 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .1515 "\t\t" . '{' . PHP_EOL .1516 "\t\t\t" . '$this->getMockController()->__construct = function() {' . PHP_EOL .1517 "\t\t\t" . '};' . PHP_EOL .1518 "\t\t" . '}' . PHP_EOL .1519 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .1520 "\t" . '}' . PHP_EOL .1521 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .1522 "\t" . '{' . PHP_EOL .1523 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .1524 "\t\t" . '{' . PHP_EOL .1525 "\t\t\t" . '$return = $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .1526 "\t\t\t" . 'return $return;' . PHP_EOL .1527 "\t\t" . '}' . PHP_EOL .1528 "\t\t" . 'else' . PHP_EOL .1529 "\t\t" . '{' . PHP_EOL .1530 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .1531 "\t\t" . '}' . PHP_EOL .1532 "\t" . '}' . PHP_EOL .1533 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1534 "\t" . '{' . PHP_EOL .1535 "\t\t" . 'return ' . var_export(['__construct', '__call'], true) . ';' . PHP_EOL .1536 "\t" . '}' . PHP_EOL .1537 '}' . PHP_EOL .1538 '}'1539 )1540 ->if($reflectionClassController->implementsInterface = function ($interface) {1541 return ($interface == 'traversable' ? true : false);1542 })1543 ->and($generator->setReflectionClassFactory(function ($class) use ($reflectionClass) {1544 return ($class == 'iteratorAggregate' ? new \reflectionClass('iteratorAggregate') : $reflectionClass);1545 }))1546 ->then1547 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(1548 'namespace mock {' . PHP_EOL .1549 'final class ' . $realClass . ' implements \\iteratorAggregate, \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .1550 '{' . PHP_EOL .1551 $this->getMockControllerMethods() .1552 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1553 "\t" . '{' . PHP_EOL .1554 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .1555 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1556 "\t\t" . '{' . PHP_EOL .1557 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1558 "\t\t" . '}' . PHP_EOL .1559 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1560 "\t\t" . '{' . PHP_EOL .1561 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1562 "\t\t" . '}' . PHP_EOL .1563 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .1564 "\t\t" . '{' . PHP_EOL .1565 "\t\t\t" . '$this->getMockController()->__construct = function() {' . PHP_EOL .1566 "\t\t\t" . '};' . PHP_EOL .1567 "\t\t" . '}' . PHP_EOL .1568 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .1569 "\t" . '}' . PHP_EOL .1570 "\t" . 'public function getIterator()' . PHP_EOL .1571 "\t" . '{' . PHP_EOL .1572 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .1573 "\t\t" . 'if (isset($this->getMockController()->getIterator) === false)' . PHP_EOL .1574 "\t\t" . '{' . PHP_EOL .1575 "\t\t\t" . '$this->getMockController()->getIterator = function() {' . PHP_EOL .1576 "\t\t\t" . '};' . PHP_EOL .1577 "\t\t" . '}' . PHP_EOL .1578 "\t\t" . '$return = $this->getMockController()->invoke(\'getIterator\', $arguments);' . PHP_EOL .1579 "\t\t" . 'return $return;' . PHP_EOL .1580 "\t" . '}' . PHP_EOL .1581 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .1582 "\t" . '{' . PHP_EOL .1583 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .1584 "\t\t" . '{' . PHP_EOL .1585 "\t\t\t" . '$return = $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .1586 "\t\t\t" . 'return $return;' . PHP_EOL .1587 "\t\t" . '}' . PHP_EOL .1588 "\t\t" . 'else' . PHP_EOL .1589 "\t\t" . '{' . PHP_EOL .1590 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .1591 "\t\t" . '}' . PHP_EOL .1592 "\t" . '}' . PHP_EOL .1593 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1594 "\t" . '{' . PHP_EOL .1595 "\t\t" . 'return ' . var_export(['__construct', 'getiterator', '__call'], true) . ';' . PHP_EOL .1596 "\t" . '}' . PHP_EOL .1597 '}' . PHP_EOL .1598 '}'1599 )1600 ->if($generator = new testedClass())1601 ->and($reflectionMethodController = new mock\controller())1602 ->and($reflectionMethodController->__construct = function () {1603 })1604 ->and($reflectionMethodController->getName = '__construct')1605 ->and($reflectionMethodController->isConstructor = true)1606 ->and($reflectionMethodController->getParameters = [])1607 ->and($reflectionMethodController->isFinal = false)1608 ->and($reflectionMethodController->isStatic = false)1609 ->and($reflectionMethodController->returnsReference = false)1610 ->and($reflectionMethodController->hasReturnType = false)1611 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))1612 ->and($reflectionClassController = new mock\controller())1613 ->and($reflectionClassController->__construct = function () {1614 })1615 ->and($reflectionClassController->getName = function () use (& $realClass) {1616 return $realClass;1617 })1618 ->and($reflectionClassController->isFinal = false)1619 ->and($reflectionClassController->isInterface = true)1620 ->and($reflectionClassController->getMethods = [$reflectionMethod])1621 ->and($reflectionClassController->isInstantiable = false)1622 ->and($reflectionClassController->implementsInterface = false)1623 ->and($reflectionClass = new \mock\reflectionClass(null))1624 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {1625 return $reflectionClass;1626 }))1627 ->and($adapter = new atoum\test\adapter())1628 ->and($adapter->class_exists = function ($class) use (& $realClass) {1629 return ($class == '\\' . $realClass);1630 })1631 ->and($generator->setAdapter($adapter))1632 ->and($generator->disallowUndefinedMethodUsage())1633 ->then1634 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(1635 'namespace mock {' . PHP_EOL .1636 'final class ' . $realClass . ' implements \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .1637 '{' . PHP_EOL .1638 $this->getMockControllerMethods() .1639 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1640 "\t" . '{' . PHP_EOL .1641 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .1642 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1643 "\t\t" . '{' . PHP_EOL .1644 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1645 "\t\t" . '}' . PHP_EOL .1646 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1647 "\t\t" . '{' . PHP_EOL .1648 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1649 "\t\t" . '}' . PHP_EOL .1650 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .1651 "\t\t" . '{' . PHP_EOL .1652 "\t\t\t" . '$this->getMockController()->__construct = function() {' . PHP_EOL .1653 "\t\t\t" . '};' . PHP_EOL .1654 "\t\t" . '}' . PHP_EOL .1655 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .1656 "\t" . '}' . PHP_EOL .1657 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1658 "\t" . '{' . PHP_EOL .1659 "\t\t" . 'return ' . var_export(['__construct'], true) . ';' . PHP_EOL .1660 "\t" . '}' . PHP_EOL .1661 '}' . PHP_EOL .1662 '}'1663 )1664 ;1665 }1666 /**1667 * @php >= 7.01668 */1669 public function testGetMockedClassCodeForInterfaceWithConstructorArguments()1670 {1671 $this1672 ->if($generator = new testedClass())1673 ->and($reflectionParameterController = new mock\controller())1674 ->and($reflectionParameterController->__construct = function () {1675 })1676 ->and($reflectionParameterController->isArray = true)1677 ->and($reflectionParameterController->getName = 'param')1678 ->and($reflectionParameterController->isPassedByReference = false)1679 ->and($reflectionParameterController->isDefaultValueAvailable = false)1680 ->and($reflectionParameterController->isOptional = false)1681 ->and($reflectionParameterController->isVariadic = false)1682 ->and($reflectionParameterController->allowsNull = false)1683 ->and($reflectionParameter = new \mock\reflectionParameter(null, null))1684 ->and($reflectionMethodController = new mock\controller())1685 ->and($reflectionMethodController->__construct = function () {1686 })1687 ->and($reflectionMethodController->getName = '__construct')1688 ->and($reflectionMethodController->isConstructor = true)1689 ->and($reflectionMethodController->getParameters = [$reflectionParameter])1690 ->and($reflectionMethodController->isFinal = false)1691 ->and($reflectionMethodController->isStatic = false)1692 ->and($reflectionMethodController->returnsReference = false)1693 ->and($reflectionMethodController->hasReturnType = false)1694 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))1695 ->and($reflectionClassController = new mock\controller())1696 ->and($reflectionClassController->__construct = function () {1697 })1698 ->and($reflectionClassController->getName = function () use (& $realClass) {1699 return $realClass;1700 })1701 ->and($reflectionClassController->isFinal = false)1702 ->and($reflectionClassController->isInterface = true)1703 ->and($reflectionClassController->getMethods = [$reflectionMethod])1704 ->and($reflectionClassController->isInstantiable = false)1705 ->and($reflectionClassController->implementsInterface = false)1706 ->and($reflectionClass = new \mock\reflectionClass(null))1707 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {1708 return $reflectionClass;1709 }))1710 ->and($adapter = new atoum\test\adapter())1711 ->and($adapter->class_exists = function ($class) use (& $realClass) {1712 return ($class == '\\' . $realClass);1713 })1714 ->and($generator->setAdapter($adapter))1715 ->then1716 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(1717 'namespace mock {' . PHP_EOL .1718 'final class ' . $realClass . ' implements \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .1719 '{' . PHP_EOL .1720 $this->getMockControllerMethods() .1721 "\t" . 'public function __construct(array $param, \mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1722 "\t" . '{' . PHP_EOL .1723 "\t\t" . '$arguments = array_merge(array($param), array_slice(func_get_args(), 1, -1));' . PHP_EOL .1724 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1725 "\t\t" . '{' . PHP_EOL .1726 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1727 "\t\t" . '}' . PHP_EOL .1728 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1729 "\t\t" . '{' . PHP_EOL .1730 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1731 "\t\t" . '}' . PHP_EOL .1732 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .1733 "\t\t" . '{' . PHP_EOL .1734 "\t\t\t" . '$this->getMockController()->__construct = function() {' . PHP_EOL .1735 "\t\t\t" . '};' . PHP_EOL .1736 "\t\t" . '}' . PHP_EOL .1737 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .1738 "\t" . '}' . PHP_EOL .1739 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .1740 "\t" . '{' . PHP_EOL .1741 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .1742 "\t\t" . '{' . PHP_EOL .1743 "\t\t\t" . '$return = $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .1744 "\t\t\t" . 'return $return;' . PHP_EOL .1745 "\t\t" . '}' . PHP_EOL .1746 "\t\t" . 'else' . PHP_EOL .1747 "\t\t" . '{' . PHP_EOL .1748 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .1749 "\t\t" . '}' . PHP_EOL .1750 "\t" . '}' . PHP_EOL .1751 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1752 "\t" . '{' . PHP_EOL .1753 "\t\t" . 'return ' . var_export(['__construct', '__call'], true) . ';' . PHP_EOL .1754 "\t" . '}' . PHP_EOL .1755 '}' . PHP_EOL .1756 '}'1757 )1758 ;1759 }1760 /**1761 * @php < 7.01762 */1763 public function testGetMockedClassCodeForInterfaceWithConstructorArgumentsPhp56()1764 {1765 $this1766 ->if($generator = new testedClass())1767 ->and($reflectionParameterController = new mock\controller())1768 ->and($reflectionParameterController->__construct = function () {1769 })1770 ->and($reflectionParameterController->isArray = true)1771 ->and($reflectionParameterController->getName = 'param')1772 ->and($reflectionParameterController->isPassedByReference = false)1773 ->and($reflectionParameterController->isDefaultValueAvailable = false)1774 ->and($reflectionParameterController->isOptional = false)1775 ->and($reflectionParameterController->isVariadic = false)1776 ->and($reflectionParameterController->allowsNull = false)1777 ->and($reflectionParameter = new \mock\reflectionParameter(null, null))1778 ->and($reflectionMethodController = new mock\controller())1779 ->and($reflectionMethodController->__construct = function () {1780 })1781 ->and($reflectionMethodController->getName = '__construct')1782 ->and($reflectionMethodController->isConstructor = true)1783 ->and($reflectionMethodController->getParameters = [$reflectionParameter])1784 ->and($reflectionMethodController->isFinal = false)1785 ->and($reflectionMethodController->isStatic = false)1786 ->and($reflectionMethodController->returnsReference = false)1787 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))1788 ->and($reflectionClassController = new mock\controller())1789 ->and($reflectionClassController->__construct = function () {1790 })1791 ->and($reflectionClassController->getName = function () use (& $realClass) {1792 return $realClass;1793 })1794 ->and($reflectionClassController->isFinal = false)1795 ->and($reflectionClassController->isInterface = true)1796 ->and($reflectionClassController->getMethods = [$reflectionMethod])1797 ->and($reflectionClassController->isInstantiable = false)1798 ->and($reflectionClassController->implementsInterface = false)1799 ->and($reflectionClass = new \mock\reflectionClass(null))1800 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {1801 return $reflectionClass;1802 }))1803 ->and($adapter = new atoum\test\adapter())1804 ->and($adapter->class_exists = function ($class) use (& $realClass) {1805 return ($class == '\\' . $realClass);1806 })1807 ->and($generator->setAdapter($adapter))1808 ->then1809 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(1810 'namespace mock {' . PHP_EOL .1811 'final class ' . $realClass . ' implements \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .1812 '{' . PHP_EOL .1813 $this->getMockControllerMethods() .1814 "\t" . 'public function __construct(array $param, \mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1815 "\t" . '{' . PHP_EOL .1816 "\t\t" . '$arguments = array_merge(array($param), array_slice(func_get_args(), 1, -1));' . PHP_EOL .1817 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1818 "\t\t" . '{' . PHP_EOL .1819 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1820 "\t\t" . '}' . PHP_EOL .1821 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1822 "\t\t" . '{' . PHP_EOL .1823 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1824 "\t\t" . '}' . PHP_EOL .1825 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .1826 "\t\t" . '{' . PHP_EOL .1827 "\t\t\t" . '$this->getMockController()->__construct = function() {' . PHP_EOL .1828 "\t\t\t" . '};' . PHP_EOL .1829 "\t\t" . '}' . PHP_EOL .1830 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .1831 "\t" . '}' . PHP_EOL .1832 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .1833 "\t" . '{' . PHP_EOL .1834 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .1835 "\t\t" . '{' . PHP_EOL .1836 "\t\t\t" . '$return = $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .1837 "\t\t\t" . 'return $return;' . PHP_EOL .1838 "\t\t" . '}' . PHP_EOL .1839 "\t\t" . 'else' . PHP_EOL .1840 "\t\t" . '{' . PHP_EOL .1841 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .1842 "\t\t" . '}' . PHP_EOL .1843 "\t" . '}' . PHP_EOL .1844 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1845 "\t" . '{' . PHP_EOL .1846 "\t\t" . 'return ' . var_export(['__construct', '__call'], true) . ';' . PHP_EOL .1847 "\t" . '}' . PHP_EOL .1848 '}' . PHP_EOL .1849 '}'1850 )1851 ;1852 }1853 /** @php < 7.0 */1854 public function testGetMockedClassCodeForInterfaceWithStaticMethod()1855 {1856 $this1857 ->if($generator = new testedClass())1858 ->and($reflectionMethodController = new mock\controller())1859 ->and($reflectionMethodController->__construct = function () {1860 })1861 ->and($reflectionMethodController->getName = $methodName = uniqid())1862 ->and($reflectionMethodController->isConstructor = false)1863 ->and($reflectionMethodController->getParameters = [])1864 ->and($reflectionMethodController->isFinal = false)1865 ->and($reflectionMethodController->isStatic = true)1866 ->and($reflectionMethodController->returnsReference = false)1867 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))1868 ->and($reflectionClassController = new mock\controller())1869 ->and($reflectionClassController->__construct = function () {1870 })1871 ->and($reflectionClassController->getName = function () use (& $realClass) {1872 return $realClass;1873 })1874 ->and($reflectionClassController->isFinal = false)1875 ->and($reflectionClassController->isInterface = true)1876 ->and($reflectionClassController->getMethods = [$reflectionMethod])1877 ->and($reflectionClassController->isInstantiable = false)1878 ->and($reflectionClassController->implementsInterface = false)1879 ->and($reflectionClass = new \mock\reflectionClass(null))1880 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {1881 return $reflectionClass;1882 }))1883 ->and($adapter = new atoum\test\adapter())1884 ->and($adapter->class_exists = function ($class) use (& $realClass) {1885 return ($class == '\\' . $realClass);1886 })1887 ->and($generator->setAdapter($adapter))1888 ->then1889 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(1890 'namespace mock {' . PHP_EOL .1891 'final class ' . $realClass . ' implements \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .1892 '{' . PHP_EOL .1893 $this->getMockControllerMethods() .1894 "\t" . 'public static function ' . $methodName . '()' . PHP_EOL .1895 "\t" . '{' . PHP_EOL .1896 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .1897 "\t\t" . 'return call_user_func_array(array(\'parent\', \'' . $methodName . '\'), $arguments);' . PHP_EOL .1898 "\t" . '}' . PHP_EOL .1899 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1900 "\t" . '{' . PHP_EOL .1901 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1902 "\t\t" . '{' . PHP_EOL .1903 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1904 "\t\t" . '}' . PHP_EOL .1905 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1906 "\t\t" . '{' . PHP_EOL .1907 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1908 "\t\t" . '}' . PHP_EOL .1909 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .1910 "\t\t" . '{' . PHP_EOL .1911 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .1912 "\t\t" . '}' . PHP_EOL .1913 "\t" . '}' . PHP_EOL .1914 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .1915 "\t" . '{' . PHP_EOL .1916 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .1917 "\t\t" . '{' . PHP_EOL .1918 "\t\t\t" . '$return = $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .1919 "\t\t\t" . 'return $return;' . PHP_EOL .1920 "\t\t" . '}' . PHP_EOL .1921 "\t\t" . 'else' . PHP_EOL .1922 "\t\t" . '{' . PHP_EOL .1923 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .1924 "\t\t" . '}' . PHP_EOL .1925 "\t" . '}' . PHP_EOL .1926 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1927 "\t" . '{' . PHP_EOL .1928 "\t\t" . 'return ' . var_export([$methodName, '__construct', '__call'], true) . ';' . PHP_EOL .1929 "\t" . '}' . PHP_EOL .1930 '}' . PHP_EOL .1931 '}'1932 )1933 ->if($reflectionClassController->implementsInterface = function ($interface) {1934 return ($interface == 'traversable' ? true : false);1935 })1936 ->and($generator->setReflectionClassFactory(function ($class) use ($reflectionClass) {1937 return ($class == 'iteratorAggregate' ? new \reflectionClass('iteratorAggregate') : $reflectionClass);1938 }))1939 ->then1940 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(1941 'namespace mock {' . PHP_EOL .1942 'final class ' . $realClass . ' implements \\iteratorAggregate, \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .1943 '{' . PHP_EOL .1944 $this->getMockControllerMethods() .1945 "\t" . 'public static function ' . $methodName . '()' . PHP_EOL .1946 "\t" . '{' . PHP_EOL .1947 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .1948 "\t\t" . 'return call_user_func_array(array(\'parent\', \'' . $methodName . '\'), $arguments);' . PHP_EOL .1949 "\t" . '}' . PHP_EOL .1950 "\t" . 'public function getIterator()' . PHP_EOL .1951 "\t" . '{' . PHP_EOL .1952 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .1953 "\t\t" . 'if (isset($this->getMockController()->getIterator) === false)' . PHP_EOL .1954 "\t\t" . '{' . PHP_EOL .1955 "\t\t\t" . '$this->getMockController()->getIterator = function() {' . PHP_EOL .1956 "\t\t\t" . '};' . PHP_EOL .1957 "\t\t" . '}' . PHP_EOL .1958 "\t\t" . '$return = $this->getMockController()->invoke(\'getIterator\', $arguments);' . PHP_EOL .1959 "\t\t" . 'return $return;' . PHP_EOL .1960 "\t" . '}' . PHP_EOL .1961 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1962 "\t" . '{' . PHP_EOL .1963 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1964 "\t\t" . '{' . PHP_EOL .1965 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1966 "\t\t" . '}' . PHP_EOL .1967 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1968 "\t\t" . '{' . PHP_EOL .1969 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1970 "\t\t" . '}' . PHP_EOL .1971 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .1972 "\t\t" . '{' . PHP_EOL .1973 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .1974 "\t\t" . '}' . PHP_EOL .1975 "\t" . '}' . PHP_EOL .1976 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .1977 "\t" . '{' . PHP_EOL .1978 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .1979 "\t\t" . '{' . PHP_EOL .1980 "\t\t\t" . '$return = $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .1981 "\t\t\t" . 'return $return;' . PHP_EOL .1982 "\t\t" . '}' . PHP_EOL .1983 "\t\t" . 'else' . PHP_EOL .1984 "\t\t" . '{' . PHP_EOL .1985 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .1986 "\t\t" . '}' . PHP_EOL .1987 "\t" . '}' . PHP_EOL .1988 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1989 "\t" . '{' . PHP_EOL .1990 "\t\t" . 'return ' . var_export([$methodName, 'getiterator', '__construct', '__call'], true) . ';' . PHP_EOL .1991 "\t" . '}' . PHP_EOL .1992 '}' . PHP_EOL .1993 '}'1994 )1995 ;1996 }1997 /** @php >= 7.0 */1998 public function testGetMockedClassCodeForInterfaceWithTypeHint()1999 {2000 $this2001 ->if($generator = new testedClass())2002 ->and($reflectionParameterController = new mock\controller())2003 ->and($reflectionParameterController->__construct = function () {2004 })2005 ->and($reflectionParameterController->isArray = false)2006 ->and($reflectionParameterController->isCallable = false)2007 ->and($reflectionParameterController->getName = 'typeHint')2008 ->and($reflectionParameterController->isPassedByReference = false)2009 ->and($reflectionParameterController->isDefaultValueAvailable = false)2010 ->and($reflectionParameterController->isOptional = false)2011 ->and($reflectionParameterController->isVariadic = false)2012 ->and($reflectionParameterController->getClass = null)2013 ->and($reflectionParameterController->hasType = true)2014 ->and($reflectionParameterController->getType = 'string')2015 ->and($reflectionParameterController->allowsNull = false)2016 ->and($reflectionParameter = new \mock\reflectionParameter(null, null))2017 ->and($reflectionMethodController = new mock\controller())2018 ->and($reflectionMethodController->__construct = function () {2019 })2020 ->and($reflectionMethodController->getName = $methodName = uniqid())2021 ->and($reflectionMethodController->isConstructor = false)2022 ->and($reflectionMethodController->getParameters = [$reflectionParameter])2023 ->and($reflectionMethodController->isPublic = true)2024 ->and($reflectionMethodController->isProtected = false)2025 ->and($reflectionMethodController->isPrivate = false)2026 ->and($reflectionMethodController->isFinal = false)2027 ->and($reflectionMethodController->isStatic = false)2028 ->and($reflectionMethodController->isAbstract = false)2029 ->and($reflectionMethodController->returnsReference = false)2030 ->and($reflectionMethodController->hasReturnType = false)2031 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))2032 ->and($reflectionClassController = new mock\controller())2033 ->and($reflectionClassController->__construct = function () {2034 })2035 ->and($reflectionClassController->getName = function () use (& $realClass) {2036 return $realClass;2037 })2038 ->and($reflectionClassController->isFinal = false)2039 ->and($reflectionClassController->isInterface = false)2040 ->and($reflectionClassController->getMethods = [$reflectionMethod])2041 ->and($reflectionClassController->getConstructor = null)2042 ->and($reflectionClassController->isAbstract = false)2043 ->and($reflectionClass = new \mock\reflectionClass(null))2044 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {2045 return $reflectionClass;2046 }))2047 ->and($adapter = new atoum\test\adapter())2048 ->and($adapter->class_exists = function ($class) use (& $realClass) {2049 return ($class == '\\' . $realClass);2050 })2051 ->and($generator->setAdapter($adapter))2052 ->then2053 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(2054 'namespace mock {' . PHP_EOL .2055 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .2056 '{' . PHP_EOL .2057 $this->getMockControllerMethods() .2058 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .2059 "\t" . '{' . PHP_EOL .2060 "\t\t" . 'if ($mockController === null)' . PHP_EOL .2061 "\t\t" . '{' . PHP_EOL .2062 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .2063 "\t\t" . '}' . PHP_EOL .2064 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .2065 "\t\t" . '{' . PHP_EOL .2066 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .2067 "\t\t" . '}' . PHP_EOL .2068 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .2069 "\t\t" . '{' . PHP_EOL .2070 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .2071 "\t\t" . '}' . PHP_EOL .2072 "\t" . '}' . PHP_EOL .2073 "\t" . 'public function ' . $methodName . '(string $typeHint)' . PHP_EOL .2074 "\t" . '{' . PHP_EOL .2075 "\t\t" . '$arguments = array_merge(array($typeHint), array_slice(func_get_args(), 1));' . PHP_EOL .2076 "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL .2077 "\t\t" . '{' . PHP_EOL .2078 "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL .2079 "\t\t\t" . 'return $return;' . PHP_EOL .2080 "\t\t" . '}' . PHP_EOL .2081 "\t\t" . 'else' . PHP_EOL .2082 "\t\t" . '{' . PHP_EOL .2083 "\t\t\t" . '$this->getMockController()->addCall(\'' . $methodName . '\', $arguments);' . PHP_EOL .2084 "\t\t\t" . '$return = call_user_func_array(\'parent::' . $methodName . '\', $arguments);' . PHP_EOL .2085 "\t\t\t" . 'return $return;' . PHP_EOL .2086 "\t\t" . '}' . PHP_EOL .2087 "\t" . '}' . PHP_EOL .2088 "\t" . 'public static function getMockedMethods()' . PHP_EOL .2089 "\t" . '{' . PHP_EOL .2090 "\t\t" . 'return ' . var_export(['__construct', $methodName], true) . ';' . PHP_EOL .2091 "\t" . '}' . PHP_EOL .2092 '}' . PHP_EOL .2093 '}'2094 )2095 ;2096 }2097 /** @php >= 7.0 */2098 public function testGetMockedClassCodeForInterfaceWithReturnType()2099 {2100 $this2101 ->if($generator = new testedClass())2102 ->and($reflectionTypeController = new mock\controller())2103 ->and($reflectionTypeController->__construct = function () {2104 })2105 ->and($reflectionTypeController->isBuiltin = true)2106 ->and($reflectionTypeController->allowsNull = false)2107 ->and($reflectionTypeController->__toString = $returnType = 'string')2108 ->and($reflectionType = new \mock\reflectionType())2109 ->and($reflectionMethodController = new mock\controller())2110 ->and($reflectionMethodController->__construct = function () {2111 })2112 ->and($reflectionMethodController->getName = $methodName = uniqid())2113 ->and($reflectionMethodController->isConstructor = false)2114 ->and($reflectionMethodController->getParameters = [])2115 ->and($reflectionMethodController->isPublic = true)2116 ->and($reflectionMethodController->isProtected = false)2117 ->and($reflectionMethodController->isPrivate = false)2118 ->and($reflectionMethodController->isFinal = false)2119 ->and($reflectionMethodController->isStatic = false)2120 ->and($reflectionMethodController->isAbstract = false)2121 ->and($reflectionMethodController->returnsReference = false)2122 ->and($reflectionMethodController->hasReturnType = true)2123 ->and($reflectionMethodController->getReturnType = $reflectionType)2124 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))2125 ->and($reflectionClassController = new mock\controller())2126 ->and($reflectionClassController->__construct = function () {2127 })2128 ->and($reflectionClassController->getName = function () use (& $realClass) {2129 return $realClass;2130 })2131 ->and($reflectionClassController->isFinal = false)2132 ->and($reflectionClassController->isInterface = false)2133 ->and($reflectionClassController->getMethods = [$reflectionMethod])2134 ->and($reflectionClassController->getConstructor = null)2135 ->and($reflectionClassController->isAbstract = false)2136 ->and($reflectionClass = new \mock\reflectionClass(null))2137 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {2138 return $reflectionClass;2139 }))2140 ->and($adapter = new atoum\test\adapter())2141 ->and($adapter->class_exists = function ($class) use (& $realClass) {2142 return ($class == '\\' . $realClass);2143 })2144 ->and($generator->setAdapter($adapter))2145 ->then2146 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(2147 'namespace mock {' . PHP_EOL .2148 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .2149 '{' . PHP_EOL .2150 $this->getMockControllerMethods() .2151 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .2152 "\t" . '{' . PHP_EOL .2153 "\t\t" . 'if ($mockController === null)' . PHP_EOL .2154 "\t\t" . '{' . PHP_EOL .2155 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .2156 "\t\t" . '}' . PHP_EOL .2157 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .2158 "\t\t" . '{' . PHP_EOL .2159 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .2160 "\t\t" . '}' . PHP_EOL .2161 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .2162 "\t\t" . '{' . PHP_EOL .2163 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .2164 "\t\t" . '}' . PHP_EOL .2165 "\t" . '}' . PHP_EOL .2166 "\t" . 'public function ' . $methodName . '(): ' . $returnType . PHP_EOL .2167 "\t" . '{' . PHP_EOL .2168 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .2169 "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL .2170 "\t\t" . '{' . PHP_EOL .2171 "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL .2172 "\t\t\t" . 'return $return;' . PHP_EOL .2173 "\t\t" . '}' . PHP_EOL .2174 "\t\t" . 'else' . PHP_EOL .2175 "\t\t" . '{' . PHP_EOL .2176 "\t\t\t" . '$this->getMockController()->addCall(\'' . $methodName . '\', $arguments);' . PHP_EOL .2177 "\t\t\t" . '$return = call_user_func_array(\'parent::' . $methodName . '\', $arguments);' . PHP_EOL .2178 "\t\t\t" . 'return $return;' . PHP_EOL .2179 "\t\t" . '}' . PHP_EOL .2180 "\t" . '}' . PHP_EOL .2181 "\t" . 'public static function getMockedMethods()' . PHP_EOL .2182 "\t" . '{' . PHP_EOL .2183 "\t\t" . 'return ' . var_export(['__construct', $methodName], true) . ';' . PHP_EOL .2184 "\t" . '}' . PHP_EOL .2185 '}' . PHP_EOL .2186 '}'2187 )2188 ;2189 }2190 /** @php >= 7.0 */2191 public function testGetMockedClassCodeForInterfaceWithReturnTypeNotBuiltIn()2192 {2193 $this2194 ->if($generator = new testedClass())2195 ->and($reflectionTypeController = new mock\controller())2196 ->and($reflectionTypeController->__construct = function () {2197 })2198 ->and($reflectionTypeController->isBuiltin = false)2199 ->and($reflectionTypeController->allowsNull = false)2200 ->and($reflectionTypeController->__toString = $returnType = 'Mock\Foo')2201 ->and($reflectionType = new \mock\reflectionType())2202 ->and($reflectionMethodController = new mock\controller())2203 ->and($reflectionMethodController->__construct = function () {2204 })2205 ->and($reflectionMethodController->getName = $methodName = uniqid())2206 ->and($reflectionMethodController->isConstructor = false)2207 ->and($reflectionMethodController->getParameters = [])2208 ->and($reflectionMethodController->isPublic = true)2209 ->and($reflectionMethodController->isProtected = false)2210 ->and($reflectionMethodController->isPrivate = false)2211 ->and($reflectionMethodController->isFinal = false)2212 ->and($reflectionMethodController->isStatic = false)2213 ->and($reflectionMethodController->isAbstract = false)2214 ->and($reflectionMethodController->returnsReference = false)2215 ->and($reflectionMethodController->hasReturnType = true)2216 ->and($reflectionMethodController->getReturnType = $reflectionType)2217 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))2218 ->and($reflectionClassController = new mock\controller())2219 ->and($reflectionClassController->__construct = function () {2220 })2221 ->and($reflectionClassController->getName = function () use (& $realClass) {2222 return $realClass;2223 })2224 ->and($reflectionClassController->isFinal = false)2225 ->and($reflectionClassController->isInterface = false)2226 ->and($reflectionClassController->getMethods = [$reflectionMethod])2227 ->and($reflectionClassController->getConstructor = null)2228 ->and($reflectionClassController->isAbstract = false)2229 ->and($reflectionClass = new \mock\reflectionClass(null))2230 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {2231 return $reflectionClass;2232 }))2233 ->and($adapter = new atoum\test\adapter())2234 ->and($adapter->class_exists = function ($class) use (& $realClass) {2235 return ($class == '\\' . $realClass);2236 })2237 ->and($generator->setAdapter($adapter))2238 ->then2239 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(2240 'namespace mock {' . PHP_EOL .2241 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .2242 '{' . PHP_EOL .2243 $this->getMockControllerMethods() .2244 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .2245 "\t" . '{' . PHP_EOL .2246 "\t\t" . 'if ($mockController === null)' . PHP_EOL .2247 "\t\t" . '{' . PHP_EOL .2248 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .2249 "\t\t" . '}' . PHP_EOL .2250 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .2251 "\t\t" . '{' . PHP_EOL .2252 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .2253 "\t\t" . '}' . PHP_EOL .2254 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .2255 "\t\t" . '{' . PHP_EOL .2256 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .2257 "\t\t" . '}' . PHP_EOL .2258 "\t" . '}' . PHP_EOL .2259 "\t" . 'public function ' . $methodName . '(): \\' . $returnType . PHP_EOL .2260 "\t" . '{' . PHP_EOL .2261 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .2262 "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL .2263 "\t\t" . '{' . PHP_EOL .2264 "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL .2265 "\t\t\t" . 'return $return;' . PHP_EOL .2266 "\t\t" . '}' . PHP_EOL .2267 "\t\t" . 'else' . PHP_EOL .2268 "\t\t" . '{' . PHP_EOL .2269 "\t\t\t" . '$this->getMockController()->addCall(\'' . $methodName . '\', $arguments);' . PHP_EOL .2270 "\t\t\t" . '$return = call_user_func_array(\'parent::' . $methodName . '\', $arguments);' . PHP_EOL .2271 "\t\t\t" . 'return $return;' . PHP_EOL .2272 "\t\t" . '}' . PHP_EOL .2273 "\t" . '}' . PHP_EOL .2274 "\t" . 'public static function getMockedMethods()' . PHP_EOL .2275 "\t" . '{' . PHP_EOL .2276 "\t\t" . 'return ' . var_export(['__construct', $methodName], true) . ';' . PHP_EOL .2277 "\t" . '}' . PHP_EOL .2278 '}' . PHP_EOL .2279 '}'2280 )2281 ;2282 }2283 /** @php < 7.0 */2284 public function testGetMockedClassCodeForRealClassWithoutConstructor()2285 {2286 $this2287 ->if($generator = new testedClass())2288 ->and($reflectionMethodController = new mock\controller())2289 ->and($reflectionMethodController->__construct = function () {2290 })2291 ->and($reflectionMethodController->getName = $methodName = uniqid())2292 ->and($reflectionMethodController->isConstructor = false)2293 ->and($reflectionMethodController->getParameters = [])2294 ->and($reflectionMethodController->isPublic = true)2295 ->and($reflectionMethodController->isProtected = false)2296 ->and($reflectionMethodController->isPrivate = false)2297 ->and($reflectionMethodController->isFinal = false)2298 ->and($reflectionMethodController->isAbstract = false)2299 ->and($reflectionMethodController->isStatic = false)2300 ->and($reflectionMethodController->returnsReference = false)2301 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))2302 ->and($reflectionClassController = new mock\controller())2303 ->and($reflectionClassController->__construct = function () {2304 })2305 ->and($reflectionClassController->getName = function () use (& $realClass) {2306 return $realClass;2307 })2308 ->and($reflectionClassController->isFinal = false)2309 ->and($reflectionClassController->isInterface = false)2310 ->and($reflectionClassController->getMethods = [$reflectionMethod])2311 ->and($reflectionClassController->getConstructor = null)2312 ->and($reflectionClassController->isAbstract = false)2313 ->and($reflectionClass = new \mock\reflectionClass(null))2314 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {2315 return $reflectionClass;2316 }))2317 ->and($adapter = new atoum\test\adapter())2318 ->and($adapter->class_exists = function ($class) use (& $realClass) {2319 return ($class == '\\' . $realClass);2320 })2321 ->and($generator->setAdapter($adapter))2322 ->then2323 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(2324 'namespace mock {' . PHP_EOL .2325 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .2326 '{' . PHP_EOL .2327 $this->getMockControllerMethods() .2328 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .2329 "\t" . '{' . PHP_EOL .2330 "\t\t" . 'if ($mockController === null)' . PHP_EOL .2331 "\t\t" . '{' . PHP_EOL .2332 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .2333 "\t\t" . '}' . PHP_EOL .2334 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .2335 "\t\t" . '{' . PHP_EOL .2336 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .2337 "\t\t" . '}' . PHP_EOL .2338 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .2339 "\t\t" . '{' . PHP_EOL .2340 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .2341 "\t\t" . '}' . PHP_EOL .2342 "\t" . '}' . PHP_EOL .2343 "\t" . 'public function ' . $methodName . '()' . PHP_EOL .2344 "\t" . '{' . PHP_EOL .2345 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .2346 "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL .2347 "\t\t" . '{' . PHP_EOL .2348 "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL .2349 "\t\t\t" . 'return $return;' . PHP_EOL .2350 "\t\t" . '}' . PHP_EOL .2351 "\t\t" . 'else' . PHP_EOL .2352 "\t\t" . '{' . PHP_EOL .2353 "\t\t\t" . '$this->getMockController()->addCall(\'' . $methodName . '\', $arguments);' . PHP_EOL .2354 "\t\t\t" . '$return = call_user_func_array(\'parent::' . $methodName . '\', $arguments);' . PHP_EOL .2355 "\t\t\t" . 'return $return;' . PHP_EOL .2356 "\t\t" . '}' . PHP_EOL .2357 "\t" . '}' . PHP_EOL .2358 "\t" . 'public static function getMockedMethods()' . PHP_EOL .2359 "\t" . '{' . PHP_EOL .2360 "\t\t" . 'return ' . var_export(['__construct', $methodName], true) . ';' . PHP_EOL .2361 "\t" . '}' . PHP_EOL .2362 '}' . PHP_EOL .2363 '}'2364 )2365 ;2366 }2367 /** @php >= 7.0 */2368 public function testGetMockedClassCodeForRealClassWithoutConstructorPhp7()2369 {2370 $this2371 ->if($generator = new testedClass())2372 ->and($reflectionMethodController = new mock\controller())2373 ->and($reflectionMethodController->__construct = function () {2374 })2375 ->and($reflectionMethodController->getName = $methodName = uniqid())2376 ->and($reflectionMethodController->isConstructor = false)2377 ->and($reflectionMethodController->getParameters = [])2378 ->and($reflectionMethodController->isPublic = true)2379 ->and($reflectionMethodController->isProtected = false)2380 ->and($reflectionMethodController->isPrivate = false)2381 ->and($reflectionMethodController->isFinal = false)2382 ->and($reflectionMethodController->isAbstract = false)2383 ->and($reflectionMethodController->isStatic = false)2384 ->and($reflectionMethodController->returnsReference = false)2385 ->and($reflectionMethodController->hasReturnType = false)2386 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))2387 ->and($reflectionClassController = new mock\controller())2388 ->and($reflectionClassController->__construct = function () {2389 })2390 ->and($reflectionClassController->getName = function () use (& $realClass) {2391 return $realClass;2392 })2393 ->and($reflectionClassController->isFinal = false)2394 ->and($reflectionClassController->isInterface = false)2395 ->and($reflectionClassController->getMethods = [$reflectionMethod])2396 ->and($reflectionClassController->getConstructor = null)2397 ->and($reflectionClassController->isAbstract = false)2398 ->and($reflectionClass = new \mock\reflectionClass(null))2399 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {2400 return $reflectionClass;2401 }))2402 ->and($adapter = new atoum\test\adapter())2403 ->and($adapter->class_exists = function ($class) use (& $realClass) {2404 return ($class == '\\' . $realClass);2405 })2406 ->and($generator->setAdapter($adapter))2407 ->then2408 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(2409 'namespace mock {' . PHP_EOL .2410 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .2411 '{' . PHP_EOL .2412 $this->getMockControllerMethods() .2413 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .2414 "\t" . '{' . PHP_EOL .2415 "\t\t" . 'if ($mockController === null)' . PHP_EOL .2416 "\t\t" . '{' . PHP_EOL .2417 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .2418 "\t\t" . '}' . PHP_EOL .2419 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .2420 "\t\t" . '{' . PHP_EOL .2421 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .2422 "\t\t" . '}' . PHP_EOL .2423 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .2424 "\t\t" . '{' . PHP_EOL .2425 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .2426 "\t\t" . '}' . PHP_EOL .2427 "\t" . '}' . PHP_EOL .2428 "\t" . 'public function ' . $methodName . '()' . PHP_EOL .2429 "\t" . '{' . PHP_EOL .2430 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .2431 "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL .2432 "\t\t" . '{' . PHP_EOL .2433 "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL .2434 "\t\t\t" . 'return $return;' . PHP_EOL .2435 "\t\t" . '}' . PHP_EOL .2436 "\t\t" . 'else' . PHP_EOL .2437 "\t\t" . '{' . PHP_EOL .2438 "\t\t\t" . '$this->getMockController()->addCall(\'' . $methodName . '\', $arguments);' . PHP_EOL .2439 "\t\t\t" . '$return = call_user_func_array(\'parent::' . $methodName . '\', $arguments);' . PHP_EOL .2440 "\t\t\t" . 'return $return;' . PHP_EOL .2441 "\t\t" . '}' . PHP_EOL .2442 "\t" . '}' . PHP_EOL .2443 "\t" . 'public static function getMockedMethods()' . PHP_EOL .2444 "\t" . '{' . PHP_EOL .2445 "\t\t" . 'return ' . var_export(['__construct', $methodName], true) . ';' . PHP_EOL .2446 "\t" . '}' . PHP_EOL .2447 '}' . PHP_EOL .2448 '}'2449 )2450 ;2451 }2452 public function testGetMockedClassCodeForAbstractClassWithConstructorInInterface()2453 {2454 $this2455 ->if($generator = new testedClass())2456 ->and($publicMethodController = new mock\controller())2457 ->and($publicMethodController->__construct = function () {2458 })2459 ->and($publicMethodController->getName = '__construct')2460 ->and($publicMethodController->isConstructor = true)2461 ->and($publicMethodController->getParameters = [])2462 ->and($publicMethodController->isPublic = true)2463 ->and($publicMethodController->isProtected = false)2464 ->and($publicMethodController->isPrivate = false)2465 ->and($publicMethodController->isFinal = false)2466 ->and($publicMethodController->isStatic = false)2467 ->and($publicMethodController->isAbstract = true)2468 ->and($publicMethodController->returnsReference = false)2469 ->and($publicMethod = new \mock\reflectionMethod(null, null))2470 ->and($classController = new mock\controller())2471 ->and($classController->__construct = function () {2472 })2473 ->and($classController->getName = $className = uniqid())2474 ->and($classController->isFinal = false)2475 ->and($classController->isInterface = false)2476 ->and($classController->isAbstract = true)2477 ->and($classController->getMethods = [$publicMethod])2478 ->and($classController->getConstructor = $publicMethod)2479 ->and($class = new \mock\reflectionClass(null))2480 ->and($generator->setReflectionClassFactory(function () use ($class) {2481 return $class;2482 }))2483 ->and($adapter = new atoum\test\adapter())2484 ->and($adapter->class_exists = function ($class) use ($className) {2485 return ($class == '\\' . $className);2486 })2487 ->and($generator->setAdapter($adapter))2488 ->then2489 ->string($generator->getMockedClassCode($className))->isEqualTo(2490 'namespace mock {' . PHP_EOL .2491 'final class ' . $className . ' extends \\' . $className . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .2492 '{' . PHP_EOL .2493 $this->getMockControllerMethods() .2494 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .2495 "\t" . '{' . PHP_EOL .2496 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .2497 "\t\t" . 'if ($mockController === null)' . PHP_EOL .2498 "\t\t" . '{' . PHP_EOL .2499 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .2500 "\t\t" . '}' . PHP_EOL .2501 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .2502 "\t\t" . '{' . PHP_EOL .2503 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .2504 "\t\t" . '}' . PHP_EOL .2505 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .2506 "\t\t" . '{' . PHP_EOL .2507 "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .2508 "\t\t" . '}' . PHP_EOL .2509 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .2510 "\t" . '}' . PHP_EOL .2511 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .2512 "\t" . '{' . PHP_EOL .2513 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .2514 "\t\t" . '{' . PHP_EOL .2515 "\t\t\t" . '$return = $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .2516 "\t\t\t" . 'return $return;' . PHP_EOL .2517 "\t\t" . '}' . PHP_EOL .2518 "\t\t" . 'else' . PHP_EOL .2519 "\t\t" . '{' . PHP_EOL .2520 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .2521 "\t\t" . '}' . PHP_EOL .2522 "\t" . '}' . PHP_EOL .2523 "\t" . 'public static function getMockedMethods()' . PHP_EOL .2524 "\t" . '{' . PHP_EOL .2525 "\t\t" . 'return ' . var_export(['__construct', '__call'], true) . ';' . PHP_EOL .2526 "\t" . '}' . PHP_EOL .2527 '}' . PHP_EOL .2528 '}'2529 )2530 ;2531 }2532 public function testGenerate()2533 {2534 $this2535 ->if($generator = new testedClass())2536 ->then2537 ->exception(function () use ($generator) {2538 $generator->generate('');2539 })2540 ->isInstanceOf(atoum\exceptions\runtime::class)2541 ->hasMessage('Class name \'\' is invalid')2542 ->exception(function () use ($generator) {2543 $generator->generate('\\');2544 })2545 ->isInstanceOf(atoum\exceptions\runtime::class)2546 ->hasMessage('Class name \'\\\' is invalid')2547 ->exception(function () use ($generator, & $class) {2548 $generator->generate($class = ('\\' . uniqid() . '\\'));2549 })2550 ->isInstanceOf(atoum\exceptions\runtime::class)2551 ->hasMessage('Class name \'' . $class . '\' is invalid')2552 ->if($adapter = new atoum\test\adapter())2553 ->and($adapter->class_exists = false)2554 ->and($adapter->interface_exists = false)2555 ->and($generator->setAdapter($adapter))2556 ->and($class = uniqid('unknownClass'))2557 ->then2558 ->object($generator->generate($class))->isIdenticalTo($generator)2559 ->class('\mock\\' . $class)2560 ->hasNoParent()2561 ->hasInterface(atoum\mock\aggregator::class)2562 ->if($class = '\\' . uniqid('unknownClass'))2563 ->then2564 ->object($generator->generate($class))->isIdenticalTo($generator)2565 ->class('\mock' . $class)2566 ->hasNoParent()2567 ->hasInterface(atoum\mock\aggregator::class)2568 ->if($adapter->class_exists = true)2569 ->and($class = uniqid())2570 ->then2571 ->exception(function () use ($generator, $class) {2572 $generator->generate($class);2573 })2574 ->isInstanceOf(atoum\exceptions\logic::class)2575 ->hasMessage('Class \'\mock\\' . $class . '\' already exists')2576 ->if($class = '\\' . uniqid())2577 ->then2578 ->exception(function () use ($generator, $class) {2579 $generator->generate($class);2580 })2581 ->isInstanceOf(atoum\exceptions\logic::class)2582 ->hasMessage('Class \'\mock' . $class . '\' already exists')2583 ->if($class = uniqid())2584 ->and($adapter->class_exists = function ($arg) use ($class) {2585 return $arg === '\\' . $class;2586 })2587 ->and($reflectionClassController = new mock\controller())2588 ->and($reflectionClassController->__construct = function () {2589 })2590 ->and($reflectionClassController->isFinal = true)2591 ->and($reflectionClassController->isInterface = false)2592 ->and($reflectionClass = new \mock\reflectionClass(uniqid(), $reflectionClassController))2593 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {2594 return $reflectionClass;2595 }))2596 ->then2597 ->exception(function () use ($generator, $class) {2598 $generator->generate($class);2599 })2600 ->isInstanceOf(atoum\exceptions\logic::class)2601 ->hasMessage('Class \'\\' . $class . '\' is final, unable to mock it')2602 ->if($class = '\\' . uniqid())2603 ->and($adapter->class_exists = function ($arg) use ($class) {2604 return $arg === $class;2605 })2606 ->then2607 ->exception(function () use ($generator, $class) {2608 $generator->generate($class);2609 })2610 ->isInstanceOf(atoum\exceptions\logic::class)2611 ->hasMessage('Class \'' . $class . '\' is final, unable to mock it')2612 ->if($reflectionClassController->isFinal = false)2613 ->and($generator = new testedClass())2614 ->then2615 ->object($generator->generate(__CLASS__))->isIdenticalTo($generator)2616 ->class('\mock\\' . __CLASS__)2617 ->hasParent(__CLASS__)2618 ->hasInterface(atoum\mock\aggregator::class)2619 ->if($generator = new testedClass())2620 ->and($generator->shunt('__construct'))2621 ->then2622 ->boolean($generator->isShunted('__construct'))->isTrue()2623 ->object($generator->generate('reflectionMethod'))->isIdenticalTo($generator)2624 ->boolean($generator->isShunted('__construct'))->isFalse()2625 ->if($generator = new testedClass())2626 ->and($generator->shuntParentClassCalls())2627 ->then2628 ->object($generator->generate('reflectionParameter'))->isIdenticalTo($generator)2629 ->boolean($generator->callsToParentClassAreShunted())->isFalse()2630 ;2631 }2632 public function testMethodIsMockable()2633 {2634 $this2635 ->if($generator = new testedClass())2636 ->and($this->mockGenerator->orphanize('__construct'))2637 ->and($method = new \mock\reflectionMethod($this, $methodName = uniqid()))2638 ->and($this->calling($method)->getName = $methodName)2639 ->and($this->calling($method)->isFinal = false)2640 ->and($this->calling($method)->isStatic = false)2641 ->and($this->calling($method)->isAbstract = false)2642 ->and($this->calling($method)->isPrivate = false)2643 ->and($this->calling($method)->isProtected = false)2644 ->then2645 ->boolean($generator->methodIsMockable($method))->isTrue()2646 ->if($this->calling($method)->isFinal = true)2647 ->then2648 ->boolean($generator->methodIsMockable($method))->isFalse()2649 ->if($this->calling($method)->isFinal = false)2650 ->and($this->calling($method)->isStatic = true)2651 ->then2652 ->boolean($generator->methodIsMockable($method))->isFalse()2653 ->if($this->calling($method)->isStatic = false)2654 ->and($this->calling($method)->isPrivate = true)2655 ->then2656 ->boolean($generator->methodIsMockable($method))->isFalse()2657 ->if($this->calling($method)->isPrivate = false)2658 ->and($this->calling($method)->isProtected = true)2659 ->then2660 ->boolean($generator->methodIsMockable($method))->isFalse()2661 ->if($generator->overload(new mock\php\method($methodName)))2662 ->then2663 ->boolean($generator->methodIsMockable($method))->isTrue()2664 ;2665 }2666 /** @php < 7.0 */2667 public function testMethodIsMockableWithReservedWord($reservedWord)2668 {2669 $this2670 ->if($generator = new testedClass())2671 ->and($this->mockGenerator->orphanize('__construct'))2672 ->and($method = new \mock\reflectionMethod($this, $reservedWord))2673 ->and($this->calling($method)->getName = $reservedWord)2674 ->and($this->calling($method)->isFinal = false)2675 ->and($this->calling($method)->isStatic = false)2676 ->and($this->calling($method)->isAbstract = false)2677 ->and($this->calling($method)->isPrivate = false)2678 ->and($this->calling($method)->isProtected = false)2679 ->then2680 ->boolean($generator->methodIsMockable($method))->isFalse()2681 ;2682 }2683 /** @php >= 7.0 */2684 public function testMethodIsMockableWithReservedWordPhp7($reservedWord)2685 {2686 $this2687 ->if($generator = new testedClass())2688 ->and($this->mockGenerator->orphanize('__construct'))2689 ->and($method = new \mock\reflectionMethod($this, $reservedWord))2690 ->and($this->calling($method)->getName = $reservedWord)2691 ->and($this->calling($method)->isFinal = false)2692 ->and($this->calling($method)->isStatic = false)2693 ->and($this->calling($method)->isAbstract = false)2694 ->and($this->calling($method)->isPrivate = false)2695 ->and($this->calling($method)->isProtected = false)2696 ->then2697 ->boolean($generator->methodIsMockable($method))->isFalse()2698 ;2699 }2700 /**2701 * @php < 7.02702 */2703 public function testGetMockedClassCodeWithOrphanizedMethod()2704 {2705 $this2706 ->if->mockGenerator->orphanize('__construct')2707 ->and($a = new \mock\reflectionParameter())2708 ->and($this->calling($a)->getName = 'a')2709 ->and($this->calling($a)->isArray = false)2710 ->and($this->calling($a)->isCallable = false)2711 ->and($this->calling($a)->getClass = null)2712 ->and($this->calling($a)->isPassedByReference = false)2713 ->and($this->calling($a)->isDefaultValueAvailable = false)2714 ->and($this->calling($a)->isOptional = false)2715 ->and($this->calling($a)->isVariadic = false)2716 ->and($this->calling($a)->allowsNull = true)2717 ->and($b = new \mock\reflectionParameter())2718 ->and($this->calling($b)->getName = 'b')2719 ->and($this->calling($b)->isArray = false)2720 ->and($this->calling($b)->isCallable = false)2721 ->and($this->calling($b)->getClass = null)2722 ->and($this->calling($b)->isPassedByReference = false)2723 ->and($this->calling($b)->isDefaultValueAvailable = false)2724 ->and($this->calling($b)->isOptional = false)2725 ->and($this->calling($b)->isVariadic = false)2726 ->and($this->calling($b)->allowsNull = true)2727 ->and($c = new \mock\reflectionParameter())2728 ->and($this->calling($c)->getName = 'c')2729 ->and($this->calling($c)->isArray = false)2730 ->and($this->calling($c)->isCallable = false)2731 ->and($this->calling($c)->getClass = null)2732 ->and($this->calling($c)->isPassedByReference = false)2733 ->and($this->calling($c)->isDefaultValueAvailable = false)2734 ->and($this->calling($c)->isOptional = false)2735 ->and($this->calling($c)->isVariadic = false)2736 ->and($this->calling($c)->allowsNull = true)2737 ->and->mockGenerator->orphanize('__construct')2738 ->and($constructor = new \mock\reflectionMethod())2739 ->and($this->calling($constructor)->getName = '__construct')2740 ->and($this->calling($constructor)->isConstructor = true)2741 ->and($this->calling($constructor)->getParameters = [$a, $b, $c])2742 ->and($this->calling($constructor)->isPublic = true)2743 ->and($this->calling($constructor)->isProtected = false)2744 ->and($this->calling($constructor)->isPrivate = false)2745 ->and($this->calling($constructor)->isFinal = false)2746 ->and($this->calling($constructor)->isStatic = false)2747 ->and($this->calling($constructor)->isAbstract = false)2748 ->and($this->calling($constructor)->returnsReference = false)2749 ->and->mockGenerator->orphanize('__construct')2750 ->and($class = new \mock\reflectionClass())2751 ->and($this->calling($class)->getName = $className = uniqid())2752 ->and($this->calling($class)->isFinal = false)2753 ->and($this->calling($class)->isInterface = false)2754 ->and($this->calling($class)->isAbstract = false)2755 ->and($this->calling($class)->getMethods = [$constructor])2756 ->and($this->calling($class)->getConstructor = $constructor)2757 ->and($adapter = new atoum\test\adapter())2758 ->and($adapter->class_exists = function ($class) use ($className) {2759 return ($class == '\\' . $className);2760 })2761 ->and($generator = new testedClass())2762 ->and($generator->setReflectionClassFactory(function () use ($class) {2763 return $class;2764 }))2765 ->and($generator->setAdapter($adapter))2766 ->and($generator->orphanize('__construct'))2767 ->then2768 ->string($generator->getMockedClassCode($className))->isEqualTo(2769 'namespace mock {' . PHP_EOL .2770 'final class ' . $className . ' extends \\' . $className . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .2771 '{' . PHP_EOL .2772 $this->getMockControllerMethods() .2773 "\t" . 'public function __construct($a = null, $b = null, $c = null, \mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .2774 "\t" . '{' . PHP_EOL .2775 "\t\t" . '$arguments = array_merge(array($a, $b, $c), array_slice(func_get_args(), 3, -1));' . PHP_EOL .2776 "\t\t" . 'if ($mockController === null)' . PHP_EOL .2777 "\t\t" . '{' . PHP_EOL .2778 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .2779 "\t\t" . '}' . PHP_EOL .2780 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .2781 "\t\t" . '{' . PHP_EOL .2782 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .2783 "\t\t" . '}' . PHP_EOL .2784 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .2785 "\t\t" . '{' . PHP_EOL .2786 "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .2787 "\t\t" . '}' . PHP_EOL .2788 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .2789 "\t" . '}' . PHP_EOL .2790 "\t" . 'public static function getMockedMethods()' . PHP_EOL .2791 "\t" . '{' . PHP_EOL .2792 "\t\t" . 'return ' . var_export(['__construct'], true) . ';' . PHP_EOL .2793 "\t" . '}' . PHP_EOL .2794 '}' . PHP_EOL .2795 '}'2796 )2797 ;2798 }2799 /**2800 * @php >= 7.02801 */2802 public function testGetMockedClassCodeWithOrphanizedMethodPhp7()2803 {2804 $this2805 ->if->mockGenerator->orphanize('__construct')2806 ->and($a = new \mock\reflectionParameter())2807 ->and($this->calling($a)->getName = 'a')2808 ->and($this->calling($a)->isArray = false)2809 ->and($this->calling($a)->isCallable = false)2810 ->and($this->calling($a)->getClass = null)2811 ->and($this->calling($a)->isPassedByReference = false)2812 ->and($this->calling($a)->isDefaultValueAvailable = false)2813 ->and($this->calling($a)->isOptional = false)2814 ->and($this->calling($a)->isVariadic = false)2815 ->and($this->calling($a)->hasType = false)2816 ->and($this->calling($a)->allowsNull = true)2817 ->and($b = new \mock\reflectionParameter())2818 ->and($this->calling($b)->getName = 'b')2819 ->and($this->calling($b)->isArray = false)2820 ->and($this->calling($b)->isCallable = false)2821 ->and($this->calling($b)->getClass = null)2822 ->and($this->calling($b)->isPassedByReference = false)2823 ->and($this->calling($b)->isDefaultValueAvailable = false)2824 ->and($this->calling($b)->isOptional = false)2825 ->and($this->calling($b)->isVariadic = false)2826 ->and($this->calling($b)->hasType = false)2827 ->and($this->calling($b)->allowsNull = true)2828 ->and($c = new \mock\reflectionParameter())2829 ->and($this->calling($c)->getName = 'c')2830 ->and($this->calling($c)->isArray = false)2831 ->and($this->calling($c)->isCallable = false)2832 ->and($this->calling($c)->getClass = null)2833 ->and($this->calling($c)->isPassedByReference = false)2834 ->and($this->calling($c)->isDefaultValueAvailable = false)2835 ->and($this->calling($c)->isOptional = false)2836 ->and($this->calling($c)->isVariadic = false)2837 ->and($this->calling($c)->hasType = false)2838 ->and($this->calling($c)->allowsNull = true)2839 ->and->mockGenerator->orphanize('__construct')2840 ->and($constructor = new \mock\reflectionMethod())2841 ->and($this->calling($constructor)->getName = '__construct')2842 ->and($this->calling($constructor)->isConstructor = true)2843 ->and($this->calling($constructor)->getParameters = [$a, $b, $c])2844 ->and($this->calling($constructor)->isPublic = true)2845 ->and($this->calling($constructor)->isProtected = false)2846 ->and($this->calling($constructor)->isPrivate = false)2847 ->and($this->calling($constructor)->isFinal = false)2848 ->and($this->calling($constructor)->isStatic = false)2849 ->and($this->calling($constructor)->isAbstract = false)2850 ->and($this->calling($constructor)->returnsReference = false)2851 ->and->mockGenerator->orphanize('__construct')2852 ->and($class = new \mock\reflectionClass())2853 ->and($this->calling($class)->getName = $className = uniqid())2854 ->and($this->calling($class)->isFinal = false)2855 ->and($this->calling($class)->isInterface = false)2856 ->and($this->calling($class)->isAbstract = false)2857 ->and($this->calling($class)->getMethods = [$constructor])2858 ->and($this->calling($class)->getConstructor = $constructor)2859 ->and($adapter = new atoum\test\adapter())2860 ->and($adapter->class_exists = function ($class) use ($className) {2861 return ($class == '\\' . $className);2862 })2863 ->and($generator = new testedClass())2864 ->and($generator->setReflectionClassFactory(function () use ($class) {2865 return $class;2866 }))2867 ->and($generator->setAdapter($adapter))2868 ->and($generator->orphanize('__construct'))2869 ->then2870 ->string($generator->getMockedClassCode($className))->isEqualTo(2871 'namespace mock {' . PHP_EOL .2872 'final class ' . $className . ' extends \\' . $className . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .2873 '{' . PHP_EOL .2874 $this->getMockControllerMethods() .2875 "\t" . 'public function __construct($a = null, $b = null, $c = null, \mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .2876 "\t" . '{' . PHP_EOL .2877 "\t\t" . '$arguments = array_merge(array($a, $b, $c), array_slice(func_get_args(), 3, -1));' . PHP_EOL .2878 "\t\t" . 'if ($mockController === null)' . PHP_EOL .2879 "\t\t" . '{' . PHP_EOL .2880 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .2881 "\t\t" . '}' . PHP_EOL .2882 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .2883 "\t\t" . '{' . PHP_EOL .2884 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .2885 "\t\t" . '}' . PHP_EOL .2886 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .2887 "\t\t" . '{' . PHP_EOL .2888 "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .2889 "\t\t" . '}' . PHP_EOL .2890 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .2891 "\t" . '}' . PHP_EOL .2892 "\t" . 'public static function getMockedMethods()' . PHP_EOL .2893 "\t" . '{' . PHP_EOL .2894 "\t\t" . 'return ' . var_export(['__construct'], true) . ';' . PHP_EOL .2895 "\t" . '}' . PHP_EOL .2896 '}' . PHP_EOL .2897 '}'2898 )2899 ;2900 }2901 /**2902 * @php < 7.02903 */2904 public function testGetMockedClassCodeWithProtectedAbstractMethod()2905 {2906 $this2907 ->if($generator = new testedClass())2908 ->and($parameterController1 = new mock\controller())2909 ->and($parameterController1->__construct = function () {2910 })2911 ->and($parameterController1->isArray = false)2912 ->and($parameterController1->isCallable = false)2913 ->and($parameterController1->getClass = null)2914 ->and($parameterController1->getName = 'arg1')2915 ->and($parameterController1->isPassedByReference = false)2916 ->and($parameterController1->isDefaultValueAvailable = false)2917 ->and($parameterController1->isOptional = false)2918 ->and($parameterController1->isVariadic = false)2919 ->and($parameterController1->allowsNull = false)2920 ->and($parameter1 = new \mock\reflectionParameter(null, null))2921 ->and($parameterController2 = new mock\controller())2922 ->and($parameterController2->__construct = function () {2923 })2924 ->and($parameterController2->isArray = true)2925 ->and($parameterController2->isCallable = false)2926 ->and($parameterController2->getClass = null)2927 ->and($parameterController2->getName = 'arg2')2928 ->and($parameterController2->isPassedByReference = true)2929 ->and($parameterController2->isDefaultValueAvailable = false)2930 ->and($parameterController2->isOptional = false)2931 ->and($parameterController2->isVariadic = false)2932 ->and($parameterController2->allowsNull = false)2933 ->and($parameter2 = new \mock\reflectionParameter(null, null))2934 ->and($publicMethodController = new mock\controller())2935 ->and($publicMethodController->__construct = function () {2936 })2937 ->and($publicMethodController->getName = $publicMethodName = uniqid())2938 ->and($publicMethodController->isConstructor = false)2939 ->and($publicMethodController->getParameters = [$parameter1, $parameter2])2940 ->and($publicMethodController->isPublic = true)2941 ->and($publicMethodController->isProtected = false)2942 ->and($publicMethodController->isPrivate = false)2943 ->and($publicMethodController->isFinal = false)2944 ->and($publicMethodController->isStatic = false)2945 ->and($publicMethodController->isAbstract = true)2946 ->and($publicMethodController->returnsReference = false)2947 ->and($publicMethod = new \mock\reflectionMethod(null, null))2948 ->and($protectedMethodController = new mock\controller())2949 ->and($protectedMethodController->__construct = function () {2950 })2951 ->and($protectedMethodController->getName = $protectedMethodName = uniqid())2952 ->and($protectedMethodController->isConstructor = false)2953 ->and($protectedMethodController->getParameters = [])2954 ->and($protectedMethodController->isPublic = false)2955 ->and($protectedMethodController->isProtected = true)2956 ->and($protectedMethodController->isPrivate = false)2957 ->and($protectedMethodController->isFinal = false)2958 ->and($protectedMethodController->isStatic = false)2959 ->and($protectedMethodController->isAbstract = true)2960 ->and($protectedMethodController->returnsReference = false)2961 ->and($protectedMethod = new \mock\reflectionMethod(null, null))2962 ->and($classController = new mock\controller())2963 ->and($classController->__construct = function () {2964 })2965 ->and($classController->getName = $className = uniqid())2966 ->and($classController->isFinal = false)2967 ->and($classController->isInterface = false)2968 ->and($classController->getMethods = [$publicMethod, $protectedMethod])2969 ->and($classController->getConstructor = null)2970 ->and($classController->isAbstract = false)2971 ->and($class = new \mock\reflectionClass(null))2972 ->and($generator->setReflectionClassFactory(function () use ($class) {2973 return $class;2974 }))2975 ->and($adapter = new atoum\test\adapter())2976 ->and($adapter->class_exists = function ($class) use ($className) {2977 return ($class == '\\' . $className);2978 })2979 ->and($generator->setAdapter($adapter))2980 ->then2981 ->string($generator->getMockedClassCode($className))->isEqualTo(2982 'namespace mock {' . PHP_EOL .2983 'final class ' . $className . ' extends \\' . $className . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .2984 '{' . PHP_EOL .2985 $this->getMockControllerMethods() .2986 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .2987 "\t" . '{' . PHP_EOL .2988 "\t\t" . 'if ($mockController === null)' . PHP_EOL .2989 "\t\t" . '{' . PHP_EOL .2990 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .2991 "\t\t" . '}' . PHP_EOL .2992 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .2993 "\t\t" . '{' . PHP_EOL .2994 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .2995 "\t\t" . '}' . PHP_EOL .2996 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .2997 "\t\t" . '{' . PHP_EOL .2998 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .2999 "\t\t" . '}' . PHP_EOL .3000 "\t" . '}' . PHP_EOL .3001 "\t" . 'public function ' . $publicMethodName . '($arg1, array & $arg2)' . PHP_EOL .3002 "\t" . '{' . PHP_EOL .3003 "\t\t" . '$arguments = array_merge(array($arg1, & $arg2), array_slice(func_get_args(), 2));' . PHP_EOL .3004 "\t\t" . 'if (isset($this->getMockController()->' . $publicMethodName . ') === false)' . PHP_EOL .3005 "\t\t" . '{' . PHP_EOL .3006 "\t\t\t" . '$this->getMockController()->' . $publicMethodName . ' = function() {' . PHP_EOL .3007 "\t\t\t" . '};' . PHP_EOL .3008 "\t\t" . '}' . PHP_EOL .3009 "\t\t" . '$return = $this->getMockController()->invoke(\'' . $publicMethodName . '\', $arguments);' . PHP_EOL .3010 "\t\t" . 'return $return;' . PHP_EOL .3011 "\t" . '}' . PHP_EOL .3012 "\t" . 'protected function ' . $protectedMethodName . '()' . PHP_EOL .3013 "\t" . '{' . PHP_EOL .3014 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .3015 "\t\t" . 'if (isset($this->getMockController()->' . $protectedMethodName . ') === false)' . PHP_EOL .3016 "\t\t" . '{' . PHP_EOL .3017 "\t\t\t" . '$this->getMockController()->' . $protectedMethodName . ' = function() {' . PHP_EOL .3018 "\t\t\t" . '};' . PHP_EOL .3019 "\t\t" . '}' . PHP_EOL .3020 "\t\t" . '$return = $this->getMockController()->invoke(\'' . $protectedMethodName . '\', $arguments);' . PHP_EOL .3021 "\t\t" . 'return $return;' . PHP_EOL .3022 "\t" . '}' . PHP_EOL .3023 "\t" . 'public static function getMockedMethods()' . PHP_EOL .3024 "\t" . '{' . PHP_EOL .3025 "\t\t" . 'return ' . var_export(['__construct', $publicMethodName, $protectedMethodName], true) . ';' . PHP_EOL .3026 "\t" . '}' . PHP_EOL .3027 '}' . PHP_EOL .3028 '}'3029 )3030 ;3031 }3032 /**3033 * @php >= 7.03034 */3035 public function testGetMockedClassCodeWithProtectedAbstractMethodPhp7()3036 {3037 $this3038 ->if($generator = new testedClass())3039 ->and($parameterController1 = new mock\controller())3040 ->and($parameterController1->__construct = function () {3041 })3042 ->and($parameterController1->isArray = false)3043 ->and($parameterController1->isCallable = false)3044 ->and($parameterController1->getClass = null)3045 ->and($parameterController1->getName = 'arg1')3046 ->and($parameterController1->isPassedByReference = false)3047 ->and($parameterController1->isDefaultValueAvailable = false)3048 ->and($parameterController1->isOptional = false)3049 ->and($parameterController1->isVariadic = false)3050 ->and($parameterController1->hasType = false)3051 ->and($parameterController1->allowsNull = false)3052 ->and($parameter1 = new \mock\reflectionParameter(null, null))3053 ->and($parameterController2 = new mock\controller())3054 ->and($parameterController2->__construct = function () {3055 })3056 ->and($parameterController2->isArray = true)3057 ->and($parameterController2->isCallable = false)3058 ->and($parameterController2->getClass = null)3059 ->and($parameterController2->getName = 'arg2')3060 ->and($parameterController2->isPassedByReference = true)3061 ->and($parameterController2->isDefaultValueAvailable = false)3062 ->and($parameterController2->isOptional = false)3063 ->and($parameterController2->isVariadic = false)3064 ->and($parameterController2->hasType = false)3065 ->and($parameterController2->allowsNull = false)3066 ->and($parameter2 = new \mock\reflectionParameter(null, null))3067 ->and($publicMethodController = new mock\controller())3068 ->and($publicMethodController->__construct = function () {3069 })3070 ->and($publicMethodController->getName = $publicMethodName = uniqid())3071 ->and($publicMethodController->isConstructor = false)3072 ->and($publicMethodController->getParameters = [$parameter1, $parameter2])3073 ->and($publicMethodController->isPublic = true)3074 ->and($publicMethodController->isProtected = false)3075 ->and($publicMethodController->isPrivate = false)3076 ->and($publicMethodController->isFinal = false)3077 ->and($publicMethodController->isStatic = false)3078 ->and($publicMethodController->isAbstract = true)3079 ->and($publicMethodController->returnsReference = false)3080 ->and($publicMethodController->hasReturnType = false)3081 ->and($publicMethod = new \mock\reflectionMethod(null, null))3082 ->and($protectedMethodController = new mock\controller())3083 ->and($protectedMethodController->__construct = function () {3084 })3085 ->and($protectedMethodController->getName = $protectedMethodName = uniqid())3086 ->and($protectedMethodController->isConstructor = false)3087 ->and($protectedMethodController->getParameters = [])3088 ->and($protectedMethodController->isPublic = false)3089 ->and($protectedMethodController->isProtected = true)3090 ->and($protectedMethodController->isPrivate = false)3091 ->and($protectedMethodController->isFinal = false)3092 ->and($protectedMethodController->isStatic = false)3093 ->and($protectedMethodController->isAbstract = true)3094 ->and($protectedMethodController->returnsReference = false)3095 ->and($protectedMethodController->hasReturnType = false)3096 ->and($protectedMethod = new \mock\reflectionMethod(null, null))3097 ->and($classController = new mock\controller())3098 ->and($classController->__construct = function () {3099 })3100 ->and($classController->getName = $className = uniqid())3101 ->and($classController->isFinal = false)3102 ->and($classController->isInterface = false)3103 ->and($classController->getMethods = [$publicMethod, $protectedMethod])3104 ->and($classController->getConstructor = null)3105 ->and($classController->isAbstract = false)3106 ->and($class = new \mock\reflectionClass(null))3107 ->and($generator->setReflectionClassFactory(function () use ($class) {3108 return $class;3109 }))3110 ->and($adapter = new atoum\test\adapter())3111 ->and($adapter->class_exists = function ($class) use ($className) {3112 return ($class == '\\' . $className);3113 })3114 ->and($generator->setAdapter($adapter))3115 ->then3116 ->string($generator->getMockedClassCode($className))->isEqualTo(3117 'namespace mock {' . PHP_EOL .3118 'final class ' . $className . ' extends \\' . $className . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .3119 '{' . PHP_EOL .3120 $this->getMockControllerMethods() .3121 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .3122 "\t" . '{' . PHP_EOL .3123 "\t\t" . 'if ($mockController === null)' . PHP_EOL .3124 "\t\t" . '{' . PHP_EOL .3125 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .3126 "\t\t" . '}' . PHP_EOL .3127 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .3128 "\t\t" . '{' . PHP_EOL .3129 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .3130 "\t\t" . '}' . PHP_EOL .3131 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .3132 "\t\t" . '{' . PHP_EOL .3133 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .3134 "\t\t" . '}' . PHP_EOL .3135 "\t" . '}' . PHP_EOL .3136 "\t" . 'public function ' . $publicMethodName . '($arg1, array & $arg2)' . PHP_EOL .3137 "\t" . '{' . PHP_EOL .3138 "\t\t" . '$arguments = array_merge(array($arg1, & $arg2), array_slice(func_get_args(), 2));' . PHP_EOL .3139 "\t\t" . 'if (isset($this->getMockController()->' . $publicMethodName . ') === false)' . PHP_EOL .3140 "\t\t" . '{' . PHP_EOL .3141 "\t\t\t" . '$this->getMockController()->' . $publicMethodName . ' = function() {' . PHP_EOL .3142 "\t\t\t" . '};' . PHP_EOL .3143 "\t\t" . '}' . PHP_EOL .3144 "\t\t" . '$return = $this->getMockController()->invoke(\'' . $publicMethodName . '\', $arguments);' . PHP_EOL .3145 "\t\t" . 'return $return;' . PHP_EOL .3146 "\t" . '}' . PHP_EOL .3147 "\t" . 'protected function ' . $protectedMethodName . '()' . PHP_EOL .3148 "\t" . '{' . PHP_EOL .3149 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .3150 "\t\t" . 'if (isset($this->getMockController()->' . $protectedMethodName . ') === false)' . PHP_EOL .3151 "\t\t" . '{' . PHP_EOL .3152 "\t\t\t" . '$this->getMockController()->' . $protectedMethodName . ' = function() {' . PHP_EOL .3153 "\t\t\t" . '};' . PHP_EOL .3154 "\t\t" . '}' . PHP_EOL .3155 "\t\t" . '$return = $this->getMockController()->invoke(\'' . $protectedMethodName . '\', $arguments);' . PHP_EOL .3156 "\t\t" . 'return $return;' . PHP_EOL .3157 "\t" . '}' . PHP_EOL .3158 "\t" . 'public static function getMockedMethods()' . PHP_EOL .3159 "\t" . '{' . PHP_EOL .3160 "\t\t" . 'return ' . var_export(['__construct', $publicMethodName, $protectedMethodName], true) . ';' . PHP_EOL .3161 "\t" . '}' . PHP_EOL .3162 '}' . PHP_EOL .3163 '}'3164 )3165 ;3166 }3167 public function testGetMockedClassCodeForClassWithCallableTypeHint()3168 {3169 $this3170 ->if($generator = new testedClass())3171 ->and($reflectionParameterController = new mock\controller())3172 ->and($reflectionParameterController->__construct = function () {3173 })3174 ->and($reflectionParameterController->isArray = false)3175 ->and($reflectionParameterController->isCallable = true)3176 ->and($reflectionParameterController->getName = 'callback')3177 ->and($reflectionParameterController->isPassedByReference = false)3178 ->and($reflectionParameterController->isDefaultValueAvailable = false)3179 ->and($reflectionParameterController->isOptional = false)3180 ->and($reflectionParameterController->isVariadic = false)3181 ->and($reflectionParameterController->allowsNull = false)3182 ->and($reflectionParameter = new \mock\reflectionParameter(null, null))3183 ->and($reflectionMethodController = new mock\controller())3184 ->and($reflectionMethodController->__construct = function () {3185 })3186 ->and($reflectionMethodController->getName = '__construct')3187 ->and($reflectionMethodController->isConstructor = true)3188 ->and($reflectionMethodController->getParameters = [$reflectionParameter])3189 ->and($reflectionMethodController->isPublic = true)3190 ->and($reflectionMethodController->isProtected = false)3191 ->and($reflectionMethodController->isPrivate = false)3192 ->and($reflectionMethodController->isFinal = false)3193 ->and($reflectionMethodController->isStatic = false)3194 ->and($reflectionMethodController->isAbstract = false)3195 ->and($reflectionMethodController->returnsReference = false)3196 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))3197 ->and($reflectionClassController = new mock\controller())3198 ->and($reflectionClassController->__construct = function () {3199 })3200 ->and($reflectionClassController->getName = function () use (& $realClass) {3201 return $realClass;3202 })3203 ->and($reflectionClassController->isFinal = false)3204 ->and($reflectionClassController->isInterface = false)3205 ->and($reflectionClassController->getMethods = [$reflectionMethod])3206 ->and($reflectionClassController->getConstructor = $reflectionMethod)3207 ->and($reflectionClassController->isAbstract = false)3208 ->and($reflectionClass = new \mock\reflectionClass(null))3209 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {3210 return $reflectionClass;3211 }))3212 ->and($adapter = new atoum\test\adapter())3213 ->and($adapter->class_exists = function ($class) use (& $realClass) {3214 return ($class == '\\' . $realClass);3215 })3216 ->and($generator->setAdapter($adapter))3217 ->then3218 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(3219 'namespace mock {' . PHP_EOL .3220 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .3221 '{' . PHP_EOL .3222 $this->getMockControllerMethods() .3223 "\t" . 'public function __construct(callable $callback, \mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .3224 "\t" . '{' . PHP_EOL .3225 "\t\t" . '$arguments = array_merge(array($callback), array_slice(func_get_args(), 1, -1));' . PHP_EOL .3226 "\t\t" . 'if ($mockController === null)' . PHP_EOL .3227 "\t\t" . '{' . PHP_EOL .3228 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .3229 "\t\t" . '}' . PHP_EOL .3230 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .3231 "\t\t" . '{' . PHP_EOL .3232 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .3233 "\t\t" . '}' . PHP_EOL .3234 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .3235 "\t\t" . '{' . PHP_EOL .3236 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .3237 "\t\t" . '}' . PHP_EOL .3238 "\t\t" . 'else' . PHP_EOL .3239 "\t\t" . '{' . PHP_EOL .3240 "\t\t\t" . '$this->getMockController()->addCall(\'__construct\', $arguments);' . PHP_EOL .3241 "\t\t\t" . 'call_user_func_array(\'parent::__construct\', $arguments);' . PHP_EOL .3242 "\t\t" . '}' . PHP_EOL .3243 "\t" . '}' . PHP_EOL .3244 "\t" . 'public static function getMockedMethods()' . PHP_EOL .3245 "\t" . '{' . PHP_EOL .3246 "\t\t" . 'return ' . var_export(['__construct'], true) . ';' . PHP_EOL .3247 "\t" . '}' . PHP_EOL .3248 '}' . PHP_EOL .3249 '}'3250 )3251 ;3252 }3253 /**3254 * @php < 7.03255 */3256 public function testGetMockedClassCodeForClassWithVariadicArgumentsInConstruct()3257 {3258 $this3259 ->if($generator = new testedClass())3260 ->and($reflectionParameterController = new mock\controller())3261 ->and($reflectionParameterController->__construct = function () {3262 })3263 ->and($reflectionParameterController->isArray = false)3264 ->and($reflectionParameterController->isCallable = false)3265 ->and($reflectionParameterController->getName = 'variadic')3266 ->and($reflectionParameterController->isPassedByReference = false)3267 ->and($reflectionParameterController->isDefaultValueAvailable = false)3268 ->and($reflectionParameterController->isOptional = false)3269 ->and($reflectionParameterController->isVariadic = true)3270 ->and($reflectionParameterController->getClass = null)3271 ->and($reflectionParameterController->allowsNull = false)3272 ->and($reflectionParameter = new \mock\reflectionParameter(null, null))3273 ->and($reflectionMethodController = new mock\controller())3274 ->and($reflectionMethodController->__construct = function () {3275 })3276 ->and($reflectionMethodController->getName = '__construct')3277 ->and($reflectionMethodController->isConstructor = true)3278 ->and($reflectionMethodController->getParameters = [$reflectionParameter])3279 ->and($reflectionMethodController->isPublic = true)3280 ->and($reflectionMethodController->isProtected = false)3281 ->and($reflectionMethodController->isPrivate = false)3282 ->and($reflectionMethodController->isFinal = false)3283 ->and($reflectionMethodController->isStatic = false)3284 ->and($reflectionMethodController->isAbstract = false)3285 ->and($reflectionMethodController->returnsReference = false)3286 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))3287 ->and($reflectionClassController = new mock\controller())3288 ->and($reflectionClassController->__construct = function () {3289 })3290 ->and($reflectionClassController->getName = function () use (& $realClass) {3291 return $realClass;3292 })3293 ->and($reflectionClassController->isFinal = false)3294 ->and($reflectionClassController->isInterface = false)3295 ->and($reflectionClassController->getMethods = [$reflectionMethod])3296 ->and($reflectionClassController->getConstructor = $reflectionMethod)3297 ->and($reflectionClassController->isAbstract = false)3298 ->and($reflectionClass = new \mock\reflectionClass(null))3299 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {3300 return $reflectionClass;3301 }))3302 ->and($adapter = new atoum\test\adapter())3303 ->and($adapter->class_exists = function ($class) use (& $realClass) {3304 return ($class == '\\' . $realClass);3305 })3306 ->and($generator->setAdapter($adapter))3307 ->then3308 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(3309 'namespace mock {' . PHP_EOL .3310 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .3311 '{' . PHP_EOL .3312 $this->getMockControllerMethods() .3313 "\t" . 'public function __construct(... $variadic)' . PHP_EOL .3314 "\t" . '{' . PHP_EOL .3315 "\t\t" . '$arguments = func_get_args();' . PHP_EOL .3316 "\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .3317 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .3318 "\t\t" . '{' . PHP_EOL .3319 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .3320 "\t\t" . '}' . PHP_EOL .3321 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .3322 "\t\t" . '{' . PHP_EOL .3323 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .3324 "\t\t" . '}' . PHP_EOL .3325 "\t\t" . 'else' . PHP_EOL .3326 "\t\t" . '{' . PHP_EOL .3327 "\t\t\t" . '$this->getMockController()->addCall(\'__construct\', $arguments);' . PHP_EOL .3328 "\t\t\t" . 'call_user_func_array(\'parent::__construct\', $arguments);' . PHP_EOL .3329 "\t\t" . '}' . PHP_EOL .3330 "\t" . '}' . PHP_EOL .3331 "\t" . 'public static function getMockedMethods()' . PHP_EOL .3332 "\t" . '{' . PHP_EOL .3333 "\t\t" . 'return ' . var_export(['__construct'], true) . ';' . PHP_EOL .3334 "\t" . '}' . PHP_EOL .3335 '}' . PHP_EOL .3336 '}'3337 )3338 ;3339 }3340 /**3341 * @php < 7.03342 */3343 public function testGetMockedClassCodeForClassWithOnlyVariadicArgumentsInMethod()3344 {3345 $this3346 ->if($generator = new testedClass())3347 ->and($reflectionParameterController = new mock\controller())3348 ->and($reflectionParameterController->__construct = function () {3349 })3350 ->and($reflectionParameterController->isArray = false)3351 ->and($reflectionParameterController->isCallable = false)3352 ->and($reflectionParameterController->getName = 'variadic')3353 ->and($reflectionParameterController->isPassedByReference = false)3354 ->and($reflectionParameterController->isDefaultValueAvailable = false)3355 ->and($reflectionParameterController->isOptional = false)3356 ->and($reflectionParameterController->isVariadic = true)3357 ->and($reflectionParameterController->getClass = null)3358 ->and($reflectionParameterController->allowsNull = false)3359 ->and($reflectionParameter = new \mock\reflectionParameter(null, null))3360 ->and($reflectionMethodController = new mock\controller())3361 ->and($reflectionMethodController->__construct = function () {3362 })3363 ->and($reflectionMethodController->getName = $methodName = uniqid())3364 ->and($reflectionMethodController->isConstructor = false)3365 ->and($reflectionMethodController->getParameters = [$reflectionParameter])3366 ->and($reflectionMethodController->isPublic = true)3367 ->and($reflectionMethodController->isProtected = false)3368 ->and($reflectionMethodController->isPrivate = false)3369 ->and($reflectionMethodController->isFinal = false)3370 ->and($reflectionMethodController->isStatic = false)3371 ->and($reflectionMethodController->isAbstract = false)3372 ->and($reflectionMethodController->returnsReference = false)3373 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))3374 ->and($reflectionClassController = new mock\controller())3375 ->and($reflectionClassController->__construct = function () {3376 })3377 ->and($reflectionClassController->getName = function () use (& $realClass) {3378 return $realClass;3379 })3380 ->and($reflectionClassController->isFinal = false)3381 ->and($reflectionClassController->isInterface = false)3382 ->and($reflectionClassController->getMethods = [$reflectionMethod])3383 ->and($reflectionClassController->getConstructor = null)3384 ->and($reflectionClassController->isAbstract = false)3385 ->and($reflectionClass = new \mock\reflectionClass(null))3386 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {3387 return $reflectionClass;3388 }))3389 ->and($adapter = new atoum\test\adapter())3390 ->and($adapter->class_exists = function ($class) use (& $realClass) {3391 return ($class == '\\' . $realClass);3392 })3393 ->and($generator->setAdapter($adapter))3394 ->then3395 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(3396 'namespace mock {' . PHP_EOL .3397 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .3398 '{' . PHP_EOL .3399 $this->getMockControllerMethods() .3400 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .3401 "\t" . '{' . PHP_EOL .3402 "\t\t" . 'if ($mockController === null)' . PHP_EOL .3403 "\t\t" . '{' . PHP_EOL .3404 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .3405 "\t\t" . '}' . PHP_EOL .3406 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .3407 "\t\t" . '{' . PHP_EOL .3408 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .3409 "\t\t" . '}' . PHP_EOL .3410 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .3411 "\t\t" . '{' . PHP_EOL .3412 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .3413 "\t\t" . '}' . PHP_EOL .3414 "\t" . '}' . PHP_EOL .3415 "\t" . 'public function ' . $methodName . '(... $variadic)' . PHP_EOL .3416 "\t" . '{' . PHP_EOL .3417 "\t\t" . '$arguments = func_get_args();' . PHP_EOL .3418 "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL .3419 "\t\t" . '{' . PHP_EOL .3420 "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL .3421 "\t\t\t" . 'return $return;' . PHP_EOL .3422 "\t\t" . '}' . PHP_EOL .3423 "\t\t" . 'else' . PHP_EOL .3424 "\t\t" . '{' . PHP_EOL .3425 "\t\t\t" . '$this->getMockController()->addCall(\'' . $methodName . '\', $arguments);' . PHP_EOL .3426 "\t\t\t" . '$return = call_user_func_array(\'parent::' . $methodName . '\', $arguments);' . PHP_EOL .3427 "\t\t\t" . 'return $return;' . PHP_EOL .3428 "\t\t" . '}' . PHP_EOL .3429 "\t" . '}' . PHP_EOL .3430 "\t" . 'public static function getMockedMethods()' . PHP_EOL .3431 "\t" . '{' . PHP_EOL .3432 "\t\t" . 'return ' . var_export(['__construct', $methodName], true) . ';' . PHP_EOL .3433 "\t" . '}' . PHP_EOL .3434 '}' . PHP_EOL .3435 '}'3436 )3437 ;3438 }3439 /** @php >= 7.0 */3440 public function testGetMockedClassCodeForMethodWithTypeHint()3441 {3442 $this3443 ->if($generator = new testedClass())3444 ->and($reflectionParameterController = new mock\controller())3445 ->and($reflectionParameterController->__construct = function () {3446 })3447 ->and($reflectionParameterController->isArray = false)3448 ->and($reflectionParameterController->isCallable = false)3449 ->and($reflectionParameterController->getName = 'typeHint')3450 ->and($reflectionParameterController->isPassedByReference = false)3451 ->and($reflectionParameterController->isDefaultValueAvailable = false)3452 ->and($reflectionParameterController->isOptional = false)3453 ->and($reflectionParameterController->isVariadic = false)3454 ->and($reflectionParameterController->getClass = null)3455 ->and($reflectionParameterController->hasType = true)3456 ->and($reflectionParameterController->getType = 'string')3457 ->and($reflectionParameterController->allowsNull = false)3458 ->and($reflectionParameter = new \mock\reflectionParameter(null, null))3459 ->and($reflectionMethodController = new mock\controller())3460 ->and($reflectionMethodController->__construct = function () {3461 })3462 ->and($reflectionMethodController->getName = $methodName = uniqid())3463 ->and($reflectionMethodController->isConstructor = false)3464 ->and($reflectionMethodController->getParameters = [$reflectionParameter])3465 ->and($reflectionMethodController->isPublic = true)3466 ->and($reflectionMethodController->isProtected = false)3467 ->and($reflectionMethodController->isPrivate = false)3468 ->and($reflectionMethodController->isFinal = false)3469 ->and($reflectionMethodController->isStatic = false)3470 ->and($reflectionMethodController->isAbstract = false)3471 ->and($reflectionMethodController->returnsReference = false)3472 ->and($reflectionMethodController->hasReturnType = false)3473 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))3474 ->and($reflectionClassController = new mock\controller())3475 ->and($reflectionClassController->__construct = function () {3476 })3477 ->and($reflectionClassController->getName = function () use (& $realClass) {3478 return $realClass;3479 })3480 ->and($reflectionClassController->isFinal = false)3481 ->and($reflectionClassController->isInterface = false)3482 ->and($reflectionClassController->getMethods = [$reflectionMethod])3483 ->and($reflectionClassController->getConstructor = null)3484 ->and($reflectionClassController->isAbstract = false)3485 ->and($reflectionClass = new \mock\reflectionClass(null))3486 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {3487 return $reflectionClass;3488 }))3489 ->and($adapter = new atoum\test\adapter())3490 ->and($adapter->class_exists = function ($class) use (& $realClass) {3491 return ($class == '\\' . $realClass);3492 })3493 ->and($generator->setAdapter($adapter))3494 ->then3495 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(3496 'namespace mock {' . PHP_EOL .3497 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .3498 '{' . PHP_EOL .3499 $this->getMockControllerMethods() .3500 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .3501 "\t" . '{' . PHP_EOL .3502 "\t\t" . 'if ($mockController === null)' . PHP_EOL .3503 "\t\t" . '{' . PHP_EOL .3504 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .3505 "\t\t" . '}' . PHP_EOL .3506 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .3507 "\t\t" . '{' . PHP_EOL .3508 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .3509 "\t\t" . '}' . PHP_EOL .3510 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .3511 "\t\t" . '{' . PHP_EOL .3512 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .3513 "\t\t" . '}' . PHP_EOL .3514 "\t" . '}' . PHP_EOL .3515 "\t" . 'public function ' . $methodName . '(string $typeHint)' . PHP_EOL .3516 "\t" . '{' . PHP_EOL .3517 "\t\t" . '$arguments = array_merge(array($typeHint), array_slice(func_get_args(), 1));' . PHP_EOL .3518 "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL .3519 "\t\t" . '{' . PHP_EOL .3520 "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL .3521 "\t\t\t" . 'return $return;' . PHP_EOL .3522 "\t\t" . '}' . PHP_EOL .3523 "\t\t" . 'else' . PHP_EOL .3524 "\t\t" . '{' . PHP_EOL .3525 "\t\t\t" . '$this->getMockController()->addCall(\'' . $methodName . '\', $arguments);' . PHP_EOL .3526 "\t\t\t" . '$return = call_user_func_array(\'parent::' . $methodName . '\', $arguments);' . PHP_EOL .3527 "\t\t\t" . 'return $return;' . PHP_EOL .3528 "\t\t" . '}' . PHP_EOL .3529 "\t" . '}' . PHP_EOL .3530 "\t" . 'public static function getMockedMethods()' . PHP_EOL .3531 "\t" . '{' . PHP_EOL .3532 "\t\t" . 'return ' . var_export(['__construct', $methodName], true) . ';' . PHP_EOL .3533 "\t" . '}' . PHP_EOL .3534 '}' . PHP_EOL .3535 '}'3536 )3537 ;3538 }3539 /**3540 * @php < 7.13541 * @php >= 7.03542 */3543 public function testGetMockedClassCodeForMethodWithTypeHintNullable()3544 {3545 $this3546 ->if($generator = new testedClass())3547 ->and($reflectionParameterController = new mock\controller())3548 ->and($reflectionParameterController->__construct = function () {3549 })3550 ->and($reflectionParameterController->isArray = false)3551 ->and($reflectionParameterController->isCallable = false)3552 ->and($reflectionParameterController->getName = 'typeHint')3553 ->and($reflectionParameterController->isPassedByReference = false)3554 ->and($reflectionParameterController->isDefaultValueAvailable = false)3555 ->and($reflectionParameterController->isOptional = false)3556 ->and($reflectionParameterController->isVariadic = false)3557 ->and($reflectionParameterController->getClass = null)3558 ->and($reflectionParameterController->hasType = true)3559 ->and($reflectionParameterController->getType = 'string')3560 ->and($reflectionParameterController->allowsNull = true)3561 ->and($reflectionParameter = new \mock\reflectionParameter(null, null))3562 ->and($reflectionMethodController = new mock\controller())3563 ->and($reflectionMethodController->__construct = function () {3564 })3565 ->and($reflectionMethodController->getName = $methodName = uniqid())3566 ->and($reflectionMethodController->isConstructor = false)3567 ->and($reflectionMethodController->getParameters = [$reflectionParameter])3568 ->and($reflectionMethodController->isPublic = true)3569 ->and($reflectionMethodController->isProtected = false)3570 ->and($reflectionMethodController->isPrivate = false)3571 ->and($reflectionMethodController->isFinal = false)3572 ->and($reflectionMethodController->isStatic = false)3573 ->and($reflectionMethodController->isAbstract = false)3574 ->and($reflectionMethodController->returnsReference = false)3575 ->and($reflectionMethodController->hasReturnType = false)3576 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))3577 ->and($reflectionClassController = new mock\controller())3578 ->and($reflectionClassController->__construct = function () {3579 })3580 ->and($reflectionClassController->getName = function () use (& $realClass) {3581 return $realClass;3582 })3583 ->and($reflectionClassController->isFinal = false)3584 ->and($reflectionClassController->isInterface = false)3585 ->and($reflectionClassController->getMethods = [$reflectionMethod])3586 ->and($reflectionClassController->getConstructor = null)3587 ->and($reflectionClassController->isAbstract = false)3588 ->and($reflectionClass = new \mock\reflectionClass(null))3589 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {3590 return $reflectionClass;3591 }))3592 ->and($adapter = new atoum\test\adapter())3593 ->and($adapter->class_exists = function ($class) use (& $realClass) {3594 return ($class == '\\' . $realClass);3595 })3596 ->and($generator->setAdapter($adapter))3597 ->then3598 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(3599 'namespace mock {' . PHP_EOL .3600 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .3601 '{' . PHP_EOL .3602 $this->getMockControllerMethods() .3603 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .3604 "\t" . '{' . PHP_EOL .3605 "\t\t" . 'if ($mockController === null)' . PHP_EOL .3606 "\t\t" . '{' . PHP_EOL .3607 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .3608 "\t\t" . '}' . PHP_EOL .3609 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .3610 "\t\t" . '{' . PHP_EOL .3611 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .3612 "\t\t" . '}' . PHP_EOL .3613 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .3614 "\t\t" . '{' . PHP_EOL .3615 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .3616 "\t\t" . '}' . PHP_EOL .3617 "\t" . '}' . PHP_EOL .3618 "\t" . 'public function ' . $methodName . '(string $typeHint)' . PHP_EOL .3619 "\t" . '{' . PHP_EOL .3620 "\t\t" . '$arguments = array_merge(array($typeHint), array_slice(func_get_args(), 1));' . PHP_EOL .3621 "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL .3622 "\t\t" . '{' . PHP_EOL .3623 "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL .3624 "\t\t\t" . 'return $return;' . PHP_EOL .3625 "\t\t" . '}' . PHP_EOL .3626 "\t\t" . 'else' . PHP_EOL .3627 "\t\t" . '{' . PHP_EOL .3628 "\t\t\t" . '$this->getMockController()->addCall(\'' . $methodName . '\', $arguments);' . PHP_EOL .3629 "\t\t\t" . '$return = call_user_func_array(\'parent::' . $methodName . '\', $arguments);' . PHP_EOL .3630 "\t\t\t" . 'return $return;' . PHP_EOL .3631 "\t\t" . '}' . PHP_EOL .3632 "\t" . '}' . PHP_EOL .3633 "\t" . 'public static function getMockedMethods()' . PHP_EOL .3634 "\t" . '{' . PHP_EOL .3635 "\t\t" . 'return ' . var_export(['__construct', $methodName], true) . ';' . PHP_EOL .3636 "\t" . '}' . PHP_EOL .3637 '}' . PHP_EOL .3638 '}'3639 )3640 ;3641 }3642 /** @php >= 7.1 */3643 public function testGetMockedClassCodeForMethodWithTypeHintNullablePHP71()3644 {3645 $this3646 ->if($generator = new testedClass())3647 ->and($reflectionParameterController = new mock\controller())3648 ->and($reflectionParameterController->__construct = function () {3649 })3650 ->and($reflectionParameterController->isArray = false)3651 ->and($reflectionParameterController->isCallable = false)3652 ->and($reflectionParameterController->getName = 'typeHint')3653 ->and($reflectionParameterController->isPassedByReference = false)3654 ->and($reflectionParameterController->isDefaultValueAvailable = false)3655 ->and($reflectionParameterController->isOptional = false)3656 ->and($reflectionParameterController->isVariadic = false)3657 ->and($reflectionParameterController->getClass = null)3658 ->and($reflectionParameterController->hasType = true)3659 ->and($reflectionParameterController->getType = 'string')3660 ->and($reflectionParameterController->allowsNull = true)3661 ->and($reflectionParameter = new \mock\reflectionParameter(null, null))3662 ->and($reflectionMethodController = new mock\controller())3663 ->and($reflectionMethodController->__construct = function () {3664 })3665 ->and($reflectionMethodController->getName = $methodName = uniqid())3666 ->and($reflectionMethodController->isConstructor = false)3667 ->and($reflectionMethodController->getParameters = [$reflectionParameter])3668 ->and($reflectionMethodController->isPublic = true)3669 ->and($reflectionMethodController->isProtected = false)3670 ->and($reflectionMethodController->isPrivate = false)3671 ->and($reflectionMethodController->isFinal = false)3672 ->and($reflectionMethodController->isStatic = false)3673 ->and($reflectionMethodController->isAbstract = false)3674 ->and($reflectionMethodController->returnsReference = false)3675 ->and($reflectionMethodController->hasReturnType = false)3676 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))3677 ->and($reflectionClassController = new mock\controller())3678 ->and($reflectionClassController->__construct = function () {3679 })3680 ->and($reflectionClassController->getName = function () use (& $realClass) {3681 return $realClass;3682 })3683 ->and($reflectionClassController->isFinal = false)3684 ->and($reflectionClassController->isInterface = false)3685 ->and($reflectionClassController->getMethods = [$reflectionMethod])3686 ->and($reflectionClassController->getConstructor = null)3687 ->and($reflectionClassController->isAbstract = false)3688 ->and($reflectionClass = new \mock\reflectionClass(null))3689 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {3690 return $reflectionClass;3691 }))3692 ->and($adapter = new atoum\test\adapter())3693 ->and($adapter->class_exists = function ($class) use (& $realClass) {3694 return ($class == '\\' . $realClass);3695 })3696 ->and($generator->setAdapter($adapter))3697 ->then3698 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(3699 'namespace mock {' . PHP_EOL .3700 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .3701 '{' . PHP_EOL .3702 $this->getMockControllerMethods() .3703 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .3704 "\t" . '{' . PHP_EOL .3705 "\t\t" . 'if ($mockController === null)' . PHP_EOL .3706 "\t\t" . '{' . PHP_EOL .3707 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .3708 "\t\t" . '}' . PHP_EOL .3709 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .3710 "\t\t" . '{' . PHP_EOL .3711 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .3712 "\t\t" . '}' . PHP_EOL .3713 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .3714 "\t\t" . '{' . PHP_EOL .3715 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .3716 "\t\t" . '}' . PHP_EOL .3717 "\t" . '}' . PHP_EOL .3718 "\t" . 'public function ' . $methodName . '(?string $typeHint)' . PHP_EOL .3719 "\t" . '{' . PHP_EOL .3720 "\t\t" . '$arguments = array_merge(array($typeHint), array_slice(func_get_args(), 1));' . PHP_EOL .3721 "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL .3722 "\t\t" . '{' . PHP_EOL .3723 "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL .3724 "\t\t\t" . 'return $return;' . PHP_EOL .3725 "\t\t" . '}' . PHP_EOL .3726 "\t\t" . 'else' . PHP_EOL .3727 "\t\t" . '{' . PHP_EOL .3728 "\t\t\t" . '$this->getMockController()->addCall(\'' . $methodName . '\', $arguments);' . PHP_EOL .3729 "\t\t\t" . '$return = call_user_func_array(\'parent::' . $methodName . '\', $arguments);' . PHP_EOL .3730 "\t\t\t" . 'return $return;' . PHP_EOL .3731 "\t\t" . '}' . PHP_EOL .3732 "\t" . '}' . PHP_EOL .3733 "\t" . 'public static function getMockedMethods()' . PHP_EOL .3734 "\t" . '{' . PHP_EOL .3735 "\t\t" . 'return ' . var_export(['__construct', $methodName], true) . ';' . PHP_EOL .3736 "\t" . '}' . PHP_EOL .3737 '}' . PHP_EOL .3738 '}'3739 )3740 ;3741 }3742 /** @php >= 7.0 */3743 public function testGetMockedClassCodeForMethodWithReturnType()3744 {3745 $this3746 ->if($generator = new testedClass())3747 ->and($reflectionTypeController = new mock\controller())3748 ->and($reflectionTypeController->__construct = function () {3749 })3750 ->and($reflectionTypeController->isBuiltin = true)3751 ->and($reflectionTypeController->allowsNull = false)3752 ->and($reflectionTypeController->__toString = $returnType = 'string')3753 ->and($reflectionType = new \mock\reflectionType())3754 ->and($reflectionMethodController = new mock\controller())3755 ->and($reflectionMethodController->__construct = function () {3756 })3757 ->and($reflectionMethodController->getName = $methodName = uniqid())3758 ->and($reflectionMethodController->isConstructor = false)3759 ->and($reflectionMethodController->getParameters = [])3760 ->and($reflectionMethodController->isPublic = true)3761 ->and($reflectionMethodController->isProtected = false)3762 ->and($reflectionMethodController->isPrivate = false)3763 ->and($reflectionMethodController->isFinal = false)3764 ->and($reflectionMethodController->isStatic = false)3765 ->and($reflectionMethodController->isAbstract = false)3766 ->and($reflectionMethodController->returnsReference = false)3767 ->and($reflectionMethodController->hasReturnType = true)3768 ->and($reflectionMethodController->getReturnType = $reflectionType)3769 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))3770 ->and($reflectionClassController = new mock\controller())3771 ->and($reflectionClassController->__construct = function () {3772 })3773 ->and($reflectionClassController->getName = function () use (& $realClass) {3774 return $realClass;3775 })3776 ->and($reflectionClassController->isFinal = false)3777 ->and($reflectionClassController->isInterface = false)3778 ->and($reflectionClassController->getMethods = [$reflectionMethod])3779 ->and($reflectionClassController->getConstructor = null)3780 ->and($reflectionClassController->isAbstract = false)3781 ->and($reflectionClass = new \mock\reflectionClass(null))3782 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {3783 return $reflectionClass;3784 }))3785 ->and($adapter = new atoum\test\adapter())3786 ->and($adapter->class_exists = function ($class) use (& $realClass) {3787 return ($class == '\\' . $realClass);3788 })3789 ->and($generator->setAdapter($adapter))3790 ->then3791 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(3792 'namespace mock {' . PHP_EOL .3793 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .3794 '{' . PHP_EOL .3795 $this->getMockControllerMethods() .3796 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .3797 "\t" . '{' . PHP_EOL .3798 "\t\t" . 'if ($mockController === null)' . PHP_EOL .3799 "\t\t" . '{' . PHP_EOL .3800 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .3801 "\t\t" . '}' . PHP_EOL .3802 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .3803 "\t\t" . '{' . PHP_EOL .3804 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .3805 "\t\t" . '}' . PHP_EOL .3806 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .3807 "\t\t" . '{' . PHP_EOL .3808 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .3809 "\t\t" . '}' . PHP_EOL .3810 "\t" . '}' . PHP_EOL .3811 "\t" . 'public function ' . $methodName . '(): ' . $returnType . PHP_EOL .3812 "\t" . '{' . PHP_EOL .3813 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .3814 "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL .3815 "\t\t" . '{' . PHP_EOL .3816 "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL .3817 "\t\t\t" . 'return $return;' . PHP_EOL .3818 "\t\t" . '}' . PHP_EOL .3819 "\t\t" . 'else' . PHP_EOL .3820 "\t\t" . '{' . PHP_EOL .3821 "\t\t\t" . '$this->getMockController()->addCall(\'' . $methodName . '\', $arguments);' . PHP_EOL .3822 "\t\t\t" . '$return = call_user_func_array(\'parent::' . $methodName . '\', $arguments);' . PHP_EOL .3823 "\t\t\t" . 'return $return;' . PHP_EOL .3824 "\t\t" . '}' . PHP_EOL .3825 "\t" . '}' . PHP_EOL .3826 "\t" . 'public static function getMockedMethods()' . PHP_EOL .3827 "\t" . '{' . PHP_EOL .3828 "\t\t" . 'return ' . var_export(['__construct', $methodName], true) . ';' . PHP_EOL .3829 "\t" . '}' . PHP_EOL .3830 '}' . PHP_EOL .3831 '}'3832 )3833 ;3834 }3835 /** @php >= 7.0 */3836 public function testGetMockedClassCodeForMethodWithReservedWord()3837 {3838 $this3839 ->if($generator = new testedClass())3840 ->and($reflectionMethodController = new mock\controller())3841 ->and($reflectionMethodController->__construct = function () {3842 })3843 ->and($reflectionMethodController->getName = $methodName = 'list')3844 ->and($reflectionMethodController->isConstructor = false)3845 ->and($reflectionMethodController->getParameters = [])3846 ->and($reflectionMethodController->isPublic = true)3847 ->and($reflectionMethodController->isProtected = false)3848 ->and($reflectionMethodController->isPrivate = false)3849 ->and($reflectionMethodController->isFinal = false)3850 ->and($reflectionMethodController->isStatic = false)3851 ->and($reflectionMethodController->isAbstract = false)3852 ->and($reflectionMethodController->returnsReference = false)3853 ->and($reflectionMethodController->hasReturnType = false)3854 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))3855 ->and($reflectionClassController = new mock\controller())3856 ->and($reflectionClassController->__construct = function () {3857 })3858 ->and($reflectionClassController->getName = function () use (& $realClass) {3859 return $realClass;3860 })3861 ->and($reflectionClassController->isFinal = false)3862 ->and($reflectionClassController->isInterface = false)3863 ->and($reflectionClassController->getMethods = [$reflectionMethod])3864 ->and($reflectionClassController->getConstructor = null)3865 ->and($reflectionClassController->isAbstract = false)3866 ->and($reflectionClass = new \mock\reflectionClass(null))3867 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {3868 return $reflectionClass;3869 }))3870 ->and($adapter = new atoum\test\adapter())3871 ->and($adapter->class_exists = function ($class) use (& $realClass) {3872 return ($class == '\\' . $realClass);3873 })3874 ->and($generator->setAdapter($adapter))3875 ->then3876 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(3877 'namespace mock {' . PHP_EOL .3878 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .3879 '{' . PHP_EOL .3880 $this->getMockControllerMethods() .3881 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .3882 "\t" . '{' . PHP_EOL .3883 "\t\t" . 'if ($mockController === null)' . PHP_EOL .3884 "\t\t" . '{' . PHP_EOL .3885 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .3886 "\t\t" . '}' . PHP_EOL .3887 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .3888 "\t\t" . '{' . PHP_EOL .3889 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .3890 "\t\t" . '}' . PHP_EOL .3891 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .3892 "\t\t" . '{' . PHP_EOL .3893 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .3894 "\t\t" . '}' . PHP_EOL .3895 "\t" . '}' . PHP_EOL .3896 "\t" . 'public function ' . $methodName . '()' . PHP_EOL .3897 "\t" . '{' . PHP_EOL .3898 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .3899 "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL .3900 "\t\t" . '{' . PHP_EOL .3901 "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL .3902 "\t\t\t" . 'return $return;' . PHP_EOL .3903 "\t\t" . '}' . PHP_EOL .3904 "\t\t" . 'else' . PHP_EOL .3905 "\t\t" . '{' . PHP_EOL .3906 "\t\t\t" . '$this->getMockController()->addCall(\'' . $methodName . '\', $arguments);' . PHP_EOL .3907 "\t\t\t" . '$return = call_user_func_array(\'parent::' . $methodName . '\', $arguments);' . PHP_EOL .3908 "\t\t\t" . 'return $return;' . PHP_EOL .3909 "\t\t" . '}' . PHP_EOL .3910 "\t" . '}' . PHP_EOL .3911 "\t" . 'public static function getMockedMethods()' . PHP_EOL .3912 "\t" . '{' . PHP_EOL .3913 "\t\t" . 'return ' . var_export(['__construct', $methodName], true) . ';' . PHP_EOL .3914 "\t" . '}' . PHP_EOL .3915 '}' . PHP_EOL .3916 '}'3917 )3918 ;3919 }3920 /** @php >= 7.0 */3921 public function testGetMockedClassCodeForMethodWithSelfReturnType()3922 {3923 $this3924 ->if($generator = new testedClass())3925 ->and($reflectionTypeController = new mock\controller())3926 ->and($reflectionTypeController->__construct = function () {3927 })3928 ->and($reflectionTypeController->__toString = 'self')3929 ->and($reflectionTypeController->isBuiltIn = false)3930 ->and($reflectionTypeController->allowsNull = false)3931 ->and($reflectionType = new \mock\reflectionType())3932 ->and($reflectionMethodController = new mock\controller())3933 ->and($reflectionMethodController->__construct = function () {3934 })3935 ->and($reflectionMethodController->getName = $methodName = 'returnSelf')3936 ->and($reflectionMethodController->isConstructor = false)3937 ->and($reflectionMethodController->getParameters = [])3938 ->and($reflectionMethodController->isPublic = true)3939 ->and($reflectionMethodController->isProtected = false)3940 ->and($reflectionMethodController->isPrivate = false)3941 ->and($reflectionMethodController->isFinal = false)3942 ->and($reflectionMethodController->isStatic = false)3943 ->and($reflectionMethodController->isAbstract = false)3944 ->and($reflectionMethodController->returnsReference = false)3945 ->and($reflectionMethodController->hasReturnType = true)3946 ->and($reflectionMethodController->getReturnType = $reflectionType)3947 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))3948 ->and($reflectionClassController = new mock\controller())3949 ->and($reflectionClassController->__construct = function () {3950 })3951 ->and($reflectionClassController->getName = function () use (& $realClass) {3952 return $realClass;3953 })3954 ->and($reflectionClassController->isFinal = false)3955 ->and($reflectionClassController->isInterface = false)3956 ->and($reflectionClassController->getMethods = [$reflectionMethod])3957 ->and($reflectionClassController->getConstructor = null)3958 ->and($reflectionClassController->isAbstract = false)3959 ->and($reflectionClass = new \mock\reflectionClass(null))3960 ->and($reflectionMethodController->getDeclaringClass = $reflectionClass)3961 ->and($generator->setReflectionClassFactory(function () use ($reflectionClass) {3962 return $reflectionClass;3963 }))3964 ->and($adapter = new atoum\test\adapter())3965 ->and($adapter->class_exists = function ($class) use (& $realClass) {3966 return ($class == '\\' . $realClass);3967 })3968 ->and($generator->setAdapter($adapter))3969 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(3970 'namespace mock {' . PHP_EOL .3971 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .3972 '{' . PHP_EOL .3973 $this->getMockControllerMethods() .3974 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .3975 "\t" . '{' . PHP_EOL .3976 "\t\t" . 'if ($mockController === null)' . PHP_EOL .3977 "\t\t" . '{' . PHP_EOL .3978 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .3979 "\t\t" . '}' . PHP_EOL .3980 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .3981 "\t\t" . '{' . PHP_EOL .3982 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .3983 "\t\t" . '}' . PHP_EOL .3984 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .3985 "\t\t" . '{' . PHP_EOL .3986 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .3987 "\t\t" . '}' . PHP_EOL .3988 "\t" . '}' . PHP_EOL .3989 "\t" . 'public function ' . $methodName . '(): \\' . $realClass . PHP_EOL .3990 "\t" . '{' . PHP_EOL .3991 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .3992 "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL .3993 "\t\t" . '{' . PHP_EOL .3994 "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL .3995 "\t\t\t" . 'return $return;' . PHP_EOL .3996 "\t\t" . '}' . PHP_EOL .3997 "\t\t" . 'else' . PHP_EOL .3998 "\t\t" . '{' . PHP_EOL .3999 "\t\t\t" . '$this->getMockController()->addCall(\'' . $methodName . '\', $arguments);' . PHP_EOL .4000 "\t\t\t" . '$return = call_user_func_array(\'parent::' . $methodName . '\', $arguments);' . PHP_EOL .4001 "\t\t\t" . 'return $return;' . PHP_EOL .4002 "\t\t" . '}' . PHP_EOL .4003 "\t" . '}' . PHP_EOL .4004 "\t" . 'public static function getMockedMethods()' . PHP_EOL .4005 "\t" . '{' . PHP_EOL .4006 "\t\t" . 'return ' . var_export(['__construct', strtolower($methodName)], true) . ';' . PHP_EOL .4007 "\t" . '}' . PHP_EOL .4008 '}' . PHP_EOL .4009 '}'4010 )4011 ;4012 }4013 public function testGenerateWithEachInstanceIsUnique()4014 {4015 $this4016 ->if($generator = new testedClass())4017 ->and($generator->eachInstanceIsUnique())4018 ->then4019 ->string($generator->getMockedClassCode(__NAMESPACE__ . '\mockable'))->isEqualTo(4020 'namespace mock\\' . __NAMESPACE__ . ' {' . PHP_EOL .4021 'final class mockable extends \\' . __NAMESPACE__ . '\mockable implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .4022 '{' . PHP_EOL .4023 $this->getMockControllerMethods() .4024 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .4025 "\t" . '{' . PHP_EOL .4026 "\t\t" . '$this->{\'mock\' . uniqid()} = true;' . PHP_EOL .4027 "\t\t" . 'if ($mockController === null)' . PHP_EOL .4028 "\t\t" . '{' . PHP_EOL .4029 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .4030 "\t\t" . '}' . PHP_EOL .4031 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .4032 "\t\t" . '{' . PHP_EOL .4033 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .4034 "\t\t" . '}' . PHP_EOL .4035 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .4036 "\t\t" . '{' . PHP_EOL .4037 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .4038 "\t\t" . '}' . PHP_EOL .4039 "\t" . '}' . PHP_EOL .4040 "\t" . 'public static function getMockedMethods()' . PHP_EOL .4041 "\t" . '{' . PHP_EOL .4042 "\t\t" . 'return ' . var_export(['__construct'], true) . ';' . PHP_EOL .4043 "\t" . '}' . PHP_EOL .4044 '}' . PHP_EOL .4045 '}'4046 )4047 ;4048 }4049 /** @php >= 7.0 */4050 public function testGenerateUsingStrictTypes()4051 {4052 $this4053 ->if($generator = new testedClass())4054 ->and($generator->useStrictTypes())4055 ->then4056 ->string($generator->getMockedClassCode(__NAMESPACE__ . '\classWithScalarTypeHints'))->isEqualTo(4057 'declare(strict_types=1);' . PHP_EOL .4058 'namespace mock\\' . __NAMESPACE__ . ' {' . PHP_EOL .4059 'final class classWithScalarTypeHints extends \\' . __NAMESPACE__ . '\classWithScalarTypeHints implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .4060 '{' . PHP_EOL .4061 $this->getMockControllerMethods() .4062 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .4063 "\t" . '{' . PHP_EOL .4064 "\t\t" . 'if ($mockController === null)' . PHP_EOL .4065 "\t\t" . '{' . PHP_EOL .4066 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .4067 "\t\t" . '}' . PHP_EOL .4068 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .4069 "\t\t" . '{' . PHP_EOL .4070 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .4071 "\t\t" . '}' . PHP_EOL .4072 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .4073 "\t\t" . '{' . PHP_EOL .4074 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .4075 "\t\t" . '}' . PHP_EOL .4076 "\t" . '}' . PHP_EOL .4077 "\t" . 'public function foo(int $bar): int' . PHP_EOL .4078 "\t" . '{' . PHP_EOL .4079 "\t\t" . '$arguments = array_merge(array($bar), array_slice(func_get_args(), 1));' . PHP_EOL .4080 "\t\t" . 'if (isset($this->getMockController()->foo) === true)' . PHP_EOL .4081 "\t\t" . '{' . PHP_EOL .4082 "\t\t\t" . '$return = $this->getMockController()->invoke(\'foo\', $arguments);' . PHP_EOL .4083 "\t\t\t" . 'return $return;' . PHP_EOL .4084 "\t\t" . '}' . PHP_EOL .4085 "\t\t" . 'else' . PHP_EOL .4086 "\t\t" . '{' . PHP_EOL .4087 "\t\t\t" . '$this->getMockController()->addCall(\'foo\', $arguments);' . PHP_EOL .4088 "\t\t\t" . '$return = call_user_func_array(\'parent::foo\', $arguments);' . PHP_EOL .4089 "\t\t\t" . 'return $return;' . PHP_EOL .4090 "\t\t" . '}' . PHP_EOL .4091 "\t" . '}' . PHP_EOL .4092 "\t" . 'public static function getMockedMethods()' . PHP_EOL .4093 "\t" . '{' . PHP_EOL .4094 "\t\t" . 'return ' . var_export(['__construct', 'foo'], true) . ';' . PHP_EOL .4095 "\t" . '}' . PHP_EOL .4096 '}' . PHP_EOL .4097 '}'4098 )4099 ;4100 }4101 protected function getMockControllerMethods()4102 {4103 return4104 "\t" . 'public function getMockController()' . PHP_EOL .4105 "\t" . '{' . PHP_EOL .4106 "\t\t" . '$mockController = \mageekguy\atoum\mock\controller::getForMock($this);' . PHP_EOL .4107 "\t\t" . 'if ($mockController === null)' . PHP_EOL .4108 "\t\t" . '{' . PHP_EOL .4109 "\t\t\t" . '$this->setMockController($mockController = new \mageekguy\atoum\mock\controller());' . PHP_EOL .4110 "\t\t" . '}' . PHP_EOL .4111 "\t\t" . 'return $mockController;' . PHP_EOL .4112 "\t" . '}' . PHP_EOL .4113 "\t" . 'public function setMockController(\mageekguy\atoum\mock\controller $controller)' . PHP_EOL .4114 "\t" . '{' . PHP_EOL .4115 "\t\t" . 'return $controller->control($this);' . PHP_EOL .4116 "\t" . '}' . PHP_EOL .4117 "\t" . 'public function resetMockController()' . PHP_EOL .4118 "\t" . '{' . PHP_EOL .4119 "\t\t" . '\mageekguy\atoum\mock\controller::getForMock($this)->reset();' . PHP_EOL .4120 "\t\t" . 'return $this;' . PHP_EOL .4121 "\t" . '}' . PHP_EOL4122 ;4123 }4124 protected function testMethodIsMockableWithReservedWordDataProvider()4125 {4126 # See http://www.php.net/manual/en/reserved.keywords.php4127 return [4128 '__halt_compiler',4129 'abstract',4130 'and',4131 'array',4132 'as',4133 'break',4134 'callable',4135 'case',4136 'catch',4137 'class',4138 'clone',4139 'const',4140 'continue',4141 'declare',4142 'default',4143 'die',4144 'do',4145 'echo',4146 'else',4147 'elseif',4148 'empty',4149 'enddeclare',4150 'endfor',4151 'endforeach',4152 'endif',4153 'endswitch',4154 'endwhile',4155 'eval',4156 'exit',4157 'extends',4158 'final',4159 'for',4160 'foreach',4161 'function',4162 'global',4163 'goto',4164 'if',4165 'implements',4166 'include',4167 'include_once',4168 'instanceof',4169 'insteadof',4170 'interface',4171 'isset',4172 'list',4173 'namespace',4174 'new',4175 'or',4176 'print',4177 'private',4178 'protected',4179 'public',4180 'require',4181 'require_once',4182 'return',4183 'static',4184 'switch',4185 'throw',4186 'trait',4187 'try',4188 'unset',4189 'use',4190 'var',4191 'while',4192 'xor'4193 ];4194 }4195 protected function testMethodIsMockableWithReservedWordPHP7DataProvider()4196 {4197 # See http://www.php.net/manual/en/reserved.keywords.php4198 return [4199 '__halt_compiler',4200 ];4201 }4202}4203class mockable4204{4205}4206if (version_compare(PHP_VERSION, '5.6.0', '>=')) {4207 eval('4208 namespace ' . __NAMESPACE__ . ';4209 class foo4210 {4211 }4212 class classWithVariadicInConstructor4213 {4214 public function __construct(foo... $foo)4215 {4216 }4217 }4218 ');4219}4220if (version_compare(PHP_VERSION, '7.0.0', '>=')) {4221 eval('4222 namespace ' . __NAMESPACE__ . ';4223 4224 class classWithScalarTypeHints4225 {4226 public function foo(int $bar) : int 4227 {4228 return $bar * 2;...
Controller.php
Source:Controller.php
1<?php2class Controller {3 var $model; 4 var $view; 5 function __construct (& $data) {6 $this->model=& new Model($data);7 }8 function getView() { 9 return $this->view;10 }11}12class table1Controller extends Controller{13 function __construct (& $data){14 parent::__construct($data);15 $details=$this->model->getdetail();16 $this->view= & new Table1View($details);17 }18}19class table2Controller extends Controller{20 function __construct (& $data){21 parent::__construct($data);22 $this->view= & new Table2View();23 }24}25class printController extends Controller{ 26 function __construct (& $data) {27 parent::__construct($data);28 $details=$this->model->getdetail();29 $products=$this->model->printTable();30 $this->view=& new printView($products,$details);31 }32}33class printdetailController extends Controller{ 34 function __construct (& $data) {35 parent::__construct($data);36 $details=$this->model->getdetail();37 $this->view=& new printdetailView($details);38 }39}40class updateController extends Controller{41 function __construct (& $data){42 parent::__construct($data);43 if ($this->model->updateProduct()) $success=1;44 else $success=0;45 $this->view=& new updateView($success);46 }47}48class updatedetailController extends Controller{49 function __construct (& $data){50 parent::__construct($data);51 if ($this->model->updateDetail()) $success=1;52 else $success=0;53 $this->view=& new updateDetailView($success);54 }55}56class addController extends Controller{57 function __construct (& $data) {58 parent::__construct($data);59 if ($this->model->addProduct()) $success=1;60 else $success=0;61 $this->view=& new addView($success);62 }63}64class add_detailController extends Controller{65 function __construct (& $data){66 parent::__construct($data);67 if ($this->model->add_detail()) $success=1;68 else $success=0;69 $this->view=& new add_detailView($success);70 }71}72class deleteController extends Controller{73 function __construct (& $data) {74 parent::__construct($data);75 if ($this->model->deleteProduct()) $success=1;76 else $success=0;77 $this->view=& new deleteView($success);78 }79}80class submanagementController extends Controller{81 function __construct (& $data){82 parent::__construct($data);83 $sub = $this->model->getsub();84 $this->view=& new submanagementView($sub);85 }86}87class updatesubController extends Controller{88 function __construct (& $data){89 parent::__construct($data);90 if ($this->model->updatesub()) $success=1;91 else $success=0;92 $this->view=& new updatesubView($success);93 }94}95class addsubController extends Controller{96 function __construct (& $data){97 parent::__construct($data);98 $this->model->addsub();99 $sub = $this->model->getsub();100 $this->view=& new submanagementView($sub);101 }102}103class addempController extends Controller{104 function __construct (& $data){105 parent::__construct($data);106 $error="";107 $this->view = & new addempView($error);108 }109}110class registempController extends Controller{111 function __construct (& $data){112 parent::__construct($data);113 $error=$this->model->registemp();114 if ($error == "")115 $this->view=& new registedempView();116 else{117 $this->view= & new addempView($error);118 }119 }120}121class modifyacctController extends Controller{122 function __construct (& $data){123 parent::__construct($data);124 $error="";125 $this->view = & new searchacctView($error);126 }127}128class rentalcontrolController extends Controller{129 function __construct (& $data){130 parent::__construct($data);131 $error="";132 $this->view = & new searchrentView($error);133 }134}135class empinfoController extends Controller{136 function __construct (& $data){137 parent::__construct($data);138 $email=$_SESSION['Email'];139 $user = $this->model->get_emp($email);140 $this->view = & new EMPView($user);141 }142}143class tradeinmanagementController extends Controller{144 function __construct (& $data){145 parent::__construct($data);146 $trades = $this->model->get_opentrades();147 $this->view = & new tradelistView($trades);148 }149}150class updatetradeController extends Controller{151 function __construct (& $data){152 parent::__construct($data);153 $success= $this->model->update_trades();154 $this->view = & new updatetradeView($success);155 }156}157class denytradeController extends Controller{158 function __construct (& $data){159 parent::__construct($data);160 $success=$this->model->deny_trades();161 $this->view = & new denytradeView($success);162 }163}164class tradelistController extends Controller{165 function __construct (& $data){166 parent::__construct($data);167 $trades=$this->model->get_trades();168 $this->view = & new tradeView($trades);169 }170}171class panelController extends Controller{172 function __construct (& $data){173 parent::__construct($data);174 $this->view = & new panelView();175 }176}177?>...
__construct
Using AI Code Generation
1$obj = new Controller();2$obj->index();3$obj = new Model();4$obj->index();5$obj = new View();6$obj->index();7$obj = new Anyclass();8$obj->index();
__construct
Using AI Code Generation
1$this->load->controller('controllerName');2$this->load->model('modelName');3$this->load->controller('controllerName');4$this->load->model('modelName');5$this->load->controller('controllerName');6$this->load->model('modelName');7$this->load->controller('controllerName');8$this->load->model('modelName');9$this->load->controller('controllerName');10$this->load->model('modelName');11$this->load->controller('controllerName');12$this->load->model('modelName');13$this->load->controller('controllerName');14$this->load->model('modelName');15$this->load->controller('controllerName');16$this->load->model('modelName');17$this->load->controller('controllerName');18$this->load->model('modelName');19$this->load->controller('controllerName');20$this->load->model('modelName');21$this->load->controller('controllerName');22$this->load->model('modelName');
__construct
Using AI Code Generation
1{2 public function __construct()3 {4 echo "I am in controller class";5 }6}7{8 public function __construct()9 {10 echo "I am in model class";11 }12}13{14 public function __construct()15 {16 echo "I am in view class";17 }18}19{20 public function __construct()21 {22 $this->controller = new controller();23 $this->model = new model();24 $this->view = new view();25 }26}27$obj = new main();28{29 public function __construct()30 {31 echo "I am in controller class";32 }33}34{35 public function __construct()36 {37 echo "I am in model class";38 }39}40{41 public function __construct()42 {43 echo "I am in view class";44 }45}46{47 public function __construct()48 {49 $this->controller = new controller();50 $this->model = new model();51 $this->view = new view();52 }53}54$obj = new main();55{56 public function __construct()57 {58 echo "I am in controller class";59 }60}61{62 public function __construct()63 {64 echo "I am in model class";65 }66}67{68 public function __construct()69 {70 echo "I am in view class";71 }72}73{74 public function __construct()75 {76 $this->controller = new controller();77 $this->model = new model();78 $this->view = new view();79 }80}81$obj = new main();82{83 public function __construct()84 {85 echo "I am in controller class";86 }87}88{89 public function __construct()90 {91 echo "I am in model class";92 }93}94{95 public function __construct()96 {97 echo "I am in view class";98 }99}100{101 public function __construct()102 {
__construct
Using AI Code Generation
1{2 public function __construct()3 {4 echo 'This is a constructor method of controller class';5 }6}7{8 public function __construct()9 {10 parent::__construct();11 echo 'This is a constructor method of home class';12 }13}14$home = new home();15Related Posts: PHP - __destruct() method16PHP - __get() method17PHP - __set() method18PHP - __isset() method19PHP - __unset() method20PHP - __call() method21PHP - __callStatic() method22PHP - __clone() method23PHP - __invoke() method24PHP - __sleep() method25PHP - __wakeup() method26PHP - __toString() method27PHP - __debugInfo() method28PHP - __set_state() method
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with __construct on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!