PHP code example of beste / psr-testlogger
1. Go to this page and download the library: Download beste/psr-testlogger library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
beste / psr-testlogger example snippets
use Beste\Psr\Log\Record;
use Beste\Psr\Log\TestLogger;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
final class Subject
{
public function __construct(
public readonly LoggerInterface $logger
) {}
public function doSomething(): void
{
$this->logger->info('Doing something');
$this->logger->warning('1st problem');
$this->logger->warning('2nd problem');
$this->logger->critical('Uh oh!');
}
}
final class SubjectTest extends \PHPUnit\Framework\TestCase
{
private TestLogger $logger;
private Subject $subject;
protected function setUp() : void{
$this->logger = TestLogger::create();
}
/** @test */
public function it_does_something(): void
{
$this->subject->doSomething();
self::assertCount(4, $this->logger->records);
self::assertEqualsCanonicalizing(
[LogLevel::INFO, LogLevel::WARNING, LogLevel::CRITICAL],
$this->logger->records->levels()
);
self::assertTrue($this->logger->records->