You've already forked Php-Template
All checks were successful
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Successful in 1m40s
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Successful in 1m36s
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Successful in 2m4s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Successful in 2m24s
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Successful in 2m46s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Successful in 1m27s
🏗️✨ Build Workflow / 🖥️ 🔨 Build (push) Successful in 16m7s
🏗️✨ Build Workflow / 🖥️ 🔨 Build Migrations (push) Successful in 1m29s
Reviewed-on: #17 Co-authored-by: Ron Rise <ron@siteworxpro.com> Co-committed-by: Ron Rise <ron@siteworxpro.com>
168 lines
5.0 KiB
PHP
168 lines
5.0 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 Siteworxpro\App\Log\Logger;
|
|
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'])
|
|
->once();
|
|
|
|
\Siteworxpro\App\Services\Facades\Logger::getFacadeContainer()
|
|
->bind(\RoadRunner\Logger\Logger::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');
|
|
|
|
Mockery::close();
|
|
}
|
|
|
|
/**
|
|
* @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);
|
|
|
|
\Siteworxpro\App\Services\Facades\Logger::getFacadeContainer()
|
|
->bind(\RoadRunner\Logger\Logger::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);
|
|
Mockery::close();
|
|
}
|
|
|
|
/**
|
|
* @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);
|
|
|
|
\Siteworxpro\App\Services\Facades\Logger::getFacadeContainer()
|
|
->bind(\RoadRunner\Logger\Logger::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');
|
|
Mockery::close();
|
|
}
|
|
|
|
/**
|
|
* @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);
|
|
|
|
\Siteworxpro\App\Services\Facades\Logger::getFacadeContainer()
|
|
->bind(\RoadRunner\Logger\Logger::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);
|
|
Mockery::close();
|
|
}
|
|
|
|
/**
|
|
* @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']);
|
|
|
|
\Siteworxpro\App\Services\Facades\Logger::getFacadeContainer()
|
|
->bind(\RoadRunner\Logger\Logger::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);
|
|
Mockery::close();
|
|
}
|
|
}
|