PHP code example of vstelmakh / psr-test-logger

1. Go to this page and download the library: Download vstelmakh/psr-test-logger 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/ */

    

vstelmakh / psr-test-logger example snippets




use VStelmakh\PsrTestLogger\TestLogger;
use PHPUnit\Framework\TestCase;

class YourServiceTest extends TestCase
{
    public function testSomething(): void
    {
        $logger = new TestLogger();

        $service = new YourService($logger);
        $service->doSomething();

        // Thanks to automatic PHPUnit integration,
        // corresponding assertations can be performed as simple as:

        $logger
            ->assert()
            ->hasLog()
            ->withMessage('Execution complete.');

        $logger
            ->assert()
            ->hasWarning()
            ->withMessageContains('not found')
            ->withContextContainsSameAs('id', 1);
    }
}