-
-
Notifications
You must be signed in to change notification settings - Fork 3
v1.1 - import classes from psr/log 1.1, compatible with psr/log 2.0 and 3.0 #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,18 @@ | ||
| <?php | ||
|
|
||
| namespace Psr\Log\Test; | ||
|
|
||
| /** | ||
| * This class is internal and does not follow the BC promise. | ||
| * | ||
| * Do NOT use this class in any way. | ||
| * | ||
| * @internal | ||
| */ | ||
| class DummyTest | ||
| { | ||
| public function __toString() | ||
| { | ||
| return 'DummyTest'; | ||
| } | ||
| } |
This file contains hidden or 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,135 @@ | ||
| <?php | ||
|
|
||
| namespace Psr\Log\Test; | ||
|
|
||
| use Psr\Log\InvalidArgumentException; | ||
| use Psr\Log\LoggerInterface; | ||
| use Psr\Log\LogLevel; | ||
| use PHPUnit\Framework\TestCase; | ||
|
|
||
| /** | ||
| * Provides a base test class for ensuring compliance with the LoggerInterface. | ||
| * | ||
| * Implementors can extend the class and implement abstract methods to run this | ||
| * as part of their test suite. | ||
| */ | ||
| abstract class LoggerInterfaceTest extends TestCase | ||
| { | ||
| /** | ||
| * Return an instance of the logger to be tested. | ||
| * | ||
| * @return LoggerInterface | ||
GromNaN marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| */ | ||
| abstract public function getLogger(); | ||
|
|
||
| /** | ||
| * This must return the log messages in order. | ||
| * | ||
| * The simple formatting of the messages is: "<LOG LEVEL> <MESSAGE>". | ||
| * | ||
| * Example ->error('Foo') would yield "error Foo". | ||
| * | ||
| * @return string[] | ||
| */ | ||
| abstract public function getLogs(); | ||
GromNaN marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| public function testImplements() | ||
| { | ||
| $this->assertInstanceOf(LoggerInterface::class, $this->getLogger()); | ||
| } | ||
|
|
||
| /** | ||
| * @dataProvider provideLevelsAndMessages | ||
| */ | ||
| public function testLogsAtAllLevels($level, $message) | ||
| { | ||
| $logger = $this->getLogger(); | ||
| $logger->{$level}($message, ['user' => 'Bob']); | ||
| $logger->log($level, $message, ['user' => 'Bob']); | ||
|
|
||
| $expected = [ | ||
| $level . ' message of level ' . $level . ' with context: Bob', | ||
| $level . ' message of level ' . $level . ' with context: Bob', | ||
| ]; | ||
| $this->assertEquals($expected, $this->getLogs()); | ||
| } | ||
|
|
||
| public function provideLevelsAndMessages() | ||
| { | ||
| return [ | ||
| LogLevel::EMERGENCY => [LogLevel::EMERGENCY, 'message of level emergency with context: {user}'], | ||
| LogLevel::ALERT => [LogLevel::ALERT, 'message of level alert with context: {user}'], | ||
| LogLevel::CRITICAL => [LogLevel::CRITICAL, 'message of level critical with context: {user}'], | ||
| LogLevel::ERROR => [LogLevel::ERROR, 'message of level error with context: {user}'], | ||
| LogLevel::WARNING => [LogLevel::WARNING, 'message of level warning with context: {user}'], | ||
| LogLevel::NOTICE => [LogLevel::NOTICE, 'message of level notice with context: {user}'], | ||
| LogLevel::INFO => [LogLevel::INFO, 'message of level info with context: {user}'], | ||
| LogLevel::DEBUG => [LogLevel::DEBUG, 'message of level debug with context: {user}'], | ||
| ]; | ||
| } | ||
|
|
||
| public function testThrowsOnInvalidLevel() | ||
| { | ||
| $this->expectException(InvalidArgumentException::class); | ||
| $logger = $this->getLogger(); | ||
| $logger->log('invalid level', 'Foo'); | ||
| } | ||
|
|
||
| public function testContextReplacement() | ||
| { | ||
| $logger = $this->getLogger(); | ||
| $logger->info('{Message {nothing} {user} {foo.bar} a}', ['user' => 'Bob', 'foo.bar' => 'Bar']); | ||
|
|
||
| $expected = ['info {Message {nothing} Bob Bar a}']; | ||
| $this->assertEquals($expected, $this->getLogs()); | ||
| } | ||
|
|
||
| public function testObjectCastToString() | ||
| { | ||
| $dummy = $this->createPartialMock(DummyTest::class, ['__toString']); | ||
| $dummy->expects($this->once()) | ||
| ->method('__toString') | ||
| ->will($this->returnValue('DUMMY')); | ||
|
|
||
| $this->getLogger()->warning($dummy); | ||
|
|
||
| $expected = ['warning DUMMY']; | ||
| $this->assertEquals($expected, $this->getLogs()); | ||
| } | ||
|
|
||
| public function testContextCanContainAnything() | ||
| { | ||
| $closed = fopen('php://memory', 'r'); | ||
| fclose($closed); | ||
|
|
||
| $context = [ | ||
| 'bool' => true, | ||
| 'null' => null, | ||
| 'string' => 'Foo', | ||
| 'int' => 0, | ||
| 'float' => 0.5, | ||
| 'nested' => ['with object' => new DummyTest()], | ||
| 'object' => new \DateTime(), | ||
| 'resource' => fopen('php://memory', 'r'), | ||
| 'closed' => $closed, | ||
| ]; | ||
|
|
||
| $this->getLogger()->warning('Crazy context data', $context); | ||
|
|
||
| $expected = ['warning Crazy context data']; | ||
| $this->assertEquals($expected, $this->getLogs()); | ||
| } | ||
|
|
||
| public function testContextExceptionKeyCanBeExceptionOrOtherValues() | ||
| { | ||
| $logger = $this->getLogger(); | ||
| $logger->warning('Random message', ['exception' => 'oops']); | ||
| $logger->critical('Uncaught Exception!', ['exception' => new \LogicException('Fail')]); | ||
|
|
||
| $expected = [ | ||
| 'warning Random message', | ||
| 'critical Uncaught Exception!' | ||
| ]; | ||
| $this->assertEquals($expected, $this->getLogs()); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ralflang the release date should be updated.