You've already forked Php-Template
more tests (#19)
All checks were successful
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Successful in 2m32s
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Successful in 2m48s
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Successful in 2m33s
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Successful in 2m44s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Successful in 2m53s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Successful in 3m5s
All checks were successful
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Successful in 2m32s
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Successful in 2m48s
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Successful in 2m33s
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Successful in 2m44s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Successful in 2m53s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Successful in 3m5s
Reviewed-on: #19 Co-authored-by: Ron Rise <ron@siteworxpro.com> Co-committed-by: Ron Rise <ron@siteworxpro.com>
This commit was merged in pull request #19.
This commit is contained in:
@@ -34,7 +34,7 @@ class LoggerRpcTest extends Unit
|
||||
$mock = Mockery::mock(LoggerInterface::class);
|
||||
$mock->expects('debug')
|
||||
->with('message', ['key' => 'value'])
|
||||
->once();
|
||||
->times(1);
|
||||
|
||||
\Siteworxpro\App\Services\Facades\Logger::getFacadeContainer()
|
||||
->bind(\RoadRunner\Logger\Logger::class, function () use ($mock) {
|
||||
@@ -46,8 +46,6 @@ class LoggerRpcTest extends Unit
|
||||
$logger->debug('message', ['key' => 'value']);
|
||||
|
||||
$mock->shouldHaveReceived('debug');
|
||||
|
||||
Mockery::close();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,7 +74,6 @@ class LoggerRpcTest extends Unit
|
||||
$logger->notice('message', ['key' => 'value']);
|
||||
|
||||
$mock->shouldHaveReceived('info')->times(2);
|
||||
Mockery::close();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,7 +101,6 @@ class LoggerRpcTest extends Unit
|
||||
$logger->warning('message', ['key' => 'value']);
|
||||
|
||||
$mock->shouldHaveReceived('warning');
|
||||
Mockery::close();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,7 +131,6 @@ class LoggerRpcTest extends Unit
|
||||
$logger->emergency('message', ['key' => 'value']);
|
||||
|
||||
$mock->shouldHaveReceived('error')->times(4);
|
||||
Mockery::close();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -162,6 +157,5 @@ class LoggerRpcTest extends Unit
|
||||
$logger->log('notaloglevel', 'message', ['key' => 'value']);
|
||||
|
||||
$mock->shouldHaveReceived('log')->times(1);
|
||||
Mockery::close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,18 @@ declare(strict_types=1);
|
||||
|
||||
namespace Siteworxpro\Tests\Log;
|
||||
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use Psr\Log\LogLevel;
|
||||
use Siteworxpro\App\Log\Logger;
|
||||
use Siteworxpro\Tests\Unit;
|
||||
|
||||
class LoggerTest extends Unit
|
||||
{
|
||||
/**
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
private function getLoggerWithBuffer(string $logLevel): array
|
||||
{
|
||||
$inputBuffer = fopen('php://memory', 'r+');
|
||||
@@ -21,6 +27,10 @@ class LoggerTest extends Unit
|
||||
return stream_get_contents($inputBuffer, -1, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
private function testLogLevel(string $level): void
|
||||
{
|
||||
[$logger, $inputBuffer] = $this->getLoggerWithBuffer($level);
|
||||
@@ -33,6 +43,10 @@ class LoggerTest extends Unit
|
||||
$this->assertEquals('value', $decoded['context']['key']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
private function testLogLevelEmpty(string $configLevel, string $logLevel): void
|
||||
{
|
||||
[$logger, $inputBuffer] = $this->getLoggerWithBuffer($configLevel);
|
||||
@@ -42,57 +56,101 @@ class LoggerTest extends Unit
|
||||
$this->assertEmpty($output);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function testLogsDebugMessageWhenLevelIsDebug(): void
|
||||
{
|
||||
$this->testLogLevel(LogLevel::DEBUG);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function testLogsInfoMessageWhenLevelIsInfo(): void
|
||||
{
|
||||
$this->testLogLevel(LogLevel::INFO);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function testLogsWarningMessageWhenLevelIsWarning(): void
|
||||
{
|
||||
$this->testLogLevel(LogLevel::WARNING);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function testLogsErrorMessageWhenLevelIsError(): void
|
||||
{
|
||||
$this->testLogLevel(LogLevel::ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function testLogsCriticalMessageWhenLevelIsCritical(): void
|
||||
{
|
||||
$this->testLogLevel(LogLevel::CRITICAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function testLogsAlertMessageWhenLevelIsAlert(): void
|
||||
{
|
||||
$this->testLogLevel(LogLevel::ALERT);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function testLogsEmergencyMessageWhenLevelIsEmergency(): void
|
||||
{
|
||||
$this->testLogLevel(LogLevel::EMERGENCY);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function testLogsNoticeMessageWhenLevelIsNotice(): void
|
||||
{
|
||||
$this->testLogLevel(LogLevel::NOTICE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function testDoesNotLogWhenMinimumLevelIsInfo(): void
|
||||
{
|
||||
$this->testLogLevelEmpty(LogLevel::INFO, LogLevel::DEBUG);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function testDoesNotLogWhenMinimumLevelIsWarning(): void
|
||||
{
|
||||
$this->testLogLevelEmpty(LogLevel::WARNING, LogLevel::INFO);
|
||||
$this->testLogLevelEmpty(LogLevel::WARNING, LogLevel::DEBUG);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws ContainerExceptionInterface
|
||||
*/
|
||||
public function testDoesNotLogWhenMinimumLevelIsError(): void
|
||||
{
|
||||
$this->testLogLevelEmpty(LogLevel::ERROR, LogLevel::DEBUG);
|
||||
@@ -100,12 +158,20 @@ class LoggerTest extends Unit
|
||||
$this->testLogLevelEmpty(LogLevel::ERROR, LogLevel::WARNING);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function testDoesNotLogWhenMinimumLevelIsNotice(): void
|
||||
{
|
||||
$this->testLogLevelEmpty(LogLevel::NOTICE, LogLevel::DEBUG);
|
||||
$this->testLogLevelEmpty(LogLevel::NOTICE, LogLevel::INFO);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function testLogsMessageWithEmptyContext(): void
|
||||
{
|
||||
[$logger, $buffer] = $this->getLoggerWithBuffer(LogLevel::INFO);
|
||||
@@ -118,6 +184,10 @@ class LoggerTest extends Unit
|
||||
$this->assertEquals('Message without context', $decoded['message']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function testLogsMessageWithComplexContext(): void
|
||||
{
|
||||
[$logger, $buffer] = $this->getLoggerWithBuffer(LogLevel::INFO);
|
||||
@@ -135,6 +205,10 @@ class LoggerTest extends Unit
|
||||
$this->assertEquals('value', $decoded['context']['nested']['key']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function testLogsStringableMessage(): void
|
||||
{
|
||||
[$logger, $buffer] = $this->getLoggerWithBuffer(LogLevel::INFO);
|
||||
|
||||
Reference in New Issue
Block a user