mirror of
https://github.com/ivuorinen/monolog-gdpr-filter.git
synced 2026-03-20 13:03:57 +00:00
feat: initial commit
This commit is contained in:
87
tests/TestHelpers.php
Normal file
87
tests/TestHelpers.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
/** @noinspection GrazieInspection */
|
||||
|
||||
/** @noinspection PhpMultipleClassDeclarationsInspection */
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use Monolog\JsonSerializableDateTimeImmutable;
|
||||
use Monolog\Level;
|
||||
use Monolog\Logger;
|
||||
use Monolog\LogRecord;
|
||||
use ReflectionClass;
|
||||
use ReflectionException;
|
||||
use ReflectionMethod;
|
||||
use Stringable;
|
||||
|
||||
trait TestHelpers
|
||||
{
|
||||
private const GDPR_REPLACEMENT = '[GDPR]';
|
||||
|
||||
private const TEST_HETU = '131052-308T';
|
||||
|
||||
private const TEST_CC = '1234567812345678';
|
||||
|
||||
public const TEST_EMAIL = 'john.doe@example.com';
|
||||
|
||||
public const MASKED_EMAIL = '***EMAIL***';
|
||||
|
||||
public const MASKED_SECRET = '***MASKED***';
|
||||
|
||||
public const USER_REGISTERED = 'User registered';
|
||||
|
||||
private const INVALID_REGEX = '/[invalid/';
|
||||
|
||||
// ]'/' this should fix the issue with the regex breaking highlighting in the test
|
||||
/**
|
||||
* @source \Monolog\LogRecord::__construct
|
||||
*/
|
||||
protected function logEntry(
|
||||
int|string|Level $level = Level::Warning,
|
||||
string|Stringable $message = "test",
|
||||
array $context = [],
|
||||
string $channel = "test",
|
||||
DateTimeImmutable $datetime = new JsonSerializableDateTimeImmutable(true),
|
||||
array $extra = [],
|
||||
): LogRecord {
|
||||
return new LogRecord(
|
||||
datetime: $datetime,
|
||||
channel: $channel,
|
||||
level: Logger::toMonologLevel($level),
|
||||
message: (string) $message,
|
||||
context: $context,
|
||||
extra: $extra,
|
||||
);
|
||||
}
|
||||
|
||||
protected function getReflection(
|
||||
object|string $object,
|
||||
string $methodName = '',
|
||||
): ReflectionMethod {
|
||||
if (empty($methodName) && is_string($object)) {
|
||||
$method = new ReflectionMethod($object);
|
||||
} else {
|
||||
$method = new ReflectionMethod($object, $methodName);
|
||||
}
|
||||
|
||||
/** @noinspection PhpExpressionResultUnusedInspection */
|
||||
$method->setAccessible(true);
|
||||
return $method;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a reflection of the given class.
|
||||
*
|
||||
* @psalm-api
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
protected function noOperation(): void
|
||||
{
|
||||
// This method intentionally left blank.
|
||||
// It can be used to indicate a no-operation in tests.
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user