2017 © Pedro Peláez
 

library psr-testlogger

PSR-3 compliant test logger for developers who like tests and want to check if their application logs messages as they expect.

image

gamez/psr-testlogger

PSR-3 compliant test logger for developers who like tests and want to check if their application logs messages as they expect.

  • Monday, June 11, 2018
  • by jeromegamez
  • Repository
  • 1 Watchers
  • 5 Stars
  • 17,834 Installations
  • PHP
  • 11 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 10 Versions
  • 25 % Grown

The README.md

PSR Test Logger

PSR-3 compliant test logger for developers who like tests and want to check if their application logs messages as they expect., (*1)

This package was superseded by beste/psr-testlogger., (*2)

Packagist Supported PHP version Build Status GitHub license Total Downloads, (*3)

Installation

composer require --dev gamez/psr-testlogger

Usage

Inject an instance of Gamez\Psr\Log\TestLogger into your Subject Under Test instead of your regular logger., (*4)

use Psr\Log\LoggerInterface;

class SubjectUnderTest
{
    public function __construct(LoggerInterface $logger)
    {
        $this->logger = $logger;
    }

    public function execute()
    {
        $this->logger->info('Message with a {placeholder}', ['placeholder' => 'value']);
        $this->logger->emergency('This {placeholder} will not be replaced.');
    }
}
use Gamez\Psr\Log\TestLogger;
use PHPUnit\Framework\TestCase;

class MyTest extends TestCase
{
    /**
     * @var TestLogger
     */
    private $logger;

    /**
     * @var SubjectUnderTest
     */
    private $sut;

    protected function setUp()
    {
        $this->logger = new TestLogger();
        $this->sut = new SubjectUnderTest($this->logger);
    }

    public function testLogging()
    {
        $this->sut->execute();

        $log = $this->logger->log;

        $this->assertTrue($log->has('Message with a value'));
        $this->assertTrue($log->hasRecordsWithContextKey('foo'));
        $this->assertFalse($log->hasRecordsWithContextKeyAndValue('foo', 'unwanted'));
        // This will break
        $this->assertFalse($log->hasRecordsWithUnreplacedPlaceholders());
    }
}

You can find all available helper methods in the Gamez\Psr\Log\Log class. If it doesn't provide a method you need, you can use your own filters:, (*5)

use Gamez\Psr\Log\Record;
use Gamez\Psr\Log\TestLogger;
use PHPUnit\Framework\TestCase;

class MyTest extends TestCase
{
    /**
     * @var TestLogger
     */
    private $logger;

    /**
     * @var SubjectUnderTest
     */
    private $sut;

    protected function setUp()
    {
        $this->logger = new TestLogger();
        $this->sut = new SubjectUnderTest($this->logger);
    }

    public function testSomethingSpecial()
    {
        $filteredLog = $this->logger->log->filter(function (Record $record) {
            // Matches messages with only numbers
            return ctype_digit($record->message);
        });

        $this->assertCount(0, $filteredLog);
    }
}

The Versions

11/06 2018

dev-master

9999999-dev

PSR-3 compliant test logger for developers who like tests and want to check if their application logs messages as they expect.

  Sources   Download

MIT

The Requires

 

The Development Requires

psr log psr-3 test mock phpunit tests

11/06 2018

3.0.0

3.0.0.0

PSR-3 compliant test logger for developers who like tests and want to check if their application logs messages as they expect.

  Sources   Download

MIT

The Requires

 

The Development Requires

psr log psr-3 test phpunit tests

13/05 2017

2.0.0

2.0.0.0

PSR-3 compliant test logger for developers who like tests and want to check if their application logs messages as they expect.

  Sources   Download

MIT

The Requires

 

The Development Requires

psr log psr-3 test phpunit tests

23/04 2017

1.x-dev

1.9999999.9999999.9999999-dev

PSR-3 compliant test and mock loggers to be used in Unit Tests.

  Sources   Download

MIT

The Requires

 

The Development Requires

psr log psr-3 test mock phpunit

23/04 2017

1.0.5

1.0.5.0

PSR-3 compliant test and mock loggers to be used in Unit Tests.

  Sources   Download

MIT

The Requires

 

The Development Requires

psr log psr-3 test mock phpunit

23/04 2017

1.0.4

1.0.4.0

PSR-3 compliant test and mock loggers to be used in Unit Tests.

  Sources   Download

MIT

The Requires

 

The Development Requires

psr log psr-3 test mock phpunit

23/04 2017

1.0.3

1.0.3.0

PSR-3 compliant test and mock loggers to be used in Unit Tests.

  Sources   Download

MIT

The Requires

 

The Development Requires

psr log psr-3 test mock phpunit

31/01 2016

1.0.2

1.0.2.0

PSR-3 compliant test and mock loggers to be used in Unit Tests.

  Sources   Download

MIT

The Development Requires

psr log psr-3 test mock phpunit

17/11 2015

1.0.1

1.0.1.0

PSR-3 compliant test and mock loggers to be used in Unit Tests.

  Sources   Download

MIT

The Development Requires

psr log psr-3 test mock phpunit

13/08 2015

1.0

1.0.0.0

PSR-3 compliant test and mock loggers to be used in Unit Tests.

  Sources   Download

MIT

The Development Requires

psr log psr-3 test mock phpunit