|
|
@ -36,8 +36,8 @@ class CliControllerTest extends PHPUnit_Framework_TestCase |
|
|
|
Config::set('PROFILER', false); |
|
|
|
$cli_class = $this->getMockForAbstractClass('iCli', array(), '', '', '', '', array('run')); |
|
|
|
$cli_class->expects($this->once()) |
|
|
|
->method('run') |
|
|
|
->with(); |
|
|
|
->method('run') |
|
|
|
->with(); |
|
|
|
CliController::getInstance()->execute($cli_class); |
|
|
|
} |
|
|
|
|
|
|
@ -47,8 +47,8 @@ class CliControllerTest extends PHPUnit_Framework_TestCase |
|
|
|
Config::set('PROFILER', true); |
|
|
|
$cli_class = $this->getMockForAbstractClass('iCli', array(), '', '', '', '', array('run')); |
|
|
|
$cli_class->expects($this->once()) |
|
|
|
->method('run') |
|
|
|
->with(); |
|
|
|
->method('run') |
|
|
|
->with(); |
|
|
|
CliController::getInstance()->execute($cli_class); |
|
|
|
$output = ob_get_clean(); |
|
|
|
$this->assertContains('Elapsed time:', $output); |
|
|
@ -57,38 +57,41 @@ class CliControllerTest extends PHPUnit_Framework_TestCase |
|
|
|
/** |
|
|
|
* @runInSeparateProcess |
|
|
|
*/ |
|
|
|
public function testExecuteImplementError() |
|
|
|
public function testExecuteImplementErrorToFile() |
|
|
|
{ |
|
|
|
Config::set('ErrorStream', __DIR__ . '/temp.txt'); |
|
|
|
touch(Config::get('ErrorStream')); |
|
|
|
$cli_class = new StdClass(); |
|
|
|
$cli_controller = CliController::getInstance(); |
|
|
|
$error_stream_prop = new ReflectionProperty($cli_controller, 'error_stream'); |
|
|
|
$this->stream = fopen('php://memory', 'rw'); |
|
|
|
$error_stream_prop->setAccessible(true); |
|
|
|
$error_stream_prop->setValue($cli_controller, $this->stream); |
|
|
|
$cli_controller->execute($cli_class); |
|
|
|
rewind($this->stream); |
|
|
|
$this->assertContains('Runner "' . get_class($cli_class) . '" need implement of "iCli" interface.', stream_get_contents($this->stream)); |
|
|
|
CliController::getInstance()->execute($cli_class); |
|
|
|
$this->assertContains('Runner "' . get_class($cli_class) . '" need implement of "iCli" interface.', file_get_contents(Config::get('ErrorStream'))); |
|
|
|
unlink(Config::get('ErrorStream')); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @runInSeparateProcess |
|
|
|
*/ |
|
|
|
public function testExecuteImplementErrorToConsole() |
|
|
|
{ |
|
|
|
Config::set('ErrorStream', 'php://output'); |
|
|
|
$cli_class = new StdClass(); |
|
|
|
$this->expectOutputRegex('/.*Runner "' . get_class($cli_class) . '" need implement of "iCli" interface\..*/'); |
|
|
|
CliController::getInstance()->execute($cli_class); |
|
|
|
} |
|
|
|
/** |
|
|
|
* @runInSeparateProcess |
|
|
|
*/ |
|
|
|
public function testExecuteWithRunThrowError() |
|
|
|
{ |
|
|
|
Config::set('ErrorStream', 'php://output'); |
|
|
|
Config::set('PROFILER', false); |
|
|
|
$cli_class = $this->getMockForAbstractClass('iCli', array(), '', '', '', '', array('run')); |
|
|
|
$cli_class->expects($this->once()) |
|
|
|
->method('run') |
|
|
|
->with() |
|
|
|
->will($this->returnCallback(array($this, 'callbackWithThrow'))); |
|
|
|
$cli_controller = CliController::getInstance(); |
|
|
|
$error_stream_prop = new ReflectionProperty($cli_controller, 'error_stream'); |
|
|
|
$this->stream = fopen('php://memory', 'rw'); |
|
|
|
$error_stream_prop->setAccessible(true); |
|
|
|
$error_stream_prop->setValue($cli_controller, $this->stream); |
|
|
|
$cli_controller->execute($cli_class); |
|
|
|
rewind($this->stream); |
|
|
|
$this->assertContains('Error from callback.', stream_get_contents($this->stream)); |
|
|
|
->method('run') |
|
|
|
->with() |
|
|
|
->will($this->returnCallback(array($this, 'callbackWithThrow'))); |
|
|
|
|
|
|
|
$this->expectOutputRegex('/.*Error from callback\..*/'); |
|
|
|
CliController::getInstance()->execute($cli_class); |
|
|
|
} |
|
|
|
|
|
|
|
public function callbackWithThrow() |
|
|
|