/tests/units/classes/mock/generator.php
PHP | 2517 lines | 2493 code | 24 blank | 0 comment | 7 complexity | 527b1da235289d5029b5f1d5b0b4695c MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- <?php
- namespace mageekguy\atoum\tests\units\mock;
- use
- mageekguy\atoum,
- mageekguy\atoum\mock,
- mageekguy\atoum\test\adapter\call\decorators,
- mageekguy\atoum\mock\generator as testedClass
- ;
- require_once __DIR__ . '/../../runner.php';
- class generator extends atoum\test
- {
- public function test__construct()
- {
- $this
- ->if($generator = new testedClass())
- ->then
- ->object($generator->getAdapter())->isEqualTo(new atoum\adapter())
- ->boolean($generator->callsToParentClassAreShunted())->isFalse()
- ;
- }
- public function testSetAdapter()
- {
- $this
- ->if($generator = new testedClass())
- ->then
- ->object($generator->setAdapter($adapter = new atoum\adapter()))->isIdenticalTo($generator)
- ->object($generator->getAdapter())->isIdenticalTo($adapter)
- ->object($generator->setAdapter())->isIdenticalTo($generator)
- ->object($generator->getAdapter())
- ->isInstanceOf('mageekguy\atoum\adapter')
- ->isNotIdenticalTo($adapter)
- ->isEqualTo(new atoum\adapter())
- ;
- }
- public function testSetReflectionClassFactory()
- {
- $this
- ->if($generator = new testedClass())
- ->then
- ->object($generator->setReflectionClassFactory($factory = function() {}))->isIdenticalTo($generator)
- ->object($generator->getReflectionClassFactory())->isIdenticalTo($factory)
- ->object($generator->setReflectionClassFactory())->isIdenticalTo($generator)
- ->object($defaultReflectionClassFactory = $generator->getReflectionClassFactory())
- ->isInstanceOf('closure')
- ->isNotIdenticalTo($factory)
- ->object($defaultReflectionClassFactory($this))->isEqualTo(new \reflectionClass($this))
- ;
- }
- public function testSetDefaultNamespace()
- {
- $this
- ->if($generator = new testedClass())
- ->then
- ->object($generator->setDefaultNamespace($namespace = uniqid()))->isIdenticalTo($generator)
- ->string($generator->getDefaultNamespace())->isEqualTo($namespace)
- ->object($generator->setDefaultNamespace('\\' . $namespace))->isIdenticalTo($generator)
- ->string($generator->getDefaultNamespace())->isEqualTo($namespace)
- ->object($generator->setDefaultNamespace('\\' . $namespace . '\\'))->isIdenticalTo($generator)
- ->string($generator->getDefaultNamespace())->isEqualTo($namespace)
- ->object($generator->setDefaultNamespace($namespace . '\\'))->isIdenticalTo($generator)
- ->string($generator->getDefaultNamespace())->isEqualTo($namespace)
- ;
- }
- public function testShuntCallsToParentClass()
- {
- $this
- ->if($generator = new testedClass())
- ->then
- ->object($generator->shuntParentClassCalls())->isIdenticalTo($generator)
- ->boolean($generator->callsToParentClassAreShunted())->isTrue()
- ;
- }
- public function testUnshuntParentClassCalls()
- {
- $this
- ->if($generator = new testedClass())
- ->then
- ->object($generator->unshuntParentClassCalls())->isIdenticalTo($generator)
- ->boolean($generator->callsToParentClassAreShunted())->isFalse()
- ->if($generator->shuntParentClassCalls())
- ->then
- ->object($generator->unshuntParentClassCalls())->isIdenticalTo($generator)
- ->boolean($generator->callsToParentClassAreShunted())->isFalse()
- ;
- }
- function testAllIsInterface()
- {
- $this
- ->if($generator = new testedClass())
- ->then
- ->object($generator->allIsInterface())->isIdenticalTo($generator)
- ;
- }
- function testTestedClassIs()
- {
- $this
- ->if($generator = new testedClass())
- ->then
- ->object($generator->testedClassIs(uniqid()))->isIdenticalTo($generator)
- ;
- }
- public function testOverload()
- {
- $this
- ->if($generator = new testedClass())
- ->then
- ->object($generator->overload(new mock\php\method($method = uniqid())))->isIdenticalTo($generator)
- ->boolean($generator->isOverloaded($method))->isTrue()
- ;
- }
- public function testIsOverloaded()
- {
- $this
- ->if($generator = new testedClass())
- ->then
- ->boolean($generator->isOverloaded(uniqid()))->isFalse()
- ->if($generator->overload(new mock\php\method($method = uniqid())))
- ->then
- ->boolean($generator->isOverloaded($method))->isTrue()
- ;
- }
- public function testGetOverload()
- {
- $this
- ->if($generator = new testedClass())
- ->then
- ->variable($generator->getOverload(uniqid()))->isNull()
- ->if($generator->overload($overload = new mock\php\method(uniqid())))
- ->then
- ->object($generator->getOverload($overload->getName()))->isIdenticalTo($overload)
- ;
- }
- public function testShunt()
- {
- $this
- ->if($generator = new testedClass())
- ->then
- ->object($generator->shunt($method = uniqid()))->isIdenticalTo($generator)
- ->boolean($generator->isShunted($method))->isTrue()
- ->boolean($generator->isShunted(strtoupper($method)))->isTrue()
- ->boolean($generator->isShunted(strtolower($method)))->isTrue()
- ->boolean($generator->isShunted(uniqid()))->isFalse()
- ;
- }
- public function testDisallowUndefinedMethodUsage()
- {
- $this
- ->if($generator = new testedClass())
- ->then
- ->object($generator->disallowUndefinedMethodUsage())->isIdenticalTo($generator)
- ;
- }
- public function testOrphanize()
- {
- $this
- ->if($generator = new testedClass())
- ->then
- ->object($generator->orphanize($method = uniqid()))->isIdenticalTo($generator)
- ->boolean($generator->isOrphanized($method))->isTrue()
- ->boolean($generator->isShunted($method))->isTrue()
- ;
- }
- public function testGetMockedClassCodeForUnknownClass()
- {
- $this
- ->if($generator = new testedClass())
- ->and($adapter = new atoum\test\adapter())
- ->and($adapter->class_exists = false)
- ->and($generator->setAdapter($adapter))
- ->then
- ->string($generator->getMockedClassCode($unknownClass = uniqid()))->isEqualTo(
- 'namespace mock {' . PHP_EOL .
- 'final class ' . $unknownClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .
- '{' . PHP_EOL .
- $this->getMockControllerMethods() .
- "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .
- "\t" . '{' . PHP_EOL .
- "\t\t" . 'if ($mockController === null)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . 'if ($mockController !== null)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . '$this->getMockController()->disableMethodChecking();' . PHP_EOL .
- "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t" . '}' . PHP_EOL .
- "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .
- "\t" . '{' . PHP_EOL .
- "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$return = $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .
- "\t\t\t" . 'return $return;' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . 'else' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t" . '}' . PHP_EOL .
- "\t" . 'public static function getMockedMethods()' . PHP_EOL .
- "\t" . '{' . PHP_EOL .
- "\t\t" . 'return ' . var_export(array('__call'), true) . ';' . PHP_EOL .
- "\t" . '}' . PHP_EOL .
- '}' . PHP_EOL .
- '}'
- )
- ->if($unknownClass = __NAMESPACE__ . '\dummy')
- ->and($generator->generate($unknownClass))
- ->and($mockedUnknownClass = '\mock\\' . $unknownClass)
- ->and($dummy = new $mockedUnknownClass())
- ->and($dummyController = new atoum\mock\controller())
- ->and($dummyController->notControlNextNewMock())
- ->and($calls = new \mock\mageekguy\atoum\test\adapter\calls())
- ->and($dummyController->setCalls($calls))
- ->and($dummyController->control($dummy))
- ->then
- ->when(function() use ($dummy) { $dummy->bar(); })
- ->mock($calls)->call('addCall')->withArguments(new atoum\test\adapter\call('bar', array(), new decorators\addClass($dummy)))->once()
- ->when(function() use ($dummy) { $dummy->bar(); })
- ->mock($calls)->call('addCall')->withArguments(new atoum\test\adapter\call('bar', array(), new decorators\addClass($dummy)))->twice()
- ;
- }
- public function testGetMockedClassCodeForRealClass()
- {
- $this
- ->if($generator = new testedClass())
- ->and($reflectionMethodController = new mock\controller())
- ->and($reflectionMethodController->__construct = function() {})
- ->and($reflectionMethodController->getName = '__construct')
- ->and($reflectionMethodController->isConstructor = true)
- ->and($reflectionMethodController->getParameters = array())
- ->and($reflectionMethodController->isPublic = true)
- ->and($reflectionMethodController->isProtected = false)
- ->and($reflectionMethodController->isPrivate = false)
- ->and($reflectionMethodController->isFinal = false)
- ->and($reflectionMethodController->isStatic = false)
- ->and($reflectionMethodController->isAbstract = false)
- ->and($reflectionMethodController->returnsReference = false)
- ->and($reflectionMethod = new \mock\reflectionMethod(null, null))
- ->and($reflectionClassController = new mock\controller())
- ->and($reflectionClassController->__construct = function() {})
- ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })
- ->and($reflectionClassController->isFinal = false)
- ->and($reflectionClassController->isInterface = false)
- ->and($reflectionClassController->isAbstract = false)
- ->and($reflectionClassController->getMethods = array($reflectionMethod))
- ->and($reflectionClassController->getConstructor = $reflectionMethod)
- ->and($reflectionClass = new \mock\reflectionClass(null))
- ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))
- ->and($adapter = new atoum\test\adapter())
- ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })
- ->and($generator->setAdapter($adapter))
- ->then
- ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(
- 'namespace mock {' . PHP_EOL .
- 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .
- '{' . PHP_EOL .
- $this->getMockControllerMethods() .
- "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .
- "\t" . '{' . PHP_EOL .
- "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .
- "\t\t" . 'if ($mockController === null)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . 'if ($mockController !== null)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . 'else' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$this->getMockController()->addCall(\'__construct\', $arguments);' . PHP_EOL .
- "\t\t\t" . 'call_user_func_array(\'parent::__construct\', $arguments);' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t" . '}' . PHP_EOL .
- "\t" . 'public static function getMockedMethods()' . PHP_EOL .
- "\t" . '{' . PHP_EOL .
- "\t\t" . 'return ' . var_export(array('__construct'), true) . ';' . PHP_EOL .
- "\t" . '}' . PHP_EOL .
- '}' . PHP_EOL .
- '}'
- )
- ;
- }
- public function testGetMockedClassCodeForRealClassWithDeprecatedConstructor()
- {
- $this
- ->if($generator = new testedClass())
- ->and($reflectionMethodController = new mock\controller())
- ->and($reflectionMethodController->__construct = function() {})
- ->and($reflectionMethodController->getName = $realClass = uniqid())
- ->and($reflectionMethodController->isConstructor = true)
- ->and($reflectionMethodController->getParameters = array())
- ->and($reflectionMethodController->isPublic = true)
- ->and($reflectionMethodController->isProtected = false)
- ->and($reflectionMethodController->isPrivate = false)
- ->and($reflectionMethodController->isFinal = false)
- ->and($reflectionMethodController->isStatic = false)
- ->and($reflectionMethodController->isAbstract = false)
- ->and($reflectionMethodController->returnsReference = false)
- ->and($reflectionMethod = new \mock\reflectionMethod(null, null))
- ->and($reflectionClassController = new mock\controller())
- ->and($reflectionClassController->__construct = function() {})
- ->and($reflectionClassController->getName = $realClass)
- ->and($reflectionClassController->isFinal = false)
- ->and($reflectionClassController->isInterface = false)
- ->and($reflectionClassController->isAbstract = false)
- ->and($reflectionClassController->getMethods = array($reflectionMethod))
- ->and($reflectionClassController->getConstructor = $reflectionMethod)
- ->and($reflectionClass = new \mock\reflectionClass(null))
- ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))
- ->and($adapter = new atoum\test\adapter())
- ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })
- ->and($generator->setAdapter($adapter))
- ->then
- ->string($generator->getMockedClassCode($realClass))->isEqualTo(
- 'namespace mock {' . PHP_EOL .
- 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .
- '{' . PHP_EOL .
- $this->getMockControllerMethods() .
- "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .
- "\t" . '{' . PHP_EOL .
- "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .
- "\t\t" . 'if ($mockController === null)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . 'if ($mockController !== null)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . 'if (isset($this->getMockController()->' . $realClass . ') === true)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$this->getMockController()->invoke(\'' . $realClass . '\', $arguments);' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . 'else' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$this->getMockController()->addCall(\'' . $realClass . '\', $arguments);' . PHP_EOL .
- "\t\t\t" . 'call_user_func_array(\'parent::' . $realClass . '\', $arguments);' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t" . '}' . PHP_EOL .
- "\t" . 'public static function getMockedMethods()' . PHP_EOL .
- "\t" . '{' . PHP_EOL .
- "\t\t" . 'return ' . var_export(array($realClass), true) . ';' . PHP_EOL .
- "\t" . '}' . PHP_EOL .
- '}' . PHP_EOL .
- '}'
- )
- ;
- }
- public function testGetMockedClassCodeForRealClassWithCallsToParentClassShunted()
- {
- $this
- ->if($generator = new testedClass())
- ->and($reflectionMethodController = new mock\controller())
- ->and($reflectionMethodController->__construct = function() {})
- ->and($reflectionMethodController->getName = '__construct')
- ->and($reflectionMethodController->isConstructor = true)
- ->and($reflectionMethodController->getParameters = array())
- ->and($reflectionMethodController->isPublic = true)
- ->and($reflectionMethodController->isProtected = false)
- ->and($reflectionMethodController->isPrivate = false)
- ->and($reflectionMethodController->isFinal = false)
- ->and($reflectionMethodController->isStatic = false)
- ->and($reflectionMethodController->isAbstract = false)
- ->and($reflectionMethodController->returnsReference = false)
- ->and($reflectionMethod = new \mock\reflectionMethod(null, null))
- ->and($otherReflectionMethodController = new mock\controller())
- ->and($otherReflectionMethodController->__construct = function() {})
- ->and($otherReflectionMethodController->getName = $otherMethod = uniqid())
- ->and($otherReflectionMethodController->isConstructor = false)
- ->and($otherReflectionMethodController->getParameters = array())
- ->and($otherReflectionMethodController->isPublic = true)
- ->and($otherReflectionMethodController->isProtected = false)
- ->and($otherReflectionMethodController->isPrivate = false)
- ->and($otherReflectionMethodController->isFinal = false)
- ->and($otherReflectionMethodController->isStatic = false)
- ->and($otherReflectionMethodController->isAbstract = false)
- ->and($otherReflectionMethodController->returnsReference = false)
- ->and($otherReflectionMethod = new \mock\reflectionMethod(null, null))
- ->and($reflectionClassController = new mock\controller())
- ->and($reflectionClassController->__construct = function() {})
- ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })
- ->and($reflectionClassController->isFinal = false)
- ->and($reflectionClassController->isInterface = false)
- ->and($reflectionClassController->isAbstract = false)
- ->and($reflectionClassController->getMethods = array($reflectionMethod, $otherReflectionMethod))
- ->and($reflectionClassController->getConstructor = $reflectionMethod)
- ->and($reflectionClass = new \mock\reflectionClass(null))
- ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))
- ->and($adapter = new atoum\test\adapter())
- ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })
- ->and($generator->setAdapter($adapter))
- ->and($generator->shuntParentClassCalls())
- ->then
- ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(
- 'namespace mock {' . PHP_EOL .
- 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .
- '{' . PHP_EOL .
- $this->getMockControllerMethods() .
- "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .
- "\t" . '{' . PHP_EOL .
- "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .
- "\t\t" . 'if ($mockController === null)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . 'if ($mockController !== null)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . 'else' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$this->getMockController()->addCall(\'__construct\', $arguments);' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t" . '}' . PHP_EOL .
- "\t" . 'public function ' . $otherMethod . '()' . PHP_EOL .
- "\t" . '{' . PHP_EOL .
- "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .
- "\t\t" . 'if (isset($this->getMockController()->' . $otherMethod . ') === true)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$return = $this->getMockController()->invoke(\'' . $otherMethod . '\', $arguments);' . PHP_EOL .
- "\t\t\t" . 'return $return;' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . 'else' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$this->getMockController()->addCall(\'' . $otherMethod . '\', $arguments);' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t" . '}' . PHP_EOL .
- "\t" . 'public static function getMockedMethods()' . PHP_EOL .
- "\t" . '{' . PHP_EOL .
- "\t\t" . 'return ' . var_export(array('__construct', $otherMethod), true) . ';' . PHP_EOL .
- "\t" . '}' . PHP_EOL .
- '}' . PHP_EOL .
- '}'
- )
- ;
- }
- public function testGetMockedClassCodeWithOverloadMethod()
- {
- $this
- ->if($generator = new testedClass())
- ->and($reflectionMethodController = new mock\controller())
- ->and($reflectionMethodController->__construct = function() {})
- ->and($reflectionMethodController->getName = '__construct')
- ->and($reflectionMethodController->isConstructor = true)
- ->and($reflectionMethodController->getParameters = array())
- ->and($reflectionMethodController->isPublic = true)
- ->and($reflectionMethodController->isProtected = false)
- ->and($reflectionMethodController->isPrivate = false)
- ->and($reflectionMethodController->isFinal = false)
- ->and($reflectionMethodController->isAbstract = false)
- ->and($reflectionMethodController->isStatic = false)
- ->and($reflectionMethodController->returnsReference = false)
- ->and($reflectionMethod = new \mock\reflectionMethod(null, null))
- ->and($reflectionClassController = new mock\controller())
- ->and($reflectionClassController->__construct = function() {})
- ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })
- ->and($reflectionClassController->isFinal = false)
- ->and($reflectionClassController->isInterface = false)
- ->and($reflectionClassController->getMethods = array($reflectionMethod))
- ->and($reflectionClassController->getConstructor = $reflectionMethod)
- ->and($reflectionClassController->isAbstract = false)
- ->and($reflectionClass = new \mock\reflectionClass(null))
- ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))
- ->and($adapter = new atoum\test\adapter())
- ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })
- ->and($generator->setAdapter($adapter))
- ->and($overloadedMethod = new mock\php\method('__construct'))
- ->and($overloadedMethod->addArgument($argument = new mock\php\method\argument(uniqid())))
- ->and($generator->overload($overloadedMethod))
- ->then
- ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(
- 'namespace mock {' . PHP_EOL .
- 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .
- '{' . PHP_EOL .
- $this->getMockControllerMethods() .
- "\t" . '' . $overloadedMethod . PHP_EOL .
- "\t" . '{' . PHP_EOL .
- "\t\t" . '$arguments = array_merge(array(' . $argument . '), array_slice(func_get_args(), 1, -1));' . PHP_EOL .
- "\t\t" . 'if ($mockController === null)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . 'if ($mockController !== null)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . 'else' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$this->getMockController()->addCall(\'__construct\', $arguments);' . PHP_EOL .
- "\t\t\t" . 'call_user_func_array(\'parent::__construct\', $arguments);' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t" . '}' . PHP_EOL .
- "\t" . 'public static function getMockedMethods()' . PHP_EOL .
- "\t" . '{' . PHP_EOL .
- "\t\t" . 'return ' . var_export(array('__construct'), true) . ';' . PHP_EOL .
- "\t" . '}' . PHP_EOL .
- '}' . PHP_EOL .
- '}'
- )
- ;
- }
- public function testGetMockedClassCodeWithAbstractMethod()
- {
- $this
- ->if($generator = new testedClass())
- ->and($realClass = uniqid())
- ->and($reflectionMethodController = new mock\controller())
- ->and($reflectionMethodController->__construct = function() {})
- ->and($reflectionMethodController->getName = function() { return '__construct'; })
- ->and($reflectionMethodController->isConstructor = true)
- ->and($reflectionMethodController->getParameters = array())
- ->and($reflectionMethodController->isPublic = true)
- ->and($reflectionMethodController->isProtected = false)
- ->and($reflectionMethodController->isPrivate = false)
- ->and($reflectionMethodController->isFinal = false)
- ->and($reflectionMethodController->isStatic = false)
- ->and($reflectionMethodController->isAbstract = true)
- ->and($reflectionMethodController->returnsReference = false)
- ->and($reflectionMethod = new \mock\reflectionMethod(null, null))
- ->and($reflectionClassController = new mock\controller())
- ->and($reflectionClassController->__construct = function() {})
- ->and($reflectionClassController->getName = function() use ($realClass) { return $realClass; })
- ->and($reflectionClassController->isFinal = false)
- ->and($reflectionClassController->isInterface = false)
- ->and($reflectionClassController->getMethods = array($reflectionMethod))
- ->and($reflectionClassController->getConstructor = $reflectionMethod)
- ->and($reflectionClassController->isAbstract = false)
- ->and($reflectionClass = new \mock\reflectionClass(null))
- ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))
- ->and($adapter = new atoum\test\adapter())
- ->and($adapter->class_exists = function($class) use ($realClass) { return ($class == '\\' . $realClass); })
- ->and($generator->setAdapter($adapter))
- ->then
- ->string($generator->getMockedClassCode($realClass))->isEqualTo(
- 'namespace mock {' . PHP_EOL .
- 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .
- '{' . PHP_EOL .
- $this->getMockControllerMethods() .
- "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .
- "\t" . '{' . PHP_EOL .
- "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .
- "\t\t" . 'if ($mockController === null)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . 'if ($mockController !== null)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .
- "\t" . '}' . PHP_EOL .
- "\t" . 'public static function getMockedMethods()' . PHP_EOL .
- "\t" . '{' . PHP_EOL .
- "\t\t" . 'return ' . var_export(array('__construct'), true) . ';' . PHP_EOL .
- "\t" . '}' . PHP_EOL .
- '}' . PHP_EOL .
- '}'
- )
- ;
- }
- public function testGetMockedClassCodeWithShuntedMethod()
- {
- $this
- ->if($generator = new testedClass())
- ->and($realClass = uniqid())
- ->and($reflectionMethodController = new mock\controller())
- ->and($reflectionMethodController->__construct = function() {})
- ->and($reflectionMethodController->getName = function() { return '__construct'; })
- ->and($reflectionMethodController->isConstructor = true)
- ->and($reflectionMethodController->isAbstract = false)
- ->and($reflectionMethodController->getParameters = array())
- ->and($reflectionMethodController->isPublic = true)
- ->and($reflectionMethodController->isProtected = false)
- ->and($reflectionMethodController->isPrivate = false)
- ->and($reflectionMethodController->isFinal = false)
- ->and($reflectionMethodController->isStatic = false)
- ->and($reflectionMethodController->returnsReference = false)
- ->and($reflectionMethod = new \mock\reflectionMethod(null, null))
- ->and($reflectionClassController = new mock\controller())
- ->and($reflectionClassController->__construct = function() {})
- ->and($reflectionClassController->getName = function() use ($realClass) { return $realClass; })
- ->and($reflectionClassController->isFinal = false)
- ->and($reflectionClassController->isInterface = false)
- ->and($reflectionClassController->getMethods = array($reflectionMethod))
- ->and($reflectionClassController->getConstructor = $reflectionMethod)
- ->and($reflectionClassController->isAbstract = false)
- ->and($reflectionClass = new \mock\reflectionClass(null))
- ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))
- ->and($adapter = new atoum\test\adapter())
- ->and($adapter->class_exists = function($class) use ($realClass) { return ($class == '\\' . $realClass); })
- ->and($generator->setAdapter($adapter))
- ->and($generator->shunt('__construct'))
- ->then
- ->string($generator->getMockedClassCode($realClass))->isEqualTo(
- 'namespace mock {' . PHP_EOL .
- 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .
- '{' . PHP_EOL .
- $this->getMockControllerMethods() .
- "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .
- "\t" . '{' . PHP_EOL .
- "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .
- "\t\t" . 'if ($mockController === null)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . 'if ($mockController !== null)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .
- "\t" . '}' . PHP_EOL .
- "\t" . 'public static function getMockedMethods()' . PHP_EOL .
- "\t" . '{' . PHP_EOL .
- "\t\t" . 'return ' . var_export(array('__construct'), true) . ';' . PHP_EOL .
- "\t" . '}' . PHP_EOL .
- '}' . PHP_EOL .
- '}'
- )
- ;
- }
- public function testGetMockedClassCodeWithAllIsInterface()
- {
- $this
- ->if($generator = new testedClass())
- ->and($realClass = uniqid())
- ->and($reflectionMethodController = new mock\controller())
- ->and($reflectionMethodController->__construct = function() {})
- ->and($reflectionMethodController->getName = 'foo')
- ->and($reflectionMethodController->isConstructor = false)
- ->and($reflectionMethodController->getParameters = array())
- ->and($reflectionMethodController->isPublic = true)
- ->and($reflectionMethodController->isProtected = false)
- ->and($reflectionMethodController->isPrivate = false)
- ->and($reflectionMethodController->isFinal = false)
- ->and($reflectionMethodController->isAbstract = false)
- ->and($reflectionMethodController->isStatic = false)
- ->and($reflectionMethodController->returnsReference = false)
- ->and($reflectionMethod = new \mock\reflectionMethod(null, null))
- ->and($reflectionClassController = new mock\controller())
- ->and($reflectionClassController->__construct = function() {})
- ->and($reflectionClassController->getName = function() use ($realClass) { return $realClass; })
- ->and($reflectionClassController->isFinal = false)
- ->and($reflectionClassController->isInterface = false)
- ->and($reflectionClassController->getMethods = array($reflectionMethod))
- ->and($reflectionClassController->getConstructor = null)
- ->and($reflectionClassController->isAbstract = false)
- ->and($reflectionClass = new \mock\reflectionClass(null))
- ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))
- ->and($adapter = new atoum\test\adapter())
- ->and($adapter->class_exists = function($class) use ($realClass) { return ($class == '\\' . $realClass); })
- ->and($generator->setAdapter($adapter))
- ->and($generator->shunt('__construct'))
- ->and($generator->allIsInterface())
- ->then
- ->string($generator->getMockedClassCode($realClass))->isEqualTo(
- 'namespace mock {' . PHP_EOL .
- 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .
- '{' . PHP_EOL .
- $this->getMockControllerMethods() .
- "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .
- "\t" . '{' . PHP_EOL .
- "\t\t" . 'if ($mockController === null)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . 'if ($mockController !== null)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t" . '}' . PHP_EOL .
- "\t" . 'public function foo()' . PHP_EOL .
- "\t" . '{' . PHP_EOL .
- "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .
- "\t\t" . 'if (isset($this->getMockController()->foo) === false)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$this->getMockController()->foo = function() {};' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . '$return = $this->getMockController()->invoke(\'foo\', $arguments);' . PHP_EOL .
- "\t\t" . 'return $return;' . PHP_EOL .
- "\t" . '}' . PHP_EOL .
- "\t" . 'public static function getMockedMethods()' . PHP_EOL .
- "\t" . '{' . PHP_EOL .
- "\t\t" . 'return ' . var_export(array('__construct', 'foo'), true) . ';' . PHP_EOL .
- "\t" . '}' . PHP_EOL .
- '}' . PHP_EOL .
- '}'
- )
- ->if($generator->testedClassIs($realClass))
- ->then
- ->string($generator->getMockedClassCode($realClass))->isEqualTo(
- 'namespace mock {' . PHP_EOL .
- 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .
- '{' . PHP_EOL .
- $this->getMockControllerMethods() .
- "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .
- "\t" . '{' . PHP_EOL .
- "\t\t" . 'if ($mockController === null)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . 'if ($mockController !== null)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t" . '}' . PHP_EOL .
- "\t" . 'public function foo()' . PHP_EOL .
- "\t" . '{' . PHP_EOL .
- "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .
- "\t\t" . 'if (isset($this->getMockController()->foo) === true)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$return = $this->getMockController()->invoke(\'foo\', $arguments);' . PHP_EOL .
- "\t\t\t" . 'return $return;' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . 'else' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$this->getMockController()->addCall(\'foo\', $arguments);' . PHP_EOL .
- "\t\t\t" . '$return = call_user_func_array(\'parent::foo\', $arguments);' . PHP_EOL .
- "\t\t\t" . 'return $return;' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t" . '}' . PHP_EOL .
- "\t" . 'public static function getMockedMethods()' . PHP_EOL .
- "\t" . '{' . PHP_EOL .
- "\t\t" . 'return ' . var_export(array('__construct', 'foo'), true) . ';' . PHP_EOL .
- "\t" . '}' . PHP_EOL .
- '}' . PHP_EOL .
- '}'
- )
- ;
- }
- public function testGetMockedClassCodeWithCloneMethod()
- {
- $this
- ->if($generator = new testedClass())
- ->and($realClass = uniqid())
- ->and($reflectionMethodController = new mock\controller())
- ->and($reflectionMethodController->__construct = function() {})
- ->and($reflectionMethodController->getName = 'clone')
- ->and($reflectionMethodController->isConstructor = false)
- ->and($reflectionMethodController->isAbstract = false)
- ->and($reflectionMethodController->getParameters = array())
- ->and($reflectionMethodController->isPublic = true)
- ->and($reflectionMethodController->isProtected = false)
- ->and($reflectionMethodController->isPrivate = false)
- ->and($reflectionMethodController->isFinal = false)
- ->and($reflectionMethodController->isStatic = false)
- ->and($reflectionMethodController->returnsReference = false)
- ->and($reflectionMethod = new \mock\reflectionMethod(null, null))
- ->and($reflectionClassController = new mock\controller())
- ->and($reflectionClassController->__construct = function() {})
- ->and($reflectionClassController->getName = $realClass)
- ->and($reflectionClassController->isFinal = false)
- ->and($reflectionClassController->isInterface = false)
- ->and($reflectionClassController->getMethods = array($reflectionMethod))
- ->and($reflectionClassController->getConstructor = null)
- ->and($reflectionClassController->isAbstract = false)
- ->and($reflectionClass = new \mock\reflectionClass(null))
- ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))
- ->and($adapter = new atoum\test\adapter())
- ->and($adapter->class_exists = function($class) use ($realClass) { return ($class == '\\' . $realClass); })
- ->and($generator->setAdapter($adapter))
- ->then
- ->string($generator->getMockedClassCode($realClass))->isEqualTo(
- 'namespace mock {' . PHP_EOL .
- 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .
- '{' . PHP_EOL .
- $this->getMockControllerMethods() .
- "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .
- "\t" . '{' . PHP_EOL .
- "\t\t" . 'if ($mockController === null)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . 'if ($mockController !== null)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . 'if (isset($this->getMockController()->__construct) === true)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$this->getMockController()->invoke(\'__construct\', func_get_args());' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t" . '}' . PHP_EOL .
- "\t" . 'public static function getMockedMethods()' . PHP_EOL .
- "\t" . '{' . PHP_EOL .
- "\t\t" . 'return ' . var_export(array('__construct'), true) . ';' . PHP_EOL .
- "\t" . '}' . PHP_EOL .
- '}' . PHP_EOL .
- '}'
- )
- ;
- }
- public function testGetMockedClassCodeWithShuntedDeprecatedConstructor()
- {
- $this
- ->if($generator = new testedClass())
- ->and($reflectionMethodController = new mock\controller())
- ->and($reflectionMethodController->__construct = function() {})
- ->and($reflectionMethodController->getName = $realClass = uniqid())
- ->and($reflectionMethodController->isConstructor = true)
- ->and($reflectionMethodController->isAbstract = false)
- ->and($reflectionMethodController->getParameters = array())
- ->and($reflectionMethodController->isPublic = true)
- ->and($reflectionMethodController->isProtected = false)
- ->and($reflectionMethodController->isPrivate = false)
- ->and($reflectionMethodController->isFinal = false)
- ->and($reflectionMethodController->isStatic = false)
- ->and($reflectionMethodController->returnsReference = false)
- ->and($reflectionMethod = new \mock\reflectionMethod(null, null))
- ->and($reflectionClassController = new mock\controller())
- ->and($reflectionClassController->__construct = function() {})
- ->and($reflectionClassController->getName = $realClass)
- ->and($reflectionClassController->isFinal = false)
- ->and($reflectionClassController->isInterface = false)
- ->and($reflectionClassController->getMethods = array($reflectionMethod))
- ->and($reflectionClassController->getConstructor = $reflectionMethod)
- ->and($reflectionClassController->isAbstract = false)
- ->and($reflectionClass = new \mock\reflectionClass(null))
- ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))
- ->and($adapter = new atoum\test\adapter())
- ->and($adapter->class_exists = function($class) use ($realClass) { return ($class == '\\' . $realClass); })
- ->and($generator->setAdapter($adapter))
- ->and($generator->shunt($realClass))
- ->then
- ->string($generator->getMockedClassCode($realClass))->isEqualTo(
- 'namespace mock {' . PHP_EOL .
- 'final class ' . $realClass . ' extends \\' . $realClass . ' implements \mageekguy\atoum\mock\aggregator' . PHP_EOL .
- '{' . PHP_EOL .
- $this->getMockControllerMethods() .
- "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .
- "\t" . '{' . PHP_EOL .
- "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .
- "\t\t" . 'if ($mockController === null)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . 'if ($mockController !== null)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . 'if (isset($this->getMockController()->' . $realClass . ') === false)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$this->getMockController()->' . $realClass . ' = function() {};' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . '$this->getMockController()->invoke(\'' . $realClass . '\', $arguments);' . PHP_EOL .
- "\t" . '}' . PHP_EOL .
- "\t" . 'public static function getMockedMethods()' . PHP_EOL .
- "\t" . '{' . PHP_EOL .
- "\t\t" . 'return ' . var_export(array($realClass), true) . ';' . PHP_EOL .
- "\t" . '}' . PHP_EOL .
- '}' . PHP_EOL .
- '}'
- )
- ;
- }
- public function testGetMockedClassCodeForInterface()
- {
- $this
- ->if($generator = new testedClass())
- ->and($reflectionMethodController = new mock\controller())
- ->and($reflectionMethodController->__construct = function() {})
- ->and($reflectionMethodController->getName = '__construct')
- ->and($reflectionMethodController->isConstructor = true)
- ->and($reflectionMethodController->getParameters = array())
- ->and($reflectionMethodController->isFinal = false)
- ->and($reflectionMethodController->isStatic = false)
- ->and($reflectionMethodController->returnsReference = false)
- ->and($reflectionMethod = new \mock\reflectionMethod(null, null))
- ->and($reflectionClassController = new mock\controller())
- ->and($reflectionClassController->__construct = function() {})
- ->and($reflectionClassController->getName = function() use (& $realClass) { return $realClass; })
- ->and($reflectionClassController->isFinal = false)
- ->and($reflectionClassController->isInterface = true)
- ->and($reflectionClassController->getMethods = array($reflectionMethod))
- ->and($reflectionClassController->isInstantiable = false)
- ->and($reflectionClassController->implementsInterface = false)
- ->and($reflectionClass = new \mock\reflectionClass(null))
- ->and($generator->setReflectionClassFactory(function() use ($reflectionClass) { return $reflectionClass; }))
- ->and($adapter = new atoum\test\adapter())
- ->and($adapter->class_exists = function($class) use (& $realClass) { return ($class == '\\' . $realClass); })
- ->and($generator->setAdapter($adapter))
- ->then
- ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(
- 'namespace mock {' . PHP_EOL .
- 'final class ' . $realClass . ' implements \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .
- '{' . PHP_EOL .
- $this->getMockControllerMethods() .
- "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .
- "\t" . '{' . PHP_EOL .
- "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .
- "\t\t" . 'if ($mockController === null)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . 'if ($mockController !== null)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .
- "\t" . '}' . PHP_EOL .
- "\t" . 'public function __call($methodName, $arguments)' . PHP_EOL .
- "\t" . '{' . PHP_EOL .
- "\t\t" . 'if (isset($this->getMockController()->{$methodName}) === true)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$return = $this->getMockController()->invoke($methodName, $arguments);' . PHP_EOL .
- "\t\t\t" . 'return $return;' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . 'else' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$this->getMockController()->addCall($methodName, $arguments);' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t" . '}' . PHP_EOL .
- "\t" . 'public static function getMockedMethods()' . PHP_EOL .
- "\t" . '{' . PHP_EOL .
- "\t\t" . 'return ' . var_export(array('__construct', '__call'), true) . ';' . PHP_EOL .
- "\t" . '}' . PHP_EOL .
- '}' . PHP_EOL .
- '}'
- )
- ->if($reflectionClassController->implementsInterface = function($interface) { return ($interface == 'traversable' ? true : false); })
- ->and($generator->setReflectionClassFactory(function($class) use ($reflectionClass) { return ($class == 'iteratorAggregate' ? new \reflectionClass('iteratorAggregate') : $reflectionClass); }))
- ->then
- ->string($generator->getMockedClassCode($realClass = uniqid()))->isEqualTo(
- 'namespace mock {' . PHP_EOL .
- 'final class ' . $realClass . ' implements \\iteratorAggregate, \\' . $realClass . ', \mageekguy\atoum\mock\aggregator' . PHP_EOL .
- '{' . PHP_EOL .
- $this->getMockControllerMethods() .
- "\t" . 'public function __construct(\mageekguy\atoum\mock\controller $mockController = null)' . PHP_EOL .
- "\t" . '{' . PHP_EOL .
- "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0, -1));' . PHP_EOL .
- "\t\t" . 'if ($mockController === null)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$mockController = \mageekguy\atoum\mock\controller::get();' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . 'if ($mockController !== null)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$this->setMockController($mockController);' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . 'if (isset($this->getMockController()->__construct) === false)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$this->getMockController()->__construct = function() {};' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . '$this->getMockController()->invoke(\'__construct\', $arguments);' . PHP_EOL .
- "\t" . '}' . PHP_EOL .
- "\t" . 'public function getIterator()' . PHP_EOL .
- "\t" . '{' . PHP_EOL .
- "\t\t" . '$arguments = array_merge(array(), array_slice(func_get_args(), 0));' . PHP_EOL .
- "\t\t" . 'if (isset($this->getMockController()->getIterator) === false)' . PHP_EOL .
- "\t\t" . '{' . PHP_EOL .
- "\t\t\t" . '$this->getMockController()->getIterator = function() {};' . PHP_EOL .
- "\t\t" . '}' . PHP_EOL .
- "\t\t" . '$return = $this->getMockController()->invoke(\'getIterator\', $arguments);' . PHP_EOL .
- "\t\t" . 'return $return;' . PHP_EOL .
- "\t" . '}' . PHP_EOL .
- "\t" . 'public fu…
Large files files are truncated, but you can click here to view the full file