How to use __construct method of mock class

Best Atoum code snippet using mock.__construct

generator.php

Source:generator.php Github

copy

Full Screen

...8;9require_once __DIR__ . '/../../runner.php';10class generator extends atoum\test11{12 public function test__construct()13 {14 $this15 ->if($generator = new testedClass())16 ->then17 ->object($generator->getAdapter())->isEqualTo(new atoum\adapter())18 ->boolean($generator->callsToParentClassAreShunted())->isFalse()19 ;20 }21 public function testSetAdapter()22 {23 $this24 ->if($generator = new testedClass())25 ->then26 ->object($generator->setAdapter($adapter = new atoum\adapter()))->isIdenticalTo($generator)27 ->object($generator->getAdapter())->isIdenticalTo($adapter)28 ->object($generator->setAdapter())->isIdenticalTo($generator)29 ->object($generator->getAdapter())30 ->isInstanceOf('mageekguy\atoum\adapter')31 ->isNotIdenticalTo($adapter)32 ->isEqualTo(new atoum\adapter())33 ;34 }35 public function testSetReflectionClassFactory()36 {37 $this38 ->if($generator = new testedClass())39 ->then40 ->object($generator->setReflectionClassFactory($factory = function() {}))->isIdenticalTo($generator)41 ->object($generator->getReflectionClassFactory())->isIdenticalTo($factory)42 ->object($generator->setReflectionClassFactory())->isIdenticalTo($generator)43 ->object($defaultReflectionClassFactory = $generator->getReflectionClassFactory())44 ->isInstanceOf('closure')45 ->isNotIdenticalTo($factory)46 ->object($defaultReflectionClassFactory($this))->isEqualTo(new \reflectionClass($this))47 ;48 }49 public function testGetMethod()50 {51 $this52 ->if($generator = new testedClass())53 ->then54 ->object($generator->getMethod())->isEqualTo(new mock\generator\method($generator))55 ;56 }57 public function testSetDefaultNamespace()58 {59 $this60 ->if($generator = new testedClass())61 ->then62 ->object($generator->setDefaultNamespace($namespace = uniqid()))->isIdenticalTo($generator)63 ->string($generator->getDefaultNamespace())->isEqualTo('\\' . $namespace)64 ->object($generator->setDefaultNamespace('\\' . $namespace))->isIdenticalTo($generator)65 ->string($generator->getDefaultNamespace())->isEqualTo('\\' . $namespace)66 ->object($generator->setDefaultNamespace('\\' . $namespace . '\\'))->isIdenticalTo($generator)67 ->string($generator->getDefaultNamespace())->isEqualTo('\\' . $namespace)68 ->object($generator->setDefaultNamespace($namespace . '\\'))->isIdenticalTo($generator)69 ->string($generator->getDefaultNamespace())->isEqualTo('\\' . $namespace)70 ;71 }72 public function testShuntCallsToParentClass()73 {74 $this75 ->if($generator = new testedClass())76 ->then77 ->object($generator->shuntParentClassCalls())->isIdenticalTo($generator)78 ->boolean($generator->callsToParentClassAreShunted())->isTrue()79 ;80 }81 public function testUnshuntParentClassCalls()82 {83 $this84 ->if($generator = new testedClass())85 ->then86 ->object($generator->unshuntParentClassCalls())->isIdenticalTo($generator)87 ->boolean($generator->callsToParentClassAreShunted())->isFalse()88 ->if($generator->shuntParentClassCalls())89 ->then90 ->object($generator->unshuntParentClassCalls())->isIdenticalTo($generator)91 ->boolean($generator->callsToParentClassAreShunted())->isFalse()92 ;93 }94 public function testOverload()95 {96 $this97 ->if($generator = new testedClass())98 ->then99 ->object($generator->overload(new mock\php\method($method = uniqid())))->isIdenticalTo($generator)100 ->boolean($generator->isOverloaded($method))->isTrue()101 ;102 }103 public function testIsOverloaded()104 {105 $this106 ->if($generator = new testedClass())107 ->then108 ->boolean($generator->isOverloaded(uniqid()))->isFalse()109 ->if($generator->overload(new mock\php\method($method = uniqid())))110 ->then111 ->boolean($generator->isOverloaded($method))->isTrue()112 ;113 }114 public function testGetOverload()115 {116 $this117 ->if($generator = new testedClass())118 ->then119 ->variable($generator->getOverload(uniqid()))->isNull()120 ->if($generator->overload($overload = new mock\php\method(uniqid())))121 ->then122 ->object($generator->getOverload($overload->getName()))->isIdenticalTo($overload)123 ;124 }125 public function testShunt()126 {127 $this128 ->if($generator = new testedClass())129 ->then130 ->object($generator->shunt($method = uniqid()))->isIdenticalTo($generator)131 ->boolean($generator->isShunted($method))->isTrue()132 ->boolean($generator->isShunted(strtoupper($method)))->isTrue()133 ->boolean($generator->isShunted(strtolower($method)))->isTrue()134 ->boolean($generator->isShunted(uniqid()))->isFalse()135 ;136 }137 public function testOrphanize()138 {139 $this140 ->if($generator = new testedClass())141 ->then142 ->object($generator->orphanize($method = uniqid()))->isIdenticalTo($generator)143 ->boolean($generator->isOrphanized($method))->isTrue()144 ->boolean($generator->isShunted($method))->isTrue()145 ;146 }147 public function testGetMockedClassCodeForUnknownClass()148 {149 $this150 ->if($generator = new testedClass())151 ->and($adapter = new atoum\test\adapter())152 ->and($adapter->class_exists = false)153 ->and($generator->setAdapter($adapter))154 ->then155 ->string($generator->getMockedClassCode($unknownClass = uniqid()))->isEqualTo(156 'namespace mock {' . PHP_EOL .157 'final class ' . $unknownClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .158 '{' . PHP_EOL .159 $this->getMockControllerMethods() .160 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .161 "\t" . '{' . PHP_EOL .162 "\t\t" . 'if ($mockController === null)' . PHP_EOL .163 "\t\t" . '{' . PHP_EOL .164 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .165 "\t\t" . '}' . PHP_EOL .166 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .167 "\t\t" . '{' . PHP_EOL .168 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .169 "\t\t" . '}' . PHP_EOL .170 "\t\t" . '$this->getMockController()->disableMethodChecking();' . PHP_EOL .171 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .172 "\t\t" . '{' . PHP_EOL .173 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .174 "\t\t" . '}' . PHP_EOL .175 "\t" . '}' . PHP_EOL .176 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .177 "\t" . '{' . PHP_EOL .178 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .179 "\t\t" . '{' . PHP_EOL .180 "\t\t\t" . 'return $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .181 "\t\t" . '}' . PHP_EOL .182 "\t\t" . 'else' . PHP_EOL .183 "\t\t" . '{' . PHP_EOL .184 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .185 "\t\t" . '}' . PHP_EOL .186 "\t" . '}' . PHP_EOL .187 "\t" . 'public static function getMockedMethods()' . PHP_EOL .188 "\t" . '{' . PHP_EOL .189 "\t\t" . 'return ' . var_export(array('__call'), true) . ';' . PHP_EOL .190 "\t" . '}' . PHP_EOL .191 '}' . PHP_EOL .192 '}'193 )194 ->if($unknownClass = __NAMESPACE__ . '\dummy')195 ->and($generator->generate($unknownClass))196 ->and($mockedUnknownClass = '\mock\\' . $unknownClass)197 ->and($dummy = new $mockedUnknownClass())198 ->and($dummyController = new atoum\mock\controller())199 ->and($dummyController->notControlNextNewMock())200 ->and($calls = new \mock\mageekguy\atoum\test\adapter\calls())201 ->and($dummyController->setCalls($calls))202 ->and($dummyController->control($dummy))203 ->then204 ->when(function() use ($dummy) { $dummy->bar(); })205 ->mock($calls)->call('addCall')->withArguments(new atoum\test\adapter\call('bar', array(), new decorators\addClass($dummy)))->once()206 ->when(function() use ($dummy) { $dummy->bar(); })207 ->mock($calls)->call('addCall')->withArguments(new atoum\test\adapter\call('bar', array(), new decorators\addClass($dummy)))->twice()208 ;209 }210 public function testGetMockedClassCodeForRealClass()211 {212 $this213 ->if($generator = new testedClass())214 ->and($reflectionMethodController = new mock\controller())215 ->and($reflectionMethodController->__construct = function() {})216 ->and($reflectionMethodController->getName = '__construct')217 ->and($reflectionMethodController->isConstructor = true)218 ->and($reflectionMethodController->getParameters = array())219 ->and($reflectionMethodController->isPublic = true)220 ->and($reflectionMethodController->isProtected = false)221 ->and($reflectionMethodController->isPrivate = false)222 ->and($reflectionMethodController->isFinal = false)223 ->and($reflectionMethodController->isStatic = false)224 ->and($reflectionMethodController->isAbstract = false)225 ->and($reflectionMethodController->returnsReference = false)226 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))227 ->and($reflectionClassController = new mock\controller())228 ->and($reflectionClassController->__construct = function() {})229 ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })230 ->and($reflectionClassController->isFinal = false)231 ->and($reflectionClassController->isInterface = false)232 ->and($reflectionClassController->isAbstract = false)233 ->and($reflectionClassController->getMethods = array($reflectionMethod))234 ->and($reflectionClassController->getConstructor = $reflectionMethod)235 ->and($reflectionClass = new \mock\reflectionClass(null))236 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))237 ->and($adapter = new atoum\test\adapter())238 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })239 ->and($generator->setAdapter($adapter))240 ->then241 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(242 'namespace mock {' . PHP_EOL .243 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .244 '{' . PHP_EOL .245 $this->getMockControllerMethods() .246 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .247 "\t" . '{' . PHP_EOL .248 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .249 "\t\t" . 'if ($mockController === null)' . PHP_EOL .250 "\t\t" . '{' . PHP_EOL .251 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .252 "\t\t" . '}' . PHP_EOL .253 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .254 "\t\t" . '{' . PHP_EOL .255 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .256 "\t\t" . '}' . PHP_EOL .257 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .258 "\t\t" . '{' . PHP_EOL .259 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .260 "\t\t" . '}' . PHP_EOL .261 "\t\t" . 'else' . PHP_EOL .262 "\t\t" . '{' . PHP_EOL .263 "\t\t\t" . '$this->getMockController()->addCall(\'__construct\', $arguments);' . PHP_EOL .264 "\t\t\t" . 'call_user_func_array(\'parent::__construct\', $arguments);' . PHP_EOL .265 "\t\t" . '}' . PHP_EOL .266 "\t" . '}' . PHP_EOL .267 "\t" . 'public static function getMockedMethods()' . PHP_EOL .268 "\t" . '{' . PHP_EOL .269 "\t\t" . 'return ' . var_export(array('__construct'), true) . ';' . PHP_EOL .270 "\t" . '}' . PHP_EOL .271 '}' . PHP_EOL .272 '}'273 )274 ;275 }276 public function testGetMockedClassCodeForRealClassWithDeprecatedConstructor()277 {278 $this279 ->if($generator = new testedClass())280 ->and($reflectionMethodController = new mock\controller())281 ->and($reflectionMethodController->__construct = function() {})282 ->and($reflectionMethodController->getName = $realClass = uniqid())283 ->and($reflectionMethodController->isConstructor = true)284 ->and($reflectionMethodController->getParameters = array())285 ->and($reflectionMethodController->isPublic = true)286 ->and($reflectionMethodController->isProtected = false)287 ->and($reflectionMethodController->isPrivate = false)288 ->and($reflectionMethodController->isFinal = false)289 ->and($reflectionMethodController->isStatic = false)290 ->and($reflectionMethodController->isAbstract = false)291 ->and($reflectionMethodController->returnsReference = false)292 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))293 ->and($reflectionClassController = new mock\controller())294 ->and($reflectionClassController->__construct = function() {})295 ->and($reflectionClassController->getName = $realClass)296 ->and($reflectionClassController->isFinal = false)297 ->and($reflectionClassController->isInterface = false)298 ->and($reflectionClassController->isAbstract = false)299 ->and($reflectionClassController->getMethods = array($reflectionMethod))300 ->and($reflectionClassController->getConstructor = $reflectionMethod)301 ->and($reflectionClass = new \mock\reflectionClass(null))302 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))303 ->and($adapter = new atoum\test\adapter())304 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })305 ->and($generator->setAdapter($adapter))306 ->then307 ->string($generator->getMockedClassCode($realClass))->isEqualTo(308 'namespace mock {' . PHP_EOL .309 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .310 '{' . PHP_EOL .311 $this->getMockControllerMethods() .312 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .313 "\t" . '{' . PHP_EOL .314 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .315 "\t\t" . 'if ($mockController === null)' . PHP_EOL .316 "\t\t" . '{' . PHP_EOL .317 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .318 "\t\t" . '}' . PHP_EOL .319 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .320 "\t\t" . '{' . PHP_EOL .321 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .322 "\t\t" . '}' . PHP_EOL .323 "\t\t" . 'if (isset($this->getMockController()->' . $realClass . ') === true)' . PHP_EOL .324 "\t\t" . '{' . PHP_EOL .325 "\t\t\t" . '$this->getMockController()->invoke(\'' . $realClass . '\', $arguments);' . PHP_EOL .326 "\t\t" . '}' . PHP_EOL .327 "\t\t" . 'else' . PHP_EOL .328 "\t\t" . '{' . PHP_EOL .329 "\t\t\t" . '$this->getMockController()->addCall(\'' . $realClass . '\', $arguments);' . PHP_EOL .330 "\t\t\t" . 'call_user_func_array(\'parent::' . $realClass . '\', $arguments);' . PHP_EOL .331 "\t\t" . '}' . PHP_EOL .332 "\t" . '}' . PHP_EOL .333 "\t" . 'public static function getMockedMethods()' . PHP_EOL .334 "\t" . '{' . PHP_EOL .335 "\t\t" . 'return ' . var_export(array($realClass), true) . ';' . PHP_EOL .336 "\t" . '}' . PHP_EOL .337 '}' . PHP_EOL .338 '}'339 )340 ;341 }342 public function testGetMockedClassCodeForRealClassWithCallsToParentClassShunted()343 {344 $this345 ->if($generator = new testedClass())346 ->and($reflectionMethodController = new mock\controller())347 ->and($reflectionMethodController->__construct = function() {})348 ->and($reflectionMethodController->getName = '__construct')349 ->and($reflectionMethodController->isConstructor = true)350 ->and($reflectionMethodController->getParameters = array())351 ->and($reflectionMethodController->isPublic = true)352 ->and($reflectionMethodController->isProtected = false)353 ->and($reflectionMethodController->isPrivate = false)354 ->and($reflectionMethodController->isFinal = false)355 ->and($reflectionMethodController->isStatic = false)356 ->and($reflectionMethodController->isAbstract = false)357 ->and($reflectionMethodController->returnsReference = false)358 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))359 ->and($otherReflectionMethodController = new mock\controller())360 ->and($otherReflectionMethodController->__construct = function() {})361 ->and($otherReflectionMethodController->getName = $otherMethod = uniqid())362 ->and($otherReflectionMethodController->isConstructor = false)363 ->and($otherReflectionMethodController->getParameters = array())364 ->and($otherReflectionMethodController->isPublic = true)365 ->and($otherReflectionMethodController->isProtected = false)366 ->and($otherReflectionMethodController->isPrivate = false)367 ->and($otherReflectionMethodController->isFinal = false)368 ->and($otherReflectionMethodController->isStatic = false)369 ->and($otherReflectionMethodController->isAbstract = false)370 ->and($otherReflectionMethodController->returnsReference = false)371 ->and($otherReflectionMethod = new \mock\reflectionMethod(null, null))372 ->and($reflectionClassController = new mock\controller())373 ->and($reflectionClassController->__construct = function() {})374 ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })375 ->and($reflectionClassController->isFinal = false)376 ->and($reflectionClassController->isInterface = false)377 ->and($reflectionClassController->isAbstract = false)378 ->and($reflectionClassController->getMethods = array($reflectionMethod, $otherReflectionMethod))379 ->and($reflectionClassController->getConstructor = $reflectionMethod)380 ->and($reflectionClass = new \mock\reflectionClass(null))381 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))382 ->and($adapter = new atoum\test\adapter())383 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })384 ->and($generator->setAdapter($adapter))385 ->and($generator->shuntParentClassCalls())386 ->then387 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(388 'namespace mock {' . PHP_EOL .389 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .390 '{' . PHP_EOL .391 $this->getMockControllerMethods() .392 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .393 "\t" . '{' . PHP_EOL .394 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .395 "\t\t" . 'if ($mockController === null)' . PHP_EOL .396 "\t\t" . '{' . PHP_EOL .397 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .398 "\t\t" . '}' . PHP_EOL .399 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .400 "\t\t" . '{' . PHP_EOL .401 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .402 "\t\t" . '}' . PHP_EOL .403 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .404 "\t\t" . '{' . PHP_EOL .405 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .406 "\t\t" . '}' . PHP_EOL .407 "\t\t" . 'else' . PHP_EOL .408 "\t\t" . '{' . PHP_EOL .409 "\t\t\t" . '$this->getMockController()->addCall(\'__construct\', $arguments);' . PHP_EOL .410 "\t\t" . '}' . PHP_EOL .411 "\t" . '}' . PHP_EOL .412 "\t" . 'public function ' . $otherMethod . '()' . PHP_EOL .413 "\t" . '{' . PHP_EOL .414 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .415 "\t\t" . 'if (isset($this->getMockController()->' . $otherMethod . ') === true)' . PHP_EOL .416 "\t\t" . '{' . PHP_EOL .417 "\t\t\t" . 'return $this->getMockController()->invoke(\'' . $otherMethod . '\', $arguments);' . PHP_EOL .418 "\t\t" . '}' . PHP_EOL .419 "\t\t" . 'else' . PHP_EOL .420 "\t\t" . '{' . PHP_EOL .421 "\t\t\t" . '$this->getMockController()->addCall(\'' . $otherMethod . '\', $arguments);' . PHP_EOL .422 "\t\t" . '}' . PHP_EOL .423 "\t" . '}' . PHP_EOL .424 "\t" . 'public static function getMockedMethods()' . PHP_EOL .425 "\t" . '{' . PHP_EOL .426 "\t\t" . 'return ' . var_export(array('__construct', $otherMethod), true) . ';' . PHP_EOL .427 "\t" . '}' . PHP_EOL .428 '}' . PHP_EOL .429 '}'430 )431 ;432 }433 public function testGetMockedClassCodeWithOverloadMethod()434 {435 $this436 ->if($generator = new testedClass())437 ->and($reflectionMethodController = new mock\controller())438 ->and($reflectionMethodController->__construct = function() {})439 ->and($reflectionMethodController->getName = '__construct')440 ->and($reflectionMethodController->isConstructor = true)441 ->and($reflectionMethodController->getParameters = array())442 ->and($reflectionMethodController->isPublic = true)443 ->and($reflectionMethodController->isProtected = false)444 ->and($reflectionMethodController->isPrivate = false)445 ->and($reflectionMethodController->isFinal = false)446 ->and($reflectionMethodController->isAbstract = false)447 ->and($reflectionMethodController->isStatic = false)448 ->and($reflectionMethodController->returnsReference = false)449 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))450 ->and($reflectionClassController = new mock\controller())451 ->and($reflectionClassController->__construct = function() {})452 ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })453 ->and($reflectionClassController->isFinal = false)454 ->and($reflectionClassController->isInterface = false)455 ->and($reflectionClassController->getMethods = array($reflectionMethod))456 ->and($reflectionClassController->getConstructor = $reflectionMethod)457 ->and($reflectionClassController->isAbstract = false)458 ->and($reflectionClass = new \mock\reflectionClass(null))459 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))460 ->and($adapter = new atoum\test\adapter())461 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })462 ->and($generator->setAdapter($adapter))463 ->and($overloadedMethod = new mock\php\method('__construct'))464 ->and($overloadedMethod->addArgument($argument = new mock\php\method\argument(uniqid())))465 ->and($generator->overload($overloadedMethod))466 ->then467 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(468 'namespace mock {' . PHP_EOL .469 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .470 '{' . PHP_EOL .471 $this->getMockControllerMethods() .472 "\t" . '' . $overloadedMethod . PHP_EOL .473 "\t" . '{' . PHP_EOL .474 "\t\t" . '$arguments = array_merge(array(' . $argument . '), array_slice(func_get_args(), 1, -1));' . PHP_EOL .475 "\t\t" . 'if ($mockController === null)' . PHP_EOL .476 "\t\t" . '{' . PHP_EOL .477 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .478 "\t\t" . '}' . PHP_EOL .479 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .480 "\t\t" . '{' . PHP_EOL .481 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .482 "\t\t" . '}' . PHP_EOL .483 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .484 "\t\t" . '{' . PHP_EOL .485 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .486 "\t\t" . '}' . PHP_EOL .487 "\t\t" . 'else' . PHP_EOL .488 "\t\t" . '{' . PHP_EOL .489 "\t\t\t" . '$this->getMockController()->addCall(\'__construct\', $arguments);' . PHP_EOL .490 "\t\t\t" . 'call_user_func_array(\'parent::__construct\', $arguments);' . PHP_EOL .491 "\t\t" . '}' . PHP_EOL .492 "\t" . '}' . PHP_EOL .493 "\t" . 'public static function getMockedMethods()' . PHP_EOL .494 "\t" . '{' . PHP_EOL .495 "\t\t" . 'return ' . var_export(array('__construct'), true) . ';' . PHP_EOL .496 "\t" . '}' . PHP_EOL .497 '}' . PHP_EOL .498 '}'499 )500 ;501 }502 public function testGetMockedClassCodeWithAbstractMethod()503 {504 $this505 ->if($generator = new testedClass())506 ->and($realClass = uniqid())507 ->and($reflectionMethodController = new mock\controller())508 ->and($reflectionMethodController->__construct = function() {})509 ->and($reflectionMethodController->getName = function() { return '__construct'; })510 ->and($reflectionMethodController->isConstructor = true)511 ->and($reflectionMethodController->getParameters = array())512 ->and($reflectionMethodController->isPublic = true)513 ->and($reflectionMethodController->isProtected = false)514 ->and($reflectionMethodController->isPrivate = false)515 ->and($reflectionMethodController->isFinal = false)516 ->and($reflectionMethodController->isStatic = false)517 ->and($reflectionMethodController->isAbstract = true)518 ->and($reflectionMethodController->returnsReference = false)519 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))520 ->and($reflectionClassController = new mock\controller())521 ->and($reflectionClassController->__construct = function() {})522 ->and($reflectionClassController->getName = function() use ($realClass) { return $realClass; })523 ->and($reflectionClassController->isFinal = false)524 ->and($reflectionClassController->isInterface = false)525 ->and($reflectionClassController->getMethods = array($reflectionMethod))526 ->and($reflectionClassController->getConstructor = $reflectionMethod)527 ->and($reflectionClassController->isAbstract = false)528 ->and($reflectionClass = new \mock\reflectionClass(null))529 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))530 ->and($adapter = new atoum\test\adapter())531 ->and($adapter->class_exists = function($class) use ($realClass) { return ($class == '\\' . $realClass); })532 ->and($generator->setAdapter($adapter))533 ->then534 ->string($generator->getMockedClassCode($realClass))->isEqualTo(535 'namespace mock {' . PHP_EOL .536 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .537 '{' . PHP_EOL .538 $this->getMockControllerMethods() .539 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .540 "\t" . '{' . PHP_EOL .541 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .542 "\t\t" . 'if ($mockController === null)' . PHP_EOL .543 "\t\t" . '{' . PHP_EOL .544 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .545 "\t\t" . '}' . PHP_EOL .546 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .547 "\t\t" . '{' . PHP_EOL .548 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .549 "\t\t" . '}' . PHP_EOL .550 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .551 "\t\t" . '{' . PHP_EOL .552 "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .553 "\t\t" . '}' . PHP_EOL .554 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .555 "\t" . '}' . PHP_EOL .556 "\t" . 'public static function getMockedMethods()' . PHP_EOL .557 "\t" . '{' . PHP_EOL .558 "\t\t" . 'return ' . var_export(array('__construct'), true) . ';' . PHP_EOL .559 "\t" . '}' . PHP_EOL .560 '}' . PHP_EOL .561 '}'562 )563 ;564 }565 public function testGetMockedClassCodeWithShuntedMethod()566 {567 $this568 ->if($generator = new testedClass())569 ->and($realClass = uniqid())570 ->and($reflectionMethodController = new mock\controller())571 ->and($reflectionMethodController->__construct = function() {})572 ->and($reflectionMethodController->getName = function() { return '__construct'; })573 ->and($reflectionMethodController->isConstructor = true)574 ->and($reflectionMethodController->isAbstract = false)575 ->and($reflectionMethodController->getParameters = array())576 ->and($reflectionMethodController->isPublic = true)577 ->and($reflectionMethodController->isProtected = false)578 ->and($reflectionMethodController->isPrivate = false)579 ->and($reflectionMethodController->isFinal = false)580 ->and($reflectionMethodController->isStatic = false)581 ->and($reflectionMethodController->returnsReference = false)582 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))583 ->and($reflectionClassController = new mock\controller())584 ->and($reflectionClassController->__construct = function() {})585 ->and($reflectionClassController->getName = function() use ($realClass) { return $realClass; })586 ->and($reflectionClassController->isFinal = false)587 ->and($reflectionClassController->isInterface = false)588 ->and($reflectionClassController->getMethods = array($reflectionMethod))589 ->and($reflectionClassController->getConstructor = $reflectionMethod)590 ->and($reflectionClassController->isAbstract = false)591 ->and($reflectionClass = new \mock\reflectionClass(null))592 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))593 ->and($adapter = new atoum\test\adapter())594 ->and($adapter->class_exists = function($class) use ($realClass) { return ($class == '\\' . $realClass); })595 ->and($generator->setAdapter($adapter))596 ->and($generator->shunt('__construct'))597 ->then598 ->string($generator->getMockedClassCode($realClass))->isEqualTo(599 'namespace mock {' . PHP_EOL .600 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .601 '{' . PHP_EOL .602 $this->getMockControllerMethods() .603 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .604 "\t" . '{' . PHP_EOL .605 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .606 "\t\t" . 'if ($mockController === null)' . PHP_EOL .607 "\t\t" . '{' . PHP_EOL .608 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .609 "\t\t" . '}' . PHP_EOL .610 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .611 "\t\t" . '{' . PHP_EOL .612 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .613 "\t\t" . '}' . PHP_EOL .614 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .615 "\t\t" . '{' . PHP_EOL .616 "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .617 "\t\t" . '}' . PHP_EOL .618 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .619 "\t" . '}' . PHP_EOL .620 "\t" . 'public static function getMockedMethods()' . PHP_EOL .621 "\t" . '{' . PHP_EOL .622 "\t\t" . 'return ' . var_export(array('__construct'), true) . ';' . PHP_EOL .623 "\t" . '}' . PHP_EOL .624 '}' . PHP_EOL .625 '}'626 )627 ;628 }629 public function testGetMockedClassCodeWithCloneMethod()630 {631 $this632 ->if($generator = new testedClass())633 ->and($realClass = uniqid())634 ->and($reflectionMethodController = new mock\controller())635 ->and($reflectionMethodController->__construct = function() {})636 ->and($reflectionMethodController->getName = 'clone')637 ->and($reflectionMethodController->isConstructor = false)638 ->and($reflectionMethodController->isAbstract = false)639 ->and($reflectionMethodController->getParameters = array())640 ->and($reflectionMethodController->isPublic = true)641 ->and($reflectionMethodController->isProtected = false)642 ->and($reflectionMethodController->isPrivate = false)643 ->and($reflectionMethodController->isFinal = false)644 ->and($reflectionMethodController->isStatic = false)645 ->and($reflectionMethodController->returnsReference = false)646 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))647 ->and($reflectionClassController = new mock\controller())648 ->and($reflectionClassController->__construct = function() {})649 ->and($reflectionClassController->getName = $realClass)650 ->and($reflectionClassController->isFinal = false)651 ->and($reflectionClassController->isInterface = false)652 ->and($reflectionClassController->getMethods = array($reflectionMethod))653 ->and($reflectionClassController->getConstructor = null)654 ->and($reflectionClassController->isAbstract = false)655 ->and($reflectionClass = new \mock\reflectionClass(null))656 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))657 ->and($adapter = new atoum\test\adapter())658 ->and($adapter->class_exists = function($class) use ($realClass) { return ($class == '\\' . $realClass); })659 ->and($generator->setAdapter($adapter))660 ->then661 ->string($generator->getMockedClassCode($realClass))->isEqualTo(662 'namespace mock {' . PHP_EOL .663 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .664 '{' . PHP_EOL .665 $this->getMockControllerMethods() .666 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .667 "\t" . '{' . PHP_EOL .668 "\t\t" . 'if ($mockController === null)' . PHP_EOL .669 "\t\t" . '{' . PHP_EOL .670 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .671 "\t\t" . '}' . PHP_EOL .672 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .673 "\t\t" . '{' . PHP_EOL .674 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .675 "\t\t" . '}' . PHP_EOL .676 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .677 "\t\t" . '{' . PHP_EOL .678 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .679 "\t\t" . '}' . PHP_EOL .680 "\t" . '}' . PHP_EOL .681 "\t" . 'public static function getMockedMethods()' . PHP_EOL .682 "\t" . '{' . PHP_EOL .683 "\t\t" . 'return ' . var_export(array('__construct'), true) . ';' . PHP_EOL .684 "\t" . '}' . PHP_EOL .685 '}' . PHP_EOL .686 '}'687 )688 ;689 }690 public function testGetMockedClassCodeWithShuntedDeprecatedConstructor()691 {692 $this693 ->if($generator = new testedClass())694 ->and($reflectionMethodController = new mock\controller())695 ->and($reflectionMethodController->__construct = function() {})696 ->and($reflectionMethodController->getName = $realClass = uniqid())697 ->and($reflectionMethodController->isConstructor = true)698 ->and($reflectionMethodController->isAbstract = false)699 ->and($reflectionMethodController->getParameters = array())700 ->and($reflectionMethodController->isPublic = true)701 ->and($reflectionMethodController->isProtected = false)702 ->and($reflectionMethodController->isPrivate = false)703 ->and($reflectionMethodController->isFinal = false)704 ->and($reflectionMethodController->isStatic = false)705 ->and($reflectionMethodController->returnsReference = false)706 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))707 ->and($reflectionClassController = new mock\controller())708 ->and($reflectionClassController->__construct = function() {})709 ->and($reflectionClassController->getName = $realClass)710 ->and($reflectionClassController->isFinal = false)711 ->and($reflectionClassController->isInterface = false)712 ->and($reflectionClassController->getMethods = array($reflectionMethod))713 ->and($reflectionClassController->getConstructor = $reflectionMethod)714 ->and($reflectionClassController->isAbstract = false)715 ->and($reflectionClass = new \mock\reflectionClass(null))716 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))717 ->and($adapter = new atoum\test\adapter())718 ->and($adapter->class_exists = function($class) use ($realClass) { return ($class == '\\' . $realClass); })719 ->and($generator->setAdapter($adapter))720 ->and($generator->shunt($realClass))721 ->then722 ->string($generator->getMockedClassCode($realClass))->isEqualTo(723 'namespace mock {' . PHP_EOL .724 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .725 '{' . PHP_EOL .726 $this->getMockControllerMethods() .727 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .728 "\t" . '{' . PHP_EOL .729 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .730 "\t\t" . 'if ($mockController === null)' . PHP_EOL .731 "\t\t" . '{' . PHP_EOL .732 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .733 "\t\t" . '}' . PHP_EOL .734 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .735 "\t\t" . '{' . PHP_EOL .736 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .737 "\t\t" . '}' . PHP_EOL .738 "\t\t" . 'if (isset($this->getMockController()->' . $realClass . ') === false)' . PHP_EOL .739 "\t\t" . '{' . PHP_EOL .740 "\t\t\t" . '$this->getMockController()->' . $realClass . ' = function() {};' . PHP_EOL .741 "\t\t" . '}' . PHP_EOL .742 "\t\t" . '$this->getMockController()->invoke(\'' . $realClass . '\', $arguments);' . PHP_EOL .743 "\t" . '}' . PHP_EOL .744 "\t" . 'public static function getMockedMethods()' . PHP_EOL .745 "\t" . '{' . PHP_EOL .746 "\t\t" . 'return ' . var_export(array($realClass), true) . ';' . PHP_EOL .747 "\t" . '}' . PHP_EOL .748 '}' . PHP_EOL .749 '}'750 )751 ;752 }753 public function testGetMockedClassCodeForInterface()754 {755 $this756 ->if($generator = new testedClass())757 ->and($reflectionMethodController = new mock\controller())758 ->and($reflectionMethodController->__construct = function() {})759 ->and($reflectionMethodController->getName = '__construct')760 ->and($reflectionMethodController->isConstructor = true)761 ->and($reflectionMethodController->getParameters = array())762 ->and($reflectionMethodController->isFinal = false)763 ->and($reflectionMethodController->isStatic = false)764 ->and($reflectionMethodController->returnsReference = false)765 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))766 ->and($reflectionClassController = new mock\controller())767 ->and($reflectionClassController->__construct = function() {})768 ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })769 ->and($reflectionClassController->isFinal = false)770 ->and($reflectionClassController->isInterface = true)771 ->and($reflectionClassController->getMethods = array($reflectionMethod))772 ->and($reflectionClassController->isInstantiable = false)773 ->and($reflectionClassController->implementsInterface = false)774 ->and($reflectionClass = new \mock\reflectionClass(null))775 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))776 ->and($adapter = new atoum\test\adapter())777 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })778 ->and($generator->setAdapter($adapter))779 ->then780 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(781 'namespace mock {' . PHP_EOL .782 'final class ' . $realClass . ' implements \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .783 '{' . PHP_EOL .784 $this->getMockControllerMethods() .785 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .786 "\t" . '{' . PHP_EOL .787 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .788 "\t\t" . 'if ($mockController === null)' . PHP_EOL .789 "\t\t" . '{' . PHP_EOL .790 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .791 "\t\t" . '}' . PHP_EOL .792 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .793 "\t\t" . '{' . PHP_EOL .794 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .795 "\t\t" . '}' . PHP_EOL .796 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .797 "\t\t" . '{' . PHP_EOL .798 "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .799 "\t\t" . '}' . PHP_EOL .800 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .801 "\t" . '}' . PHP_EOL .802 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .803 "\t" . '{' . PHP_EOL .804 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .805 "\t\t" . '{' . PHP_EOL .806 "\t\t\t" . 'return $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .807 "\t\t" . '}' . PHP_EOL .808 "\t\t" . 'else' . PHP_EOL .809 "\t\t" . '{' . PHP_EOL .810 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .811 "\t\t" . '}' . PHP_EOL .812 "\t" . '}' . PHP_EOL .813 "\t" . 'public static function getMockedMethods()' . PHP_EOL .814 "\t" . '{' . PHP_EOL .815 "\t\t" . 'return ' . var_export(array('__construct', '__call'), true) . ';' . PHP_EOL .816 "\t" . '}' . PHP_EOL .817 '}' . PHP_EOL .818 '}'819 )820 ->if($reflectionClassController->implementsInterface = function($interface) { return ($interface == 'traversable' ? true : false); })821 ->and($generator->setReflectionClassFactory(function($class) use ($reflectionClass) { return ($class == 'iteratorAggregate' ? new \reflectionClass('iteratorAggregate') : $reflectionClass); }))822 ->then823 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(824 'namespace mock {' . PHP_EOL .825 'final class ' . $realClass . ' implements \\iteratorAggregate, \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .826 '{' . PHP_EOL .827 $this->getMockControllerMethods() .828 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .829 "\t" . '{' . PHP_EOL .830 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .831 "\t\t" . 'if ($mockController === null)' . PHP_EOL .832 "\t\t" . '{' . PHP_EOL .833 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .834 "\t\t" . '}' . PHP_EOL .835 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .836 "\t\t" . '{' . PHP_EOL .837 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .838 "\t\t" . '}' . PHP_EOL .839 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .840 "\t\t" . '{' . PHP_EOL .841 "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .842 "\t\t" . '}' . PHP_EOL .843 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .844 "\t" . '}' . PHP_EOL .845 "\t" . 'public function getIterator()' . PHP_EOL .846 "\t" . '{' . PHP_EOL .847 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .848 "\t\t" . 'if (isset($this->getMockController()->getIterator) === false)' . PHP_EOL .849 "\t\t" . '{' . PHP_EOL .850 "\t\t\t" . '$this->getMockController()->getIterator = function() {};' . PHP_EOL .851 "\t\t" . '}' . PHP_EOL .852 "\t\t" . 'return $this->getMockController()->invoke(\'getIterator\', $arguments);' . PHP_EOL .853 "\t" . '}' . PHP_EOL .854 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .855 "\t" . '{' . PHP_EOL .856 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .857 "\t\t" . '{' . PHP_EOL .858 "\t\t\t" . 'return $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .859 "\t\t" . '}' . PHP_EOL .860 "\t\t" . 'else' . PHP_EOL .861 "\t\t" . '{' . PHP_EOL .862 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .863 "\t\t" . '}' . PHP_EOL .864 "\t" . '}' . PHP_EOL .865 "\t" . 'public static function getMockedMethods()' . PHP_EOL .866 "\t" . '{' . PHP_EOL .867 "\t\t" . 'return ' . var_export(array('__construct', 'getiterator', '__call'), true) . ';' . PHP_EOL .868 "\t" . '}' . PHP_EOL .869 '}' . PHP_EOL .870 '}'871 )872 ;873 }874 public function testGetMockedClassCodeForInterfaceWithStaticMethod()875 {876 $this877 ->if($generator = new testedClass())878 ->and($reflectionMethodController = new mock\controller())879 ->and($reflectionMethodController->__construct = function() {})880 ->and($reflectionMethodController->getName = $methodName = uniqid())881 ->and($reflectionMethodController->isConstructor = false)882 ->and($reflectionMethodController->getParameters = array())883 ->and($reflectionMethodController->isFinal = false)884 ->and($reflectionMethodController->isStatic = true)885 ->and($reflectionMethodController->returnsReference = false)886 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))887 ->and($reflectionClassController = new mock\controller())888 ->and($reflectionClassController->__construct = function() {})889 ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })890 ->and($reflectionClassController->isFinal = false)891 ->and($reflectionClassController->isInterface = true)892 ->and($reflectionClassController->getMethods = array($reflectionMethod))893 ->and($reflectionClassController->isInstantiable = false)894 ->and($reflectionClassController->implementsInterface = false)895 ->and($reflectionClass = new \mock\reflectionClass(null))896 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))897 ->and($adapter = new atoum\test\adapter())898 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })899 ->and($generator->setAdapter($adapter))900 ->then901 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(902 'namespace mock {' . PHP_EOL .903 'final class ' . $realClass . ' implements \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .904 '{' . PHP_EOL .905 $this->getMockControllerMethods() .906 "\t" . 'public static function ' . $methodName . '()' . PHP_EOL .907 "\t" . '{' . PHP_EOL .908 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .909 "\t\t" . 'return call_user_func_array(array(\'parent\', \'' . $methodName . '\'), $arguments);' . PHP_EOL .910 "\t" . '}' . PHP_EOL .911 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .912 "\t" . '{' . PHP_EOL .913 "\t\t" . 'if ($mockController === null)' . PHP_EOL .914 "\t\t" . '{' . PHP_EOL .915 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .916 "\t\t" . '}' . PHP_EOL .917 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .918 "\t\t" . '{' . PHP_EOL .919 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .920 "\t\t" . '}' . PHP_EOL .921 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .922 "\t\t" . '{' . PHP_EOL .923 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .924 "\t\t" . '}' . PHP_EOL .925 "\t" . '}' . PHP_EOL .926 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .927 "\t" . '{' . PHP_EOL .928 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .929 "\t\t" . '{' . PHP_EOL .930 "\t\t\t" . 'return $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .931 "\t\t" . '}' . PHP_EOL .932 "\t\t" . 'else' . PHP_EOL .933 "\t\t" . '{' . PHP_EOL .934 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .935 "\t\t" . '}' . PHP_EOL .936 "\t" . '}' . PHP_EOL .937 "\t" . 'public static function getMockedMethods()' . PHP_EOL .938 "\t" . '{' . PHP_EOL .939 "\t\t" . 'return ' . var_export(array($methodName, '__construct', '__call'), true) . ';' . PHP_EOL .940 "\t" . '}' . PHP_EOL .941 '}' . PHP_EOL .942 '}'943 )944 ->if($reflectionClassController->implementsInterface = function($interface) { return ($interface == 'traversable' ? true : false); })945 ->and($generator->setReflectionClassFactory(function($class) use ($reflectionClass) { return ($class == 'iteratorAggregate' ? new \reflectionClass('iteratorAggregate') : $reflectionClass); }))946 ->then947 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(948 'namespace mock {' . PHP_EOL .949 'final class ' . $realClass . ' implements \\iteratorAggregate, \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .950 '{' . PHP_EOL .951 $this->getMockControllerMethods() .952 "\t" . 'public static function ' . $methodName . '()' . PHP_EOL .953 "\t" . '{' . PHP_EOL .954 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .955 "\t\t" . 'return call_user_func_array(array(\'parent\', \'' . $methodName . '\'), $arguments);' . PHP_EOL .956 "\t" . '}' . PHP_EOL .957 "\t" . 'public function getIterator()' . PHP_EOL .958 "\t" . '{' . PHP_EOL .959 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .960 "\t\t" . 'if (isset($this->getMockController()->getIterator) === false)' . PHP_EOL .961 "\t\t" . '{' . PHP_EOL .962 "\t\t\t" . '$this->getMockController()->getIterator = function() {};' . PHP_EOL .963 "\t\t" . '}' . PHP_EOL .964 "\t\t" . 'return $this->getMockController()->invoke(\'getIterator\', $arguments);' . PHP_EOL .965 "\t" . '}' . PHP_EOL .966 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .967 "\t" . '{' . PHP_EOL .968 "\t\t" . 'if ($mockController === null)' . PHP_EOL .969 "\t\t" . '{' . PHP_EOL .970 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .971 "\t\t" . '}' . PHP_EOL .972 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .973 "\t\t" . '{' . PHP_EOL .974 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .975 "\t\t" . '}' . PHP_EOL .976 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .977 "\t\t" . '{' . PHP_EOL .978 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .979 "\t\t" . '}' . PHP_EOL .980 "\t" . '}' . PHP_EOL .981 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .982 "\t" . '{' . PHP_EOL .983 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .984 "\t\t" . '{' . PHP_EOL .985 "\t\t\t" . 'return $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .986 "\t\t" . '}' . PHP_EOL .987 "\t\t" . 'else' . PHP_EOL .988 "\t\t" . '{' . PHP_EOL .989 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .990 "\t\t" . '}' . PHP_EOL .991 "\t" . '}' . PHP_EOL .992 "\t" . 'public static function getMockedMethods()' . PHP_EOL .993 "\t" . '{' . PHP_EOL .994 "\t\t" . 'return ' . var_export(array($methodName, 'getiterator', '__construct', '__call'), true) . ';' . PHP_EOL .995 "\t" . '}' . PHP_EOL .996 '}' . PHP_EOL .997 '}'998 )999 ;1000 }1001 public function testGetMockedClassCodeForRealClassWithoutConstructor()1002 {1003 $this1004 ->if($generator = new testedClass())1005 ->and($reflectionMethodController = new mock\controller())1006 ->and($reflectionMethodController->__construct = function() {})1007 ->and($reflectionMethodController->getName = $methodName = uniqid())1008 ->and($reflectionMethodController->isConstructor = false)1009 ->and($reflectionMethodController->getParameters = array())1010 ->and($reflectionMethodController->isPublic = true)1011 ->and($reflectionMethodController->isProtected = false)1012 ->and($reflectionMethodController->isPrivate = false)1013 ->and($reflectionMethodController->isFinal = false)1014 ->and($reflectionMethodController->isAbstract = false)1015 ->and($reflectionMethodController->isStatic = false)1016 ->and($reflectionMethodController->returnsReference = false)1017 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))1018 ->and($reflectionClassController = new mock\controller())1019 ->and($reflectionClassController->__construct = function() {})1020 ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })1021 ->and($reflectionClassController->isFinal = false)1022 ->and($reflectionClassController->isInterface = false)1023 ->and($reflectionClassController->getMethods = array($reflectionMethod))1024 ->and($reflectionClassController->getConstructor = null)1025 ->and($reflectionClassController->isAbstract = false)1026 ->and($reflectionClass = new \mock\reflectionClass(null))1027 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))1028 ->and($adapter = new atoum\test\adapter())1029 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })1030 ->and($generator->setAdapter($adapter))1031 ->then1032 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(1033 'namespace mock {' . PHP_EOL .1034 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .1035 '{' . PHP_EOL .1036 $this->getMockControllerMethods() .1037 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1038 "\t" . '{' . PHP_EOL .1039 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1040 "\t\t" . '{' . PHP_EOL .1041 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1042 "\t\t" . '}' . PHP_EOL .1043 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1044 "\t\t" . '{' . PHP_EOL .1045 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1046 "\t\t" . '}' . PHP_EOL .1047 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .1048 "\t\t" . '{' . PHP_EOL .1049 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .1050 "\t\t" . '}' . PHP_EOL .1051 "\t" . '}' . PHP_EOL .1052 "\t" . 'public function ' . $methodName . '()' . PHP_EOL .1053 "\t" . '{' . PHP_EOL .1054 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .1055 "\t\t" . 'if (isset($this->getMockController()->' . $methodName . ') === true)' . PHP_EOL .1056 "\t\t" . '{' . PHP_EOL .1057 "\t\t\t" . 'return $this->getMockController()->invoke(\'' . $methodName . '\', $arguments);' . PHP_EOL .1058 "\t\t" . '}' . PHP_EOL .1059 "\t\t" . 'else' . PHP_EOL .1060 "\t\t" . '{' . PHP_EOL .1061 "\t\t\t" . '$this->getMockController()->addCall(\'' . $methodName . '\', $arguments);' . PHP_EOL .1062 "\t\t\t" . 'return call_user_func_array(\'parent::' . $methodName . '\', $arguments);' . PHP_EOL .1063 "\t\t" . '}' . PHP_EOL .1064 "\t" . '}' . PHP_EOL .1065 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1066 "\t" . '{' . PHP_EOL .1067 "\t\t" . 'return ' . var_export(array('__construct', $methodName), true) . ';' . PHP_EOL .1068 "\t" . '}' . PHP_EOL .1069 '}' . PHP_EOL .1070 '}'1071 )1072 ;1073 }1074 public function testGetMockedClassCodeForAbstractClassWithConstructorInInterface()1075 {1076 $this1077 ->if($generator = new testedClass())1078 ->and($publicMethodController = new mock\controller())1079 ->and($publicMethodController->__construct = function() {})1080 ->and($publicMethodController->getName = '__construct')1081 ->and($publicMethodController->isConstructor = true)1082 ->and($publicMethodController->getParameters = array())1083 ->and($publicMethodController->isPublic = true)1084 ->and($publicMethodController->isProtected = false)1085 ->and($publicMethodController->isPrivate = false)1086 ->and($publicMethodController->isFinal = false)1087 ->and($publicMethodController->isStatic = false)1088 ->and($publicMethodController->isAbstract = true)1089 ->and($publicMethodController->returnsReference = false)1090 ->and($publicMethod = new \mock\reflectionMethod(null, null))1091 ->and($classController = new mock\controller())1092 ->and($classController->__construct = function() {})1093 ->and($classController->getName = $className = uniqid())1094 ->and($classController->isFinal = false)1095 ->and($classController->isInterface = false)1096 ->and($classController->isAbstract = true)1097 ->and($classController->getMethods = array($publicMethod))1098 ->and($classController->getConstructor = $publicMethod)1099 ->and($class = new \mock\reflectionClass(null))1100 ->and($generator->setReflectionClassFactory(function() use ($class) { return $class; }))1101 ->and($adapter = new atoum\test\adapter())1102 ->and($adapter->class_exists = function($class) use ($className) { return ($class == '\\' . $className); })1103 ->and($generator->setAdapter($adapter))1104 ->then1105 ->string($generator->getMockedClassCode($className))->isEqualTo(1106 'namespace mock {' . PHP_EOL .1107 'final class ' . $className . ' extends \\' . $className . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .1108 '{' . PHP_EOL .1109 $this->getMockControllerMethods() .1110 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1111 "\t" . '{' . PHP_EOL .1112 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .1113 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1114 "\t\t" . '{' . PHP_EOL .1115 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1116 "\t\t" . '}' . PHP_EOL .1117 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1118 "\t\t" . '{' . PHP_EOL .1119 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1120 "\t\t" . '}' . PHP_EOL .1121 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .1122 "\t\t" . '{' . PHP_EOL .1123 "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .1124 "\t\t" . '}' . PHP_EOL .1125 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .1126 "\t" . '}' . PHP_EOL .1127 "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .1128 "\t" . '{' . PHP_EOL .1129 "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .1130 "\t\t" . '{' . PHP_EOL .1131 "\t\t\t" . 'return $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .1132 "\t\t" . '}' . PHP_EOL .1133 "\t\t" . 'else' . PHP_EOL .1134 "\t\t" . '{' . PHP_EOL .1135 "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .1136 "\t\t" . '}' . PHP_EOL .1137 "\t" . '}' . PHP_EOL .1138 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1139 "\t" . '{' . PHP_EOL .1140 "\t\t" . 'return ' . var_export(array('__construct', '__call'), true) . ';' . PHP_EOL .1141 "\t" . '}' . PHP_EOL .1142 '}' . PHP_EOL .1143 '}'1144 )1145 ;1146 }1147 public function testGenerate()1148 {1149 $this1150 ->if($generator = new testedClass())1151 ->then1152 ->exception(function() use ($generator) { $generator->generate(''); })1153 ->isInstanceOf('mageekguy\atoum\exceptions\runtime')1154 ->hasMessage('Class name \'\' is invalid')1155 ->exception(function() use ($generator) { $generator->generate('\\'); })1156 ->isInstanceOf('mageekguy\atoum\exceptions\runtime')1157 ->hasMessage('Class name \'\\\' is invalid')1158 ->exception(function() use ($generator, & $class) { $generator->generate($class = ('\\' . uniqid() . '\\')); })1159 ->isInstanceOf('mageekguy\atoum\exceptions\runtime')1160 ->hasMessage('Class name \'' . $class . '\' is invalid')1161 ->if($adapter = new atoum\test\adapter())1162 ->and($adapter->class_exists = false)1163 ->and($adapter->interface_exists = false)1164 ->and($generator->setAdapter($adapter))1165 ->and($class = uniqid('unknownClass'))1166 ->then1167 ->object($generator->generate($class))->isIdenticalTo($generator)1168 ->class('\mock\\' . $class)1169 ->hasNoParent()1170 ->hasInterface('mageekguy\atoum\mock\aggregator')1171 ->if($class = '\\' . uniqid('unknownClass'))1172 ->then1173 ->object($generator->generate($class))->isIdenticalTo($generator)1174 ->class('\mock' . $class)1175 ->hasNoParent()1176 ->hasInterface('mageekguy\atoum\mock\aggregator')1177 ->if($adapter->class_exists = true)1178 ->and($class = uniqid())1179 ->then1180 ->exception(function () use ($generator, $class) {1181 $generator->generate($class);1182 }1183 )1184 ->isInstanceOf('mageekguy\atoum\exceptions\logic')1185 ->hasMessage('Class \'\mock\\' . $class . '\' already exists')1186 ->if($class = '\\' . uniqid())1187 ->then1188 ->exception(function () use ($generator, $class) {1189 $generator->generate($class);1190 }1191 )1192 ->isInstanceOf('mageekguy\atoum\exceptions\logic')1193 ->hasMessage('Class \'\mock' . $class . '\' already exists')1194 ->if($class = uniqid())1195 ->and($adapter->class_exists = function($arg) use ($class) { return $arg === '\\' . $class; })1196 ->and($reflectionClassController = new mock\controller())1197 ->and($reflectionClassController->__construct = function() {})1198 ->and($reflectionClassController->isFinal = true)1199 ->and($reflectionClassController->isInterface = false)1200 ->and($reflectionClass = new \mock\reflectionClass(uniqid(), $reflectionClassController))1201 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))1202 ->then1203 ->exception(function () use ($generator, $class) {1204 $generator->generate($class);1205 }1206 )1207 ->isInstanceOf('mageekguy\atoum\exceptions\logic')1208 ->hasMessage('Class \'\\' . $class . '\' is final, unable to mock it')1209 ->if($class = '\\' . uniqid())1210 ->and($adapter->class_exists = function($arg) use ($class) { return $arg === $class; })1211 ->then1212 ->exception(function () use ($generator, $class) {1213 $generator->generate($class);1214 }1215 )1216 ->isInstanceOf('mageekguy\atoum\exceptions\logic')1217 ->hasMessage('Class \'' . $class . '\' is final, unable to mock it')1218 ->if($reflectionClassController->isFinal = false)1219 ->and($generator = new testedClass())1220 ->then1221 ->object($generator->generate(__CLASS__))->isIdenticalTo($generator)1222 ->class('\mock\\' . __CLASS__)1223 ->hasParent(__CLASS__)1224 ->hasInterface('mageekguy\atoum\mock\aggregator')1225 ->if($generator = new testedClass())1226 ->and($generator->shunt('__construct'))1227 ->then1228 ->boolean($generator->isShunted('__construct'))->isTrue()1229 ->object($generator->generate('reflectionMethod'))->isIdenticalTo($generator)1230 ->boolean($generator->isShunted('__construct'))->isFalse()1231 ->if($generator = new testedClass())1232 ->and($generator->shuntParentClassCalls())1233 ->then1234 ->object($generator->generate('reflectionParameter'))->isIdenticalTo($generator)1235 ->boolean($generator->callsToParentClassAreShunted())->isFalse()1236 ;1237 }1238 public function testMethodIsMockable()1239 {1240 $this1241 ->if($generator = new testedClass())1242 ->and($this->mockGenerator->orphanize('__construct'))1243 ->and($method = new \mock\reflectionMethod($this, $methodName = uniqid()))1244 ->and($this->calling($method)->getName = $methodName)1245 ->and($this->calling($method)->isFinal = false)1246 ->and($this->calling($method)->isStatic = false)1247 ->and($this->calling($method)->isAbstract = false)1248 ->and($this->calling($method)->isPrivate = false)1249 ->and($this->calling($method)->isProtected = false)1250 ->then1251 ->boolean($generator->methodIsMockable($method))->isTrue()1252 ->if($this->calling($method)->isFinal = true)1253 ->then1254 ->boolean($generator->methodIsMockable($method))->isFalse()1255 ->if($this->calling($method)->isFinal = false)1256 ->and($this->calling($method)->isStatic = true)1257 ->then1258 ->boolean($generator->methodIsMockable($method))->isFalse()1259 ->if($this->calling($method)->isStatic = false)1260 ->and($this->calling($method)->isPrivate = true)1261 ->then1262 ->boolean($generator->methodIsMockable($method))->isFalse()1263 ->if($this->calling($method)->isPrivate = false)1264 ->and($this->calling($method)->isProtected = true)1265 ->then1266 ->boolean($generator->methodIsMockable($method))->isFalse()1267 ->if($generator->overload(new mock\php\method($methodName)))1268 ->then1269 ->boolean($generator->methodIsMockable($method))->isTrue()1270 ;1271 }1272 public function testMethodIsMockableWithReservedWord($reservedWord)1273 {1274 $this1275 ->if($generator = new testedClass())1276 ->and($this->mockGenerator->orphanize('__construct'))1277 ->and($method = new \mock\reflectionMethod($this, $reservedWord))1278 ->and($this->calling($method)->getName = $reservedWord)1279 ->and($this->calling($method)->isFinal = false)1280 ->and($this->calling($method)->isStatic = false)1281 ->and($this->calling($method)->isAbstract = false)1282 ->and($this->calling($method)->isPrivate = false)1283 ->and($this->calling($method)->isProtected = false)1284 ->then1285 ->boolean($generator->methodIsMockable($method))->isFalse()1286 ;1287 }1288 /** @php 5.4 */1289 public function testGetMockedClassCodeWithOrphanizedMethod()1290 {1291 $this1292 ->if->mockGenerator->orphanize('__construct')1293 ->and($a = new \mock\reflectionParameter())1294 ->and($this->calling($a)->getName = 'a')1295 ->and($this->calling($a)->isArray = false)1296 ->and($this->calling($a)->isCallable = false)1297 ->and($this->calling($a)->getClass = null)1298 ->and($this->calling($a)->isPassedByReference = false)1299 ->and($this->calling($a)->isDefaultValueAvailable = false)1300 ->and($this->calling($a)->isOptional = false)1301 ->and($b = new \mock\reflectionParameter())1302 ->and($this->calling($b)->getName = 'b')1303 ->and($this->calling($b)->isArray = false)1304 ->and($this->calling($b)->isCallable = false)1305 ->and($this->calling($b)->getClass = null)1306 ->and($this->calling($b)->isPassedByReference = false)1307 ->and($this->calling($b)->isDefaultValueAvailable = false)1308 ->and($this->calling($b)->isOptional = false)1309 ->and($c = new \mock\reflectionParameter())1310 ->and($this->calling($c)->getName = 'c')1311 ->and($this->calling($c)->isArray = false)1312 ->and($this->calling($c)->isCallable = false)1313 ->and($this->calling($c)->getClass = null)1314 ->and($this->calling($c)->isPassedByReference = false)1315 ->and($this->calling($c)->isDefaultValueAvailable = false)1316 ->and($this->calling($c)->isOptional = false)1317 ->and->mockGenerator->orphanize('__construct')1318 ->and($constructor = new \mock\reflectionMethod())1319 ->and($this->calling($constructor)->getName = '__construct')1320 ->and($this->calling($constructor)->isConstructor = true)1321 ->and($this->calling($constructor)->getParameters = array($a, $b, $c))1322 ->and($this->calling($constructor)->isPublic = true)1323 ->and($this->calling($constructor)->isProtected = false)1324 ->and($this->calling($constructor)->isPrivate = false)1325 ->and($this->calling($constructor)->isFinal = false)1326 ->and($this->calling($constructor)->isStatic = false)1327 ->and($this->calling($constructor)->isAbstract = false)1328 ->and($this->calling($constructor)->returnsReference = false)1329 ->and->mockGenerator->orphanize('__construct')1330 ->and($class = new \mock\reflectionClass())1331 ->and($this->calling($class)->getName = $className = uniqid())1332 ->and($this->calling($class)->isFinal = false)1333 ->and($this->calling($class)->isInterface = false)1334 ->and($this->calling($class)->isAbstract = false)1335 ->and($this->calling($class)->getMethods = array($constructor))1336 ->and($this->calling($class)->getConstructor = $constructor)1337 ->and($adapter = new atoum\test\adapter())1338 ->and($adapter->class_exists = function($class) use ($className) { return ($class == '\\' . $className); })1339 ->and($generator = new testedClass())1340 ->and($generator->setReflectionClassFactory(function() use ($class) { return $class; }))1341 ->and($generator->setAdapter($adapter))1342 ->and($generator->orphanize('__construct'))1343 ->then1344 ->string($generator->getMockedClassCode($className))->isEqualTo(1345 'namespace mock {' . PHP_EOL .1346 'final class ' . $className . ' extends \\' . $className . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .1347 '{' . PHP_EOL .1348 $this->getMockControllerMethods() .1349 "\t" . 'public function __construct($a = null, $b = null, $c = null, \mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1350 "\t" . '{' . PHP_EOL .1351 "\t\t" . '$arguments = array_merge(array($a, $b, $c), array_slice(func_get_args(), 3, -1));' . PHP_EOL .1352 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1353 "\t\t" . '{' . PHP_EOL .1354 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1355 "\t\t" . '}' . PHP_EOL .1356 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1357 "\t\t" . '{' . PHP_EOL .1358 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1359 "\t\t" . '}' . PHP_EOL .1360 "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .1361 "\t\t" . '{' . PHP_EOL .1362 "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .1363 "\t\t" . '}' . PHP_EOL .1364 "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .1365 "\t" . '}' . PHP_EOL .1366 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1367 "\t" . '{' . PHP_EOL .1368 "\t\t" . 'return ' . var_export(array('__construct'), true) . ';' . PHP_EOL .1369 "\t" . '}' . PHP_EOL .1370 '}' . PHP_EOL .1371 '}'1372 )1373 ;1374 }1375 /** @php 5.4 */1376 public function testGetMockedClassCodeWithProtectedAbstractMethod()1377 {1378 $this1379 ->if($generator = new testedClass())1380 ->and($parameterController1 = new mock\controller())1381 ->and($parameterController1->__construct = function() {})1382 ->and($parameterController1->isArray = false)1383 ->and($parameterController1->isCallable = false)1384 ->and($parameterController1->getClass = null)1385 ->and($parameterController1->getName = 'arg1')1386 ->and($parameterController1->isPassedByReference = false)1387 ->and($parameterController1->isDefaultValueAvailable = false)1388 ->and($parameterController1->isOptional = false)1389 ->and($parameter1 = new \mock\reflectionParameter(null, null))1390 ->and($parameterController2 = new mock\controller())1391 ->and($parameterController2->__construct = function() {})1392 ->and($parameterController2->isArray = true)1393 ->and($parameterController2->isCallable = false)1394 ->and($parameterController2->getClass = null)1395 ->and($parameterController2->getName = 'arg2')1396 ->and($parameterController2->isPassedByReference = true)1397 ->and($parameterController2->isDefaultValueAvailable = false)1398 ->and($parameterController2->isOptional = false)1399 ->and($parameter2 = new \mock\reflectionParameter(null, null))1400 ->and($publicMethodController = new mock\controller())1401 ->and($publicMethodController->__construct = function() {})1402 ->and($publicMethodController->getName = $publicMethodName = uniqid())1403 ->and($publicMethodController->isConstructor = false)1404 ->and($publicMethodController->getParameters = array($parameter1, $parameter2))1405 ->and($publicMethodController->isPublic = true)1406 ->and($publicMethodController->isProtected = false)1407 ->and($publicMethodController->isPrivate = false)1408 ->and($publicMethodController->isFinal = false)1409 ->and($publicMethodController->isStatic = false)1410 ->and($publicMethodController->isAbstract = true)1411 ->and($publicMethodController->returnsReference = false)1412 ->and($publicMethod = new \mock\reflectionMethod(null, null))1413 ->and($protectedMethodController = new mock\controller())1414 ->and($protectedMethodController->__construct = function() {})1415 ->and($protectedMethodController->getName = $protectedMethodName = uniqid())1416 ->and($protectedMethodController->isConstructor = false)1417 ->and($protectedMethodController->getParameters = array())1418 ->and($protectedMethodController->isPublic = false)1419 ->and($protectedMethodController->isProtected = true)1420 ->and($protectedMethodController->isPrivate = false)1421 ->and($protectedMethodController->isFinal = false)1422 ->and($protectedMethodController->isStatic = false)1423 ->and($protectedMethodController->isAbstract = true)1424 ->and($protectedMethodController->returnsReference = false)1425 ->and($protectedMethod = new \mock\reflectionMethod(null, null))1426 ->and($classController = new mock\controller())1427 ->and($classController->__construct = function() {})1428 ->and($classController->getName = $className = uniqid())1429 ->and($classController->isFinal = false)1430 ->and($classController->isInterface = false)1431 ->and($classController->getMethods = array($publicMethod, $protectedMethod))1432 ->and($classController->getConstructor = null)1433 ->and($classController->isAbstract = false)1434 ->and($class = new \mock\reflectionClass(null))1435 ->and($generator->setReflectionClassFactory(function() use ($class) { return $class; }))1436 ->and($adapter = new atoum\test\adapter())1437 ->and($adapter->class_exists = function($class) use ($className) { return ($class == '\\' . $className); })1438 ->and($generator->setAdapter($adapter))1439 ->then1440 ->string($generator->getMockedClassCode($className))->isEqualTo(1441 'namespace mock {' . PHP_EOL .1442 'final class ' . $className . ' extends \\' . $className . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .1443 '{' . PHP_EOL .1444 $this->getMockControllerMethods() .1445 "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1446 "\t" . '{' . PHP_EOL .1447 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1448 "\t\t" . '{' . PHP_EOL .1449 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1450 "\t\t" . '}' . PHP_EOL .1451 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1452 "\t\t" . '{' . PHP_EOL .1453 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1454 "\t\t" . '}' . PHP_EOL .1455 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .1456 "\t\t" . '{' . PHP_EOL .1457 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .1458 "\t\t" . '}' . PHP_EOL .1459 "\t" . '}' . PHP_EOL .1460 "\t" . 'public function ' . $publicMethodName . '($arg1, array & $arg2)' . PHP_EOL .1461 "\t" . '{' . PHP_EOL .1462 "\t\t" . '$arguments = array_merge(array($arg1, & $arg2), array_slice(func_get_args(), 2));' . PHP_EOL .1463 "\t\t" . 'if (isset($this->getMockController()->' . $publicMethodName . ') === false)' . PHP_EOL .1464 "\t\t" . '{' . PHP_EOL .1465 "\t\t\t" . '$this->getMockController()->' . $publicMethodName . ' = function() {};' . PHP_EOL .1466 "\t\t" . '}' . PHP_EOL .1467 "\t\t" . 'return $this->getMockController()->invoke(\'' . $publicMethodName . '\', $arguments);' . PHP_EOL .1468 "\t" . '}' . PHP_EOL .1469 "\t" . 'protected function ' . $protectedMethodName . '()' . PHP_EOL .1470 "\t" . '{' . PHP_EOL .1471 "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .1472 "\t\t" . 'if (isset($this->getMockController()->' . $protectedMethodName . ') === false)' . PHP_EOL .1473 "\t\t" . '{' . PHP_EOL .1474 "\t\t\t" . '$this->getMockController()->' . $protectedMethodName . ' = function() {};' . PHP_EOL .1475 "\t\t" . '}' . PHP_EOL .1476 "\t\t" . 'return $this->getMockController()->invoke(\'' . $protectedMethodName . '\', $arguments);' . PHP_EOL .1477 "\t" . '}' . PHP_EOL .1478 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1479 "\t" . '{' . PHP_EOL .1480 "\t\t" . 'return ' . var_export(array('__construct', $publicMethodName, $protectedMethodName), true) . ';' . PHP_EOL .1481 "\t" . '}' . PHP_EOL .1482 '}' . PHP_EOL .1483 '}'1484 )1485 ;1486 }1487 /** @php 5.4 */1488 public function testGetMockedClassCodeForClassWithCallableTypeHint()1489 {1490 $this1491 ->if($generator = new testedClass())1492 ->and($reflectionParameterController = new mock\controller())1493 ->and($reflectionParameterController->__construct = function() {})1494 ->and($reflectionParameterController->isArray = false)1495 ->and($reflectionParameterController->isCallable = true)1496 ->and($reflectionParameterController->getName = 'callback')1497 ->and($reflectionParameterController->isPassedByReference = false)1498 ->and($reflectionParameterController->isDefaultValueAvailable = false)1499 ->and($reflectionParameterController->isOptional = false)1500 ->and($reflectionParameter = new \mock\reflectionParameter(null, null))1501 ->and($reflectionMethodController = new mock\controller())1502 ->and($reflectionMethodController->__construct = function() {})1503 ->and($reflectionMethodController->getName = '__construct')1504 ->and($reflectionMethodController->isConstructor = true)1505 ->and($reflectionMethodController->getParameters = array($reflectionParameter))1506 ->and($reflectionMethodController->isPublic = true)1507 ->and($reflectionMethodController->isProtected = false)1508 ->and($reflectionMethodController->isPrivate = false)1509 ->and($reflectionMethodController->isFinal = false)1510 ->and($reflectionMethodController->isStatic = false)1511 ->and($reflectionMethodController->isAbstract = false)1512 ->and($reflectionMethodController->returnsReference = false)1513 ->and($reflectionMethod = new \mock\reflectionMethod(null, null))1514 ->and($reflectionClassController = new mock\controller())1515 ->and($reflectionClassController->__construct = function() {})1516 ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })1517 ->and($reflectionClassController->isFinal = false)1518 ->and($reflectionClassController->isInterface = false)1519 ->and($reflectionClassController->getMethods = array($reflectionMethod))1520 ->and($reflectionClassController->getConstructor = $reflectionMethod)1521 ->and($reflectionClassController->isAbstract = false)1522 ->and($reflectionClass = new \mock\reflectionClass(null))1523 ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))1524 ->and($adapter = new atoum\test\adapter())1525 ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })1526 ->and($generator->setAdapter($adapter))1527 ->then1528 ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(1529 'namespace mock {' . PHP_EOL .1530 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .1531 '{' . PHP_EOL .1532 $this->getMockControllerMethods() .1533 "\t" . 'public function __construct(callable $callback, \mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .1534 "\t" . '{' . PHP_EOL .1535 "\t\t" . '$arguments = array_merge(array($callback), array_slice(func_get_args(), 1, -1));' . PHP_EOL .1536 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1537 "\t\t" . '{' . PHP_EOL .1538 "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .1539 "\t\t" . '}' . PHP_EOL .1540 "\t\t" . 'if ($mockController !== null)' . PHP_EOL .1541 "\t\t" . '{' . PHP_EOL .1542 "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .1543 "\t\t" . '}' . PHP_EOL .1544 "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .1545 "\t\t" . '{' . PHP_EOL .1546 "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .1547 "\t\t" . '}' . PHP_EOL .1548 "\t\t" . 'else' . PHP_EOL .1549 "\t\t" . '{' . PHP_EOL .1550 "\t\t\t" . '$this->getMockController()->addCall(\'__construct\', $arguments);' . PHP_EOL .1551 "\t\t\t" . 'call_user_func_array(\'parent::__construct\', $arguments);' . PHP_EOL .1552 "\t\t" . '}' . PHP_EOL .1553 "\t" . '}' . PHP_EOL .1554 "\t" . 'public static function getMockedMethods()' . PHP_EOL .1555 "\t" . '{' . PHP_EOL .1556 "\t\t" . 'return ' . var_export(array('__construct'), true) . ';' . PHP_EOL .1557 "\t" . '}' . PHP_EOL .1558 '}' . PHP_EOL .1559 '}'1560 )1561 ;1562 }1563 protected function getMockControllerMethods()1564 {1565 return1566 "\t" . 'public function getMockController()' . PHP_EOL .1567 "\t" . '{' . PHP_EOL .1568 "\t\t" . '$mockController = \mageekguy\atoum\mock\controller::getForMock($this);' . PHP_EOL .1569 "\t\t" . 'if ($mockController === null)' . PHP_EOL .1570 "\t\t" . '{' . PHP_EOL ....

Full Screen

Full Screen

Apns.php

Source:Apns.php Github

copy

Full Screen

...30 })31 ->isInstanceOf('\Sly\NotificationPusher\Exception\AdapterException')32 ->message33 ->contains('does not exist')34 ->when($this->mockGenerator()->orphanize('__construct'))35 ->and($this->mockClass('\Sly\NotificationPusher\Adapter\Apns', '\Mock'))36 ->and($object = new \Mock\Apns())37 ->and($object->setParameters(array('certificate' => 'test.pem', 'passPhrase' => 'test')))38 ->array($object->getParameters())39 ->isNotEmpty()40 ->hasSize(2)41 ->string($object->getParameter('certificate'))42 ->isEqualTo('test.pem')43 ;44 }45 public function testSupports()46 {47 $this->if($this->mockGenerator()->orphanize('__construct'))48 ->and($this->mockClass('\Sly\NotificationPusher\Adapter\Apns', '\Mock'))49 ->and($object = new \Mock\Apns())50 ->boolean($object->supports('wrongToken'))51 ->isFalse()52 ->boolean($object->supports(self::APNS_TOKEN_EXAMPLE))53 ->isTrue()54 ;55 }56 public function testDefinedParameters()57 {58 $this->if($this->mockGenerator()->orphanize('__construct'))59 ->and($this->mockClass('\Sly\NotificationPusher\Adapter\Apns', '\Mock'))60 ->and($object = new \Mock\Apns())61 ->array($defaultParameters = $object->getDefinedParameters())62 ->isEmpty()63 ;64 }65 public function testDefaultParameters()66 {67 $this->if($this->mockGenerator()->orphanize('__construct'))68 ->and($this->mockClass('\Sly\NotificationPusher\Adapter\Apns', '\Mock'))69 ->and($object = new \Mock\Apns())70 ->array($defaultParameters = $object->getDefaultParameters())71 ->isNotEmpty()72 ->hasKey('passPhrase')73 ->variable($defaultParameters['passPhrase'])74 ->isNull()75 ;76 }77 public function testRequiredParameters()78 {79 $this->if($this->mockGenerator()->orphanize('__construct'))80 ->and($this->mockClass('\Sly\NotificationPusher\Adapter\Apns', '\Mock'))81 ->and($object = new \Mock\Apns())82 ->array($requiredParameters = $object->getRequiredParameters())83 ->isNotEmpty()84 ->contains('certificate')85 ;86 }87 public function testGetOpenedClient()88 {89 $this->if($this->mockGenerator()->orphanize('__construct'))90 ->and($this->mockClass('\Sly\NotificationPusher\Adapter\Apns', '\Mock'))91 ->and($object = new \Mock\Apns())92 ->and($this->mockGenerator()->orphanize('__construct'))93 ->and($this->mockGenerator()->orphanize('open'))94 ->and($this->mockClass('\ZendService\Apple\Apns\Client\Message', '\Mock\ZendService'))95 ->and($serviceClient = new \Mock\ZendService\Message())96 ->and($object->getMockController()->getParameters = array())97 ->exception(function() use($object) {98 $object->getOpenedClient(new BaseServiceClient());99 })100 ->isInstanceOf('\ZendService\Apple\Exception\InvalidArgumentException')101 ->message102 ->contains('Certificate must be a valid path to a APNS certificate')103 ->when($object = new TestedModel(array('certificate' => __DIR__.'/../Resources/apns-certificate.pem')))104 ->and($object->getOpenedClient($serviceClient))105 ;106 }107 public function testGetServiceMessageFromOrigin()108 {109 $this->if($this->mockGenerator()->orphanize('__construct'))110 ->and($this->mockClass('\Sly\NotificationPusher\Adapter\Apns', '\Mock'))111 ->and($object = new \Mock\Apns())112 ->and($this->mockGenerator()->orphanize('__construct'))113 ->and($this->mockClass('\Sly\NotificationPusher\Model\Device', '\Mock'))114 ->and($device = new \Mock\Device())115 ->and($device->getMockController()->getToken = self::APNS_TOKEN_EXAMPLE)116 ->and($this->mockGenerator()->orphanize('__construct'))117 ->and($this->mockClass('\Sly\NotificationPusher\Model\Message', '\Mock'))118 ->and($message = new \Mock\Message())119 ->and($message->getMockController()->getText = 'Test')120 ->object($object->getServiceMessageFromOrigin($device, $message))121 ->isInstanceOf('\ZendService\Apple\Apns\Message')122 ;123 }124 public function testPush()125 {126 $this->if($this->mockGenerator()->orphanize('__construct'))127 ->and($this->mockClass('\Sly\NotificationPusher\Adapter\Apns', '\Mock'))128 ->and($object = new \Mock\Apns())129 ->and($this->mockClass('\ZendService\Apple\Apns\Response\Message', '\Mock\ZendService', 'Response'))130 ->and($serviceResponse = new \Mock\ZendService\Response())131 ->and($this->mockGenerator()->orphanize('__construct'))132 ->and($this->mockGenerator()->orphanize('open'))133 ->and($this->mockGenerator()->orphanize('send'))134 ->and($this->mockClass('\ZendService\Apple\Apns\Client\Message', '\Mock\ZendService'))135 ->and($serviceClient = new \Mock\ZendService\Message())136 ->and($serviceClient->getMockController()->send = new $serviceResponse)137 ->and($this->mockGenerator()->orphanize('__construct'))138 ->and($this->mockClass('\Sly\NotificationPusher\Model\Push', '\Mock'))139 ->and($push = new \Mock\Push())140 ->and($push->getMockController()->getMessage = new BaseMessage('Test'))141 ->and($push->getMockController()->getDevices = new BaseDeviceCollection(array(new BaseDevice(self::APNS_TOKEN_EXAMPLE))))142 ->and($object->getMockController()->getServiceMessageFromOrigin = new BaseServiceMessage())143 ->and($object->getMockController()->getOpenedClient = $serviceClient)144 ->object($object->push($push))145 ->isInstanceOf('\Sly\NotificationPusher\Collection\DeviceCollection')146 ->hasSize(1)147 ;148 }149 public function testFeedback()150 {151 $this->if($this->mockGenerator()->orphanize('__construct'))152 ->and($this->mockClass('\Sly\NotificationPusher\Adapter\Apns', '\Mock'))153 ->and($object = new \Mock\Apns())154 ->and($this->mockClass('\ZendService\Apple\Apns\Response\Message', '\Mock\ZendService', 'Response'))155 ->and($serviceResponse = new \Mock\ZendService\Response())156 ->and($this->mockGenerator()->orphanize('__construct'))157 ->and($this->mockGenerator()->orphanize('open'))158 ->and($this->mockGenerator()->orphanize('send'))159 ->and($this->mockClass('\ZendService\Apple\Apns\Client\Feedback', '\Mock\ZendService'))160 ->and($serviceClient = new \Mock\ZendService\Feedback())161 ->and($serviceClient->getMockController()->feedback = $serviceResponse)162 ->and($object->getMockController()->getServiceMessageFromOrigin = new BaseServiceMessage())163 ->and($object->getMockController()->getOpenedClient = $serviceClient)164 ->array($object->getFeedback())165 ->isEmpty()166 ;167 }168}...

Full Screen

Full Screen

__construct

Using AI Code Generation

copy

Full Screen

1$obj = new MockClass();2$obj->method1();3$obj->method2();4$obj->method3();5$obj = new MockClass();6$obj->method1();7$obj->method2();8$obj->method3();9$obj = new MockClass();10$obj->method1();11$obj->method2();12$obj->method3();13Fatal error: Call to undefined method Mockery_0_MockClass::__construct()14$mock = Mockery::mock('MockClass');15$mock->shouldReceive('__construct')->once()->andReturn(true);16$mock->shouldReceive('method1')->once()->andReturn(true);17$mock->shouldReceive('method2')->once()->andReturn(true);18$mock->shouldReceive('method3')->once()->andReturn(true);19$obj = new MockClass();

Full Screen

Full Screen

__construct

Using AI Code Generation

copy

Full Screen

1$mock = new MockClass();2$mock->__construct();3$mock->method1();4$mock->method2();5$mock = new MockClass();6$mock->__construct();7$mock->method1();8$mock->method2();9I am trying to create a mock class in PHP. I want to create a mock class which will contain a method __construct() and two other methods. I want to use this mock class in two php files. I want to use __construct() method of mock class in both the files. I want to use method1() and method2() in file 1 but not in file 2. How can I achieve this? I have tried this but it is not working. I am getting the error "Fatal error: Call to undefined method MockClass::__construct()". Please see the code below:10I am trying to create a mock class in PHP. I want to create a mock class which will contain a method __construct() and two other methods. I want to use this mock class in two php files. I want to use __construct() method of mock class in both the files. I want to use method1() and method2() in file 1 but not in file 2. How can I achieve this? I have tried this but it is not working. I am getting the error "Fatal error: Call to undefined method MockClass::__construct()". Please see the code below:11I am trying to create a mock class in PHP. I want to create a mock class which will contain a method __construct() and two other methods. I want to use this mock class in two php files. I want to use __construct() method of mock class in both the files. I want to use method1() and method2() in file 1 but not in file 2. How can I achieve this? I have tried this but it is not working. I am getting the error "Fatal error: Call to undefined method MockClass::__construct()". Please see the code below:12I am trying to create a mock class in PHP. I want to create a mock class which will contain a method __construct() and two other methods. I want to use this mock class in two php files. I want to use __construct() method of mock class in both the files. I want to use method1()

Full Screen

Full Screen

__construct

Using AI Code Generation

copy

Full Screen

1$obj=new mockClass();2$obj->method1();3$obj->method2();4$obj=new mockClass();5$obj->method1();6$obj->method2();7$obj=new mockClass();8$obj->method1();9$obj->method2();10$obj=new mockClass();11$obj->method1();12$obj->method2();13$obj=new mockClass();14$obj->method1();15$obj->method2();16$obj=new mockClass();17$obj->method1();18$obj->method2();19$obj=new mockClass();20$obj->method1();21$obj->method2();22$obj=new mockClass();23$obj->method1();24$obj->method2();25$obj=new mockClass();26$obj->method1();27$obj->method2();28$obj=new mockClass();29$obj->method1();30$obj->method2();31$obj=new mockClass();32$obj->method1();33$obj->method2();34$obj=new mockClass();35$obj->method1();36$obj->method2();37$obj=new mockClass();38$obj->method1();39$obj->method2();40$obj=new mockClass();41$obj->method1();42$obj->method2();43$obj=new mockClass();44$obj->method1();45$obj->method2();

Full Screen

Full Screen

__construct

Using AI Code Generation

copy

Full Screen

1$obj = new MockClass();2$obj->test();3$obj = new MockClass();4$obj->test();5$obj = new MockClass();6$obj->test();7$obj = new MockClass();8$obj->test();9$obj = new MockClass();10$obj->test();11$obj = new MockClass();12$obj->test();13$obj = new MockClass();14$obj->test();

Full Screen

Full Screen

__construct

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

__construct

Using AI Code Generation

copy

Full Screen

1$mock = new MockClass();2$mock->__construct();3$mock->someMethod();4$mock->someOtherMethod();5Fatal error: Call to undefined method MockClass::__construct()6Your name to display (optional):7Your name to display (optional):8{9 public function testMock()10 {11 $mock = $this->getMockBuilder('ClassToMock')12 ->setMethods(array('someMethod'))13 ->getMock();14 $mock->expects($this->once())15 ->method('someMethod')16 ->will($this->returnValue('foo'));17 $this->assertEquals('foo', $mock->someMethod());18 }19}20Your name to display (optional):

Full Screen

Full Screen

__construct

Using AI Code Generation

copy

Full Screen

1$mock = $this->getMockBuilder('Mock')2 ->setMethods(null)3 ->getMock();4$mock->__construct();5$mock->doSomething();6$mock = $this->getMockBuilder('Mock')7 ->setMethods(null)8 ->getMock();9$mock->__construct();10$mock->doSomething();11$mock = $this->getMockBuilder('Mock')12 ->setMethods(null)13 ->getMock();14$mock->expects($this->exactly(1))15 ->method('__construct')16 ->withConsecutive([[]]);17$mock->__construct();18$mock->doSomething();19$mock = $this->getMockBuilder('Mock')20 ->setMethods(null)21 ->getMock();22$mock->expects($this->exactly(1))23 ->method('__construct')24 ->withConsecutive([[]]);25$mock->__construct();26$mock->doSomething();

Full Screen

Full Screen

Automation Testing Tutorials

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

LambdaTest Learning Hubs:

YouTube

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

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful