mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-02 01:22:37 +00:00
updating Shell tests related to Console logging
This commit is contained in:
parent
e11f6b7fe4
commit
05243a1c0a
1 changed files with 41 additions and 0 deletions
|
@ -44,6 +44,13 @@ class ShellTestShell extends Shell {
|
|||
*/
|
||||
public $stopped;
|
||||
|
||||
/**
|
||||
* testMessage property
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $testMessage = 'all your base are belong to us';
|
||||
|
||||
/**
|
||||
* stop method
|
||||
*
|
||||
|
@ -63,6 +70,10 @@ class ShellTestShell extends Shell {
|
|||
|
||||
protected function no_access() {
|
||||
}
|
||||
|
||||
public function log_something() {
|
||||
$this->log($this->testMessage);
|
||||
}
|
||||
//@codingStandardsIgnoreEnd
|
||||
|
||||
public function mergeVars($properties, $class, $normalize = true) {
|
||||
|
@ -799,4 +810,34 @@ TEXT;
|
|||
$this->assertEquals('plugin.test', $parser->command());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test file and console and logging
|
||||
*/
|
||||
public function testFileAndConsoleLogging() {
|
||||
// file logging
|
||||
$this->Shell->log_something();
|
||||
$this->assertTrue(file_exists(LOGS . 'error.log'));
|
||||
|
||||
unlink(LOGS . 'error.log');
|
||||
$this->assertFalse(file_exists(LOGS . 'error.log'));
|
||||
|
||||
// both file and console logging
|
||||
require_once CORE_TEST_CASES . DS . 'Log' . DS . 'Engine' . DS . 'ConsoleLogTest.php';
|
||||
$mock = $this->getMock('ConsoleLog', array('write'), array(
|
||||
array('types' => 'error'),
|
||||
));
|
||||
TestCakeLog::config('console', array(
|
||||
'engine' => 'ConsoleLog',
|
||||
'stream' => 'php://stderr',
|
||||
));
|
||||
TestCakeLog::replace('console', $mock);
|
||||
$mock->expects($this->once())
|
||||
->method('write')
|
||||
->with('error', $this->Shell->testMessage);
|
||||
$this->Shell->log_something();
|
||||
$this->assertTrue(file_exists(LOGS . 'error.log'));
|
||||
$contents = file_get_contents(LOGS . 'error.log');
|
||||
$this->assertContains($this->Shell->testMessage, $contents);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue