PHP code example of byteout / psr-logger-codeception-module
1. Go to this page and download the library: Download byteout/psr-logger-codeception-module 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/ */
byteout / psr-logger-codeception-module example snippets
$logger = $I->grabLogger();
$logger->notice('This is logger example.');
$I->seeLoggerHasNotice('This is logger example.');
use Psr\Log\LoggerInterface;
class HelloWorld
{
private $logger;
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}
public function sayHello($name)
{
$this->logger->info("Hello $name");
}
}
$logger = $I->grabLogger();
$service = new HelloWorld($logger);
$service->sayHello('John');
$I->seeLoggerHasInfo('Hello John');
$I->haveWarning('Something bad happened', ['problem' => 'This is more info.']);
$I->dontSeeLoggerHasAnyError();
$I->seeLoggerHasAnyWarning();
$I->seeLoggerHasWarningThatContains('bad');
public function grabLogger(): \Psr\Log\LoggerInterface;
public function haveEmergency(string $message, array $context = []);
public function haveAlert(string $message, array $context = []);
public function haveCritical(string $message, array $context = []);
public function haveError(string $message, array $context = []);
public function haveWarning(string $message, array $context = []);
public function haveNotice(string $message, array $context = []);
public function haveInfo(string $message, array $context = []);
public function haveDebug(string $message, array $context = []);
$I->haveEmergency('This is emergency');
$I->haveEmergency('This is emergency with context', ['error' => 'This is context array']);
public function seeLoggerHasEmergency(string $message, array $context = null);
public function seeLoggerHasAlert(string $message, array $context = null);
public function seeLoggerHasCritical(string $message, array $context = null);
public function seeLoggerHasError(string $message, array $context = null);
public function seeLoggerHasWarning(string $message, array $context = null);
public function seeLoggerHasNotice(string $message, array $context = null);
public function seeLoggerHasInfo(string $message, array $context = null);
public function seeLoggerHasDebug(string $message, array $context = null);
// matches all 'This is emergency' emergency messages, despite the context
$I->seeLoggerHasEmergency('This is emergency');
// matches only message with the given context
$I->seeLoggerHasEmergency('This is emergency with context', ['error' => 'This is context array']);
public function dontSeeLoggerHasEmergency(string $message, array $context = null);
public function dontSeeLoggerHasAlert(string $message, array $context = null);
public function dontSeeLoggerHasCritical(string $message, array $context = null);
public function dontSeeLoggerHasError(string $message, array $context = null);
public function dontSeeLoggerHasWarning(string $message, array $context = null);
public function dontSeeLoggerHasNotice(string $message, array $context = null);
public function dontSeeLoggerHasInfo(string $message, array $context = null);
public function dontSeeLoggerHasDebug(string $message, array $context = null);
// fails if any 'This is emergency' emergency message was logged, despite the context
$I->dontSeeLoggerHasEmergency('This is emergency');
// fails only when a message with the given content and context was logged
$I->dontSeeLoggerHasEmergency('This is emergency with context', ['error' => 'This is context array']);
public function seeLoggerHasAnyEmergency();
public function seeLoggerHasAnyAlert();
public function seeLoggerHasAnyCritical();
public function seeLoggerHasAnyError();
public function seeLoggerHasAnyWarning();
public function seeLoggerHasAnyNotice();
public function seeLoggerHasAnyInfo();
public function seeLoggerHasAnyDebug();
public function dontSeeLoggerHasAnyEmergency();
public function dontSeeLoggerHasAnyAlert();
public function dontSeeLoggerHasAnyCritical();
public function dontSeeLoggerHasAnyError();
public function dontSeeLoggerHasAnyWarning();
public function dontSeeLoggerHasAnyNotice();
public function dontSeeLoggerHasAnyInfo();
public function dontSeeLoggerHasAnyDebug();
public function seeLoggerHasEmergencyThatContains(string $message);
public function seeLoggerHasAlertThatContains(string $message);
public function seeLoggerHasCriticalThatContains(string $message);
public function seeLoggerHasErrorThatContains(string $message);
public function seeLoggerHasWarningThatContains(string $message);
public function seeLoggerHasNoticeThatContains(string $message);
public function seeLoggerHasInfoThatContains(string $message);
public function seeLoggerHasDebugThatContains(string $message);
// matches all emergency messages containing 'emergency' substring
$I->seeLoggerHasEmergencyThatContains('emergency');
public function dontSeeLoggerHasEmergencyThatContains(string $message);
public function dontSeeLoggerHasAlertThatContains(string $message);
public function dontSeeLoggerHasCriticalThatContains(string $message);
public function dontSeeLoggerHasErrorThatContains(string $message);
public function dontSeeLoggerHasWarningThatContains(string $message);
public function dontSeeLoggerHasNoticeThatContains(string $message);
public function dontSeeLoggerHasInfoThatContains(string $message);
public function dontSeeLoggerHasDebugThatContains(string $message);
// fails is any emergency message containing 'emergency' substring was logged
$I->dontSeeLoggerHasEmergencyThatContains('emergency');
public function seeLoggerHasEmergencyThatMatchesRegex(string $regex);
public function seeLoggerHasAlertThatMatchesRegex(string $regex);
public function seeLoggerHasCriticalThatMatchesRegex(string $regex);
public function seeLoggerHasErrorThatMatchesRegex(string $regex);
public function seeLoggerHasWarningThatMatchesRegex(string $regex);
public function seeLoggerHasNoticeThatMatchesRegex(string $regex);
public function seeLoggerHasInfoThatMatchesRegex(string $regex);
public function seeLoggerHasDebugThatMatchesRegex(string $regex);
// matches all emergency messages passing regex '/emergency/i'
$I->seeLoggerHasEmergencyThatMatchesRegex('/emergency/i');
public function dontSeeLoggerHasEmergencyThatMatchesRegex(string $regex);
public function dontSeeLoggerHasAlertThatMatchesRegex(string $regex);
public function dontSeeLoggerHasCriticalThatMatchesRegex(string $regex);
public function dontSeeLoggerHasErrorThatMatchesRegex(string $regex);
public function dontSeeLoggerHasWarningThatMatchesRegex(string $regex);
public function dontSeeLoggerHasNoticeThatMatchesRegex(string $regex);
public function dontSeeLoggerHasInfoThatMatchesRegex(string $regex);
public function dontSeeLoggerHasDebugThatMatchesRegex(string $regex);
// fails is any emergency message passing regex '/emergency/i was logged
$I->dontSeeLoggerHasEmergencyThatMatchesRegex('emergency');
public function seeLoggerHasEmergencyThatPasses(callable $matcher);
public function seeLoggerHasAlertThatPasses(callable $matcher);
public function seeLoggerHasCriticalThatPasses(callable $matcher);
public function seeLoggerHasErrorThatPasses(callable $matcher);
public function seeLoggerHasWarningThatPasses(callable $matcher);
public function seeLoggerHasNoticeThatPasses(callable $matcher);
public function seeLoggerHasInfoThatPasses(callable $matcher);
public function seeLoggerHasDebugThatPasses(callable $matcher);
public function dontSeeLoggerHasEmergencyThatPasses(callable $matcher);
public function dontSeeLoggerHasAlertThatPasses(callable $matcher);
public function dontSeeLoggerHasCriticalThatPasses(callable $matcher);
public function dontSeeLoggerHasErrorThatPasses(callable $matcher);
public function dontSeeLoggerHasWarningThatPasses(callable $matcher);
public function dontSeeLoggerHasNoticeThatPasses(callable $matcher);
public function dontSeeLoggerHasInfoThatPasses(callable $matcher);
public function dontSeeLoggerHasDebugThatPasses(callable $matcher);