/** * Test logging to both ConsoleLog and FileLog */ public function testCombinedLogWriting() { TestCakeLog::config('test_console_log', array('engine' => 'TestConsoleLog')); $mock = $this->getMock('TestConsoleLog', array('write'), array(array('types' => 'error'))); TestCakeLog::replace('test_console_log', $mock); // log to both file and console $message = 'Test error message'; $mock->expects($this->once())->method('write'); TestCakeLog::write(LOG_ERR, $message); $this->assertTrue(file_exists(LOGS . 'error.log'), 'error.log missing'); $logOutput = file_get_contents(LOGS . 'error.log'); $this->assertContains($message, $logOutput); // TestConsoleLog is only interested in `error` type $message = 'Test info message'; $mock->expects($this->never())->method('write'); TestCakeLog::write(LOG_INFO, $message); // checks that output is correctly written in the correct logfile $this->assertTrue(file_exists(LOGS . 'error.log'), 'error.log missing'); $this->assertTrue(file_exists(LOGS . 'debug.log'), 'debug.log missing'); $logOutput = file_get_contents(LOGS . 'error.log'); $this->assertNotContains($message, $logOutput); $logOutput = file_get_contents(LOGS . 'debug.log'); $this->assertContains($message, $logOutput); }
/** * test default value of stream 'outputAs' * * @return void */ public function testDefaultOutputAs() { TestCakeLog::config('test_console_log', array('engine' => 'TestConsole')); if (DS === '\\' && !(bool) env('ANSICON') || function_exists('posix_isatty') && !posix_isatty(null)) { $expected = ConsoleOutput::PLAIN; } else { $expected = ConsoleOutput::COLOR; } $stream = TestCakeLog::stream('test_console_log'); $config = $stream->config(); $this->assertEquals($expected, $config['outputAs']); }
/** * Test file and console and logging * * @return void */ 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' => 'Console', '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); }