You've already forked Php-Template
All checks were successful
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Successful in 2m50s
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Successful in 2m40s
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Successful in 2m55s
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Successful in 3m9s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Successful in 2m56s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Successful in 1m22s
164 lines
4.7 KiB
PHP
164 lines
4.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Siteworxpro\Tests\Log;
|
|
|
|
use Mockery;
|
|
use Psr\Container\ContainerExceptionInterface;
|
|
use Psr\Container\NotFoundExceptionInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
use Psr\Log\LogLevel;
|
|
use RoadRunner\Logger\Logger as RRLogger;
|
|
use Siteworxpro\App\Log\Logger;
|
|
use Siteworxpro\App\Services\Facades\Logger as LoggerFacade;
|
|
use Siteworxpro\Tests\Unit;
|
|
|
|
class LoggerRpcTest extends Unit
|
|
{
|
|
protected function tearDown(): void
|
|
{
|
|
parent::tearDown();
|
|
unset($_SERVER['RR_RPC']);
|
|
}
|
|
|
|
/**
|
|
* @throws ContainerExceptionInterface
|
|
* @throws NotFoundExceptionInterface
|
|
* @throws \Throwable
|
|
*/
|
|
public function testLogsDebugMessageWhenLevelIsDebug(): void
|
|
{
|
|
$this->expectNotToPerformAssertions();
|
|
|
|
$_SERVER['RR_RPC'] = 'tcp://127.0.0.1:6001';
|
|
|
|
$mock = Mockery::mock(LoggerInterface::class);
|
|
$mock->expects('debug')
|
|
->with('message', ['key' => 'value'])
|
|
->times(1);
|
|
|
|
LoggerFacade::getFacadeContainer()
|
|
->bind(RRLogger::class, function () use ($mock) {
|
|
return $mock;
|
|
});
|
|
|
|
$inputBuffer = fopen('php://memory', 'r+');
|
|
$logger = new Logger(LogLevel::DEBUG, $inputBuffer);
|
|
$logger->debug('message', ['key' => 'value']);
|
|
|
|
$mock->shouldHaveReceived('debug');
|
|
}
|
|
|
|
/**
|
|
* @throws ContainerExceptionInterface
|
|
* @throws NotFoundExceptionInterface
|
|
*/
|
|
public function testLogsDebugMessageWhenLevelIsInfoNotice(): void
|
|
{
|
|
$this->expectNotToPerformAssertions();
|
|
|
|
$_SERVER['RR_RPC'] = 'tcp://127.0.0.1:6001';
|
|
|
|
$mock = Mockery::mock(LoggerInterface::class);
|
|
$mock->expects('info')
|
|
->with('message', ['key' => 'value'])
|
|
->times(2);
|
|
|
|
LoggerFacade::getFacadeContainer()
|
|
->bind(RRLogger::class, function () use ($mock) {
|
|
return $mock;
|
|
});
|
|
|
|
$inputBuffer = fopen('php://memory', 'r+');
|
|
$logger = new Logger(LogLevel::DEBUG, $inputBuffer);
|
|
$logger->info('message', ['key' => 'value']);
|
|
$logger->notice('message', ['key' => 'value']);
|
|
|
|
$mock->shouldHaveReceived('info')->times(2);
|
|
}
|
|
|
|
/**
|
|
* @throws ContainerExceptionInterface
|
|
* @throws NotFoundExceptionInterface
|
|
*/
|
|
public function testLogsDebugMessageWhenLevelIsInfoWarning(): void
|
|
{
|
|
$this->expectNotToPerformAssertions();
|
|
|
|
$_SERVER['RR_RPC'] = 'tcp://127.0.0.1:6001';
|
|
|
|
$mock = Mockery::mock(LoggerInterface::class);
|
|
$mock->expects('warning')
|
|
->with('message', ['key' => 'value'])
|
|
->times(1);
|
|
|
|
LoggerFacade::getFacadeContainer()
|
|
->bind(RRLogger::class, function () use ($mock) {
|
|
return $mock;
|
|
});
|
|
|
|
$inputBuffer = fopen('php://memory', 'r+');
|
|
$logger = new Logger(LogLevel::DEBUG, $inputBuffer);
|
|
$logger->warning('message', ['key' => 'value']);
|
|
|
|
$mock->shouldHaveReceived('warning');
|
|
}
|
|
|
|
/**
|
|
* @throws ContainerExceptionInterface
|
|
* @throws NotFoundExceptionInterface
|
|
*/
|
|
public function testLogsDebugMessageWhenLevelIsInfoError(): void
|
|
{
|
|
$this->expectNotToPerformAssertions();
|
|
|
|
$_SERVER['RR_RPC'] = 'tcp://127.0.0.1:6001';
|
|
|
|
$mock = Mockery::mock(LoggerInterface::class);
|
|
$mock->expects('error')
|
|
->with('message', ['key' => 'value'])
|
|
->times(4);
|
|
|
|
LoggerFacade::getFacadeContainer()
|
|
->bind(RRLogger::class, function () use ($mock) {
|
|
return $mock;
|
|
});
|
|
|
|
$inputBuffer = fopen('php://memory', 'r+');
|
|
$logger = new Logger(LogLevel::DEBUG, $inputBuffer);
|
|
$logger->error('message', ['key' => 'value']);
|
|
$logger->critical('message', ['key' => 'value']);
|
|
$logger->alert('message', ['key' => 'value']);
|
|
$logger->emergency('message', ['key' => 'value']);
|
|
|
|
$mock->shouldHaveReceived('error')->times(4);
|
|
}
|
|
|
|
/**
|
|
* @throws ContainerExceptionInterface
|
|
* @throws NotFoundExceptionInterface
|
|
*/
|
|
public function testLogsLog(): void
|
|
{
|
|
$this->expectNotToPerformAssertions();
|
|
|
|
$_SERVER['RR_RPC'] = 'tcp://127.0.0.1:6001';
|
|
|
|
$mock = Mockery::mock(LoggerInterface::class);
|
|
$mock->expects('log')
|
|
->with('notaloglevel', 'message', ['key' => 'value']);
|
|
|
|
LoggerFacade::getFacadeContainer()
|
|
->bind(RRLogger::class, function () use ($mock) {
|
|
return $mock;
|
|
});
|
|
|
|
$inputBuffer = fopen('php://memory', 'r+');
|
|
$logger = new Logger(LogLevel::DEBUG, $inputBuffer);
|
|
$logger->log('notaloglevel', 'message', ['key' => 'value']);
|
|
|
|
$mock->shouldHaveReceived('log')->times(1);
|
|
}
|
|
}
|