Skip to content
Permalink
Browse files

updating Shell tests related to Console logging

  • Loading branch information...
rchavik committed May 8, 2012
1 parent e11f6b7 commit 05243a1c0aa1f950d231548e1bbd19e409e0f2b9
Showing with 41 additions and 0 deletions.
  1. +41 −0 lib/Cake/Test/Case/Console/ShellTest.php
@@ -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 @@ public function do_something() {
protected function no_access() {
}
public function log_something() {
$this->log($this->testMessage);
}
//@codingStandardsIgnoreEnd
public function mergeVars($properties, $class, $normalize = true) {
@@ -799,4 +810,34 @@ public function testGetOptionParser() {
$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);
}
}

0 comments on commit 05243a1

Please sign in to comment.
You can’t perform that action at this time.