-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use correct default colors in ColoredConsoleAppender
Fixes #16
- Loading branch information
Showing
3 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/test/php/util/log/unittest/ColoredConsoleAppenderTest.class.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php namespace util\log\unittest; | ||
|
||
use io\streams\MemoryOutputStream; | ||
use io\streams\StringWriter; | ||
use unittest\TestCase; | ||
use util\cmd\Console; | ||
use util\log\ColoredConsoleAppender; | ||
use util\log\Layout; | ||
use util\log\LogCategory; | ||
use util\log\LogLevel; | ||
use util\log\LoggingEvent; | ||
|
||
class ColoredConsoleAppenderTest extends TestCase { | ||
|
||
/** | ||
* Creates a ColoredConsoleAppender with a given target | ||
* | ||
* @param string|io.streams.OutputStream $target | ||
* @return util.log.LogCategoy | ||
*/ | ||
private function category($target) { | ||
return (new LogCategory('default'))->withAppender( | ||
(new ColoredConsoleAppender(new StringWriter($target)))->withLayout(newinstance(Layout::class, [], [ | ||
'format' => function(LoggingEvent $event) { | ||
return '[LOG] '.implode(' ', $event->getArguments()); | ||
} | ||
])) | ||
); | ||
} | ||
|
||
#[@test] | ||
public function can_create() { | ||
new ColoredConsoleAppender(); | ||
} | ||
|
||
#[@test] | ||
public function writes_to_stdout_by_default() { | ||
$this->assertEquals(Console::$out, (new ColoredConsoleAppender())->writer()); | ||
} | ||
|
||
#[@test] | ||
public function can_overwrite_colors() { | ||
$this->assertEquals('00;30', (new ColoredConsoleAppender('out', [LogLevel::INFO => '00;30']))->colors()[LogLevel::INFO]); | ||
} | ||
|
||
#[@test, @values(map = [ | ||
# 'out' => Console::$out, | ||
# 'err' => Console::$err, | ||
#])] | ||
public function writes_to($param, $writer) { | ||
$this->assertEquals($writer, (new ColoredConsoleAppender($param))->writer()); | ||
} | ||
|
||
#[@test] | ||
public function info() { | ||
$out= new MemoryOutputStream(); | ||
$this->category($out)->info('Test'); | ||
|
||
$this->assertEquals("\033[00;00m[LOG] Test\033[0m", $out->getBytes()); | ||
} | ||
|
||
#[@test] | ||
public function warn() { | ||
$out= new MemoryOutputStream(); | ||
$this->category($out)->warn('Test'); | ||
|
||
$this->assertEquals("\033[00;31m[LOG] Test\033[0m", $out->getBytes()); | ||
} | ||
|
||
#[@test] | ||
public function error() { | ||
$out= new MemoryOutputStream(); | ||
$this->category($out)->error('Test'); | ||
|
||
$this->assertEquals("\033[01;31m[LOG] Test\033[0m", $out->getBytes()); | ||
} | ||
|
||
#[@test] | ||
public function debug() { | ||
$out= new MemoryOutputStream(); | ||
$this->category($out)->debug('Test'); | ||
|
||
$this->assertEquals("\033[00;34m[LOG] Test\033[0m", $out->getBytes()); | ||
} | ||
} |