| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- /**
- * ConsoleLogTest file
- *
- * PHP 5
- *
- * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
- * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
- *
- * Licensed under The MIT License
- * Redistributions of files must retain the above copyright notice
- *
- * @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
- * @link http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
- * @since 1.3.0
- * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
- */
- namespace Cake\Test\TestCase\Log\Engine;
- use Cake\Console\ConsoleOutput;
- use Cake\Log\Engine\ConsoleLog;
- use Cake\Log\Log;
- use Cake\TestSuite\TestCase;
- /**
- * ConsoleLogTest class
- *
- */
- class ConsoleLogTest extends TestCase {
- /**
- * Test writing to ConsoleOutput
- */
- public function testConsoleOutputWrites() {
- $output = $this->getMock('Cake\Console\ConsoleOutput');
- $output->expects($this->at(0))
- ->method('outputAs');
- $message = '<error>' . date('Y-m-d H:i:s') . " Error: oh noes\n</error>";
- $output->expects($this->at(1))
- ->method('write')
- ->with($message);
- $log = new ConsoleLog([
- 'stream' => $output
- ]);
- $log->write('error', 'oh noes');
- }
- public function testWriteToFileStream() {
- $filename = tempnam(sys_get_temp_dir(), 'cake_log_test');
- $log = new ConsoleLog([
- 'stream' => $filename
- ]);
- $log->write('error', 'oh noes');
- $fh = fopen($filename, 'r');
- $line = fgets($fh);
- $this->assertContains('Error: oh noes', $line);
- }
- /**
- * test default value of stream 'outputAs'
- */
- public function testDefaultOutputAs() {
- if (DS === '\\' && !(bool)env('ANSICON')) {
- $expected = ConsoleOutput::PLAIN;
- } else {
- $expected = ConsoleOutput::COLOR;
- }
- $output = $this->getMock('Cake\Console\ConsoleOutput');
- $output->expects($this->at(0))
- ->method('outputAs')
- ->with($expected);
- $log = new ConsoleLog([
- 'stream' => $output,
- ]);
- $config = $log->config();
- $this->assertEquals($expected, $config['outputAs']);
- }
- }
|