notControlNextNewMock() публичный Метод

Пример #1
0
 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();
 }
Пример #2
0
 public function testNotControlNextNewMock()
 {
     $this->if($mockController = new testedClass())->and($mockController->controlNextNewMock())->then->object($mockController->notControlNextNewMock())->isIdenticalTo($mockController)->variable(testedClass::get())->isNull()->if($mockController = new testedClass())->and($otherMockController = new testedClass())->and($otherMockController->controlNextNewMock())->then->object($mockController->notControlNextNewMock())->isIdenticalTo($mockController)->object(testedClass::get())->isIdenticalTo($otherMockController);
 }
Пример #3
0
 public function testInvoke()
 {
     $this->if($calls = new \mock\mageekguy\atoum\test\adapter\calls())->and($mockController = new testedClass())->and($mockController->notControlNextNewMock())->and($mockController->setCalls($calls))->and($method = uniqid())->then->exception(function () use($mockController, $method) {
         $mockController->invoke($method, array());
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Method ' . $method . '() is not under control')->if($return = uniqid())->and($mockController->test = function () use($return) {
         return $return;
     })->and($argument1 = uniqid())->and($argument2 = uniqid())->and($argument3 = uniqid())->then->string($mockController->invoke('test'))->isEqualTo($return)->mock($calls)->call('addCall')->withArguments(new adapter\call('test', array()))->once()->string($mockController->invoke('test', array($argument1)))->isEqualTo($return)->mock($calls)->call('addCall')->withArguments(new adapter\call('test', array($argument1)))->once()->string($mockController->invoke('test', array($argument1, $argument2)))->isEqualTo($return)->mock($calls)->call('addCall')->withArguments(new adapter\call('test', array($argument1, $argument2)))->once()->string($mockController->invoke('test', array($argument1, $argument2, $argument3)))->isEqualTo($return)->mock($calls)->call('addCall')->withArguments(new adapter\call('test', array($argument1, $argument2, $argument3)))->once()->if($mockController->test2 = function () use($return) {
         return $return;
     })->then->string($mockController->invoke('test2', array($argument1)))->isEqualTo($return)->mock($calls)->call('addCall')->withArguments(new adapter\call('test2', array($argument1)))->once()->string($mockController->invoke('test2', array($argument1, $argument2)))->isEqualTo($return)->mock($calls)->call('addCall')->withArguments(new adapter\call('test2', array($argument1, $argument2)))->once()->string($mockController->invoke('test2', array($argument1, $argument2, $argument3)))->isEqualTo($return)->mock($calls)->call('addCall')->withArguments(new adapter\call('test2', array($argument1, $argument2, $argument3)))->once()->if($mockController = new testedClass())->and($mockController->control($mock = new \mock\mageekguy\atoum\tests\units\mock\bar()))->then->exception(function () use($mockController) {
         $mockController->foo = uniqid();
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\logic')->hasMessage('Method \'mock\\' . __NAMESPACE__ . '\\bar::foo()\' does not exist');
 }