From 05eb525f390a4e5ffca066c9ac8b3d447ad2ba14 Mon Sep 17 00:00:00 2001
From: Chris Minett <1084019+chrisminett@users.noreply.github.com>
Date: Mon, 16 Oct 2023 16:06:41 +0100
Subject: [PATCH] Add EasyCodingStandard
---
.github/workflows/code-checks.yml | 3 +
.runConfigurations/All unit tests.run.xml | 6 ++
.runConfigurations/EasyCodingStandard.run.xml | 10 +++
composer.json | 3 +-
ecs.php | 35 ++++++++++
src/Config.php | 4 +-
src/ConfigInterface.php | 1 -
src/Decorator/AbstractDecorator.php | 1 -
src/Decorator/LevelFilter.php | 6 +-
src/Factory.php | 11 ++-
src/LoggerType/CliColor.php | 19 +++--
src/LoggerType/Collection.php | 1 -
src/LoggerType/Stream.php | 17 ++---
src/Pool.php | 5 +-
tests/ConfigTest.php | 34 +++++----
tests/Decorator/DefaultContextTest.php | 24 +++----
tests/FactoryTest.php | 70 +++++++++++--------
tests/LoggerType/CollectionTest.php | 1 -
tests/LoggerType/StreamTest.php | 13 ++--
tests/PoolTest.php | 35 +++++-----
20 files changed, 170 insertions(+), 129 deletions(-)
create mode 100644 .runConfigurations/All unit tests.run.xml
create mode 100644 .runConfigurations/EasyCodingStandard.run.xml
create mode 100644 ecs.php
diff --git a/.github/workflows/code-checks.yml b/.github/workflows/code-checks.yml
index 6712799..c5a6924 100644
--- a/.github/workflows/code-checks.yml
+++ b/.github/workflows/code-checks.yml
@@ -42,6 +42,9 @@ jobs:
- name: Composer
run: composer install --no-progress
+ - name: Check CS
+ run: vendor/bin/ecs
+
- name: PHPUnit
run: vendor/bin/phpunit --coverage-clover=coverage.xml
diff --git a/.runConfigurations/All unit tests.run.xml b/.runConfigurations/All unit tests.run.xml
new file mode 100644
index 0000000..a42ab5a
--- /dev/null
+++ b/.runConfigurations/All unit tests.run.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.runConfigurations/EasyCodingStandard.run.xml b/.runConfigurations/EasyCodingStandard.run.xml
new file mode 100644
index 0000000..9998b36
--- /dev/null
+++ b/.runConfigurations/EasyCodingStandard.run.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/composer.json b/composer.json
index 4a3acfc..efeb2fe 100644
--- a/composer.json
+++ b/composer.json
@@ -31,7 +31,8 @@
},
"require-dev": {
- "phpunit/phpunit": "^9"
+ "phpunit/phpunit": "^9",
+ "symplify/easy-coding-standard": "^12"
},
"autoload-dev": {
diff --git a/ecs.php b/ecs.php
new file mode 100644
index 0000000..698c6c9
--- /dev/null
+++ b/ecs.php
@@ -0,0 +1,35 @@
+paths([
+ __DIR__ . '/src',
+ __DIR__ . '/tests',
+ ]);
+
+ $ecsConfig->sets([
+ SetList::COMMON,
+ SetList::PSR_12,
+ ]);
+
+ $ecsConfig->skip([
+ // Remove sniff, from common/control-structures
+ \PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer::class,
+
+ // Remove sniff, from common/spaces
+ \PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer::class,
+ \PhpCsFixer\Fixer\CastNotation\CastSpacesFixer::class,
+ ]);
+
+ // PER Coding Style 7.1: "The `fn` keyword MUST NOT be succeeded by a space."
+ $ecsConfig->ruleWithConfiguration(
+ \PhpCsFixer\Fixer\FunctionNotation\FunctionDeclarationFixer::class,
+ [
+ 'closure_fn_spacing' => 'none',
+ ]
+ );
+};
diff --git a/src/Config.php b/src/Config.php
index a19fb80..85bdd2e 100644
--- a/src/Config.php
+++ b/src/Config.php
@@ -26,8 +26,8 @@ public function getLoggerConfig(string $name): array
if (!isset($loggerConfig['type'])) {
$loggerConfig = [
- 'type' => 'collection',
- 'loggers' => $loggerConfig
+ 'type' => 'collection',
+ 'loggers' => $loggerConfig,
];
}
diff --git a/src/ConfigInterface.php b/src/ConfigInterface.php
index b73e0c6..036f683 100644
--- a/src/ConfigInterface.php
+++ b/src/ConfigInterface.php
@@ -10,6 +10,5 @@
*/
interface ConfigInterface
{
-
public function getLoggerConfig(string $name): array;
}
diff --git a/src/Decorator/AbstractDecorator.php b/src/Decorator/AbstractDecorator.php
index 2aec395..209abd8 100644
--- a/src/Decorator/AbstractDecorator.php
+++ b/src/Decorator/AbstractDecorator.php
@@ -25,7 +25,6 @@ abstract class AbstractDecorator extends AbstractLogger
* If the concrete requires use of the config value, override the constructor
* to add validation and store for re-use
*
- * @param LoggerInterface $logger
* @param mixed $config
*/
public function __construct(LoggerInterface $logger, $config)
diff --git a/src/Decorator/LevelFilter.php b/src/Decorator/LevelFilter.php
index 871a603..e4dc40b 100644
--- a/src/Decorator/LevelFilter.php
+++ b/src/Decorator/LevelFilter.php
@@ -4,9 +4,9 @@
namespace Phlib\Logger\Decorator;
-use Psr\Log\LogLevel;
use Psr\Log\InvalidArgumentException;
use Psr\Log\LoggerInterface;
+use Psr\Log\LogLevel;
/**
* Class LevelFilter
@@ -17,7 +17,7 @@ class LevelFilter extends AbstractDecorator
/**
* Logging levels from syslog protocol defined in RFC 5424
*
- * @var string[] $levels Logging levels
+ * @var string[] Logging levels
*/
private static $levels = [
LogLevel::EMERGENCY, // 0
@@ -27,7 +27,7 @@ class LevelFilter extends AbstractDecorator
LogLevel::WARNING, // 4
LogLevel::NOTICE, // 5
LogLevel::INFO, // 6
- LogLevel::DEBUG // 7
+ LogLevel::DEBUG, // 7
];
/**
diff --git a/src/Factory.php b/src/Factory.php
index 7291480..237b459 100644
--- a/src/Factory.php
+++ b/src/Factory.php
@@ -17,23 +17,20 @@ class Factory
*/
private $decorators = [
'defaultContext' => \Phlib\Logger\Decorator\DefaultContext::class,
- 'level' => \Phlib\Logger\Decorator\LevelFilter::class
+ 'level' => \Phlib\Logger\Decorator\LevelFilter::class,
];
/**
* Register a new decorator class
*
* Class must implement DecoratorInterface
- *
- * @param string $configKey
- * @param string $className
*/
public function registerDecorator(string $configKey, string $className): void
{
if (isset($this->decorators[$configKey])) {
throw new \RuntimeException('Decorator key already in use: ' . $configKey);
}
- if (in_array($className, $this->decorators)) {
+ if (in_array($className, $this->decorators, true)) {
throw new \RuntimeException('Decorator class already registered: ' . $className);
}
$this->decorators[$configKey] = $className;
@@ -60,7 +57,7 @@ public function createLogger(string $name, array $config): LoggerInterface
if (!method_exists($this, $methodName)) {
throw new \DomainException(sprintf('Cannot find a logger type named "%s"', $type));
}
- $logger = $this->$methodName($name, $config);
+ $logger = $this->{$methodName}($name, $config);
$logger = $this->applyDecorators($logger, $config);
@@ -114,7 +111,7 @@ public function createGelfLogger(string $name, array $config): \Gelf\Logger
$host = $config['host'] ?? false;
$port = $config['port'] ?? 12201;
- $transport = new \Gelf\Transport\UdpTransport($host, $port);
+ $transport = new \Gelf\Transport\UdpTransport($host, $port);
$messagePublisher = new \Gelf\Publisher($transport);
return new \Gelf\Logger($messagePublisher, $name);
diff --git a/src/LoggerType/CliColor.php b/src/LoggerType/CliColor.php
index 9f7af3c..abed1aa 100644
--- a/src/LoggerType/CliColor.php
+++ b/src/LoggerType/CliColor.php
@@ -23,7 +23,6 @@ class CliColor extends Stream
/**
* @see Stream::__construct()
- * @param string $name
* @param resource|string $stream Optional. Default to Standard Error
*/
public function __construct(string $name, $stream = STDERR)
@@ -31,22 +30,20 @@ public function __construct(string $name, $stream = STDERR)
parent::__construct($name, $stream);
$this->formatter = new OutputFormatter(true, [
- 'debug' => new OutputFormatterStyle(),
- 'info' => new OutputFormatterStyle('blue'),
- 'notice' => new OutputFormatterStyle('green'),
- 'warning' => new OutputFormatterStyle('yellow'),
- 'error' => new OutputFormatterStyle('red'),
- 'critical' => new OutputFormatterStyle('red', 'yellow'),
- 'alert' => new OutputFormatterStyle('white', 'red', ['bold']),
- 'emergency' => new OutputFormatterStyle('white', 'red', ['bold', 'underscore'])
+ 'debug' => new OutputFormatterStyle(),
+ 'info' => new OutputFormatterStyle('blue'),
+ 'notice' => new OutputFormatterStyle('green'),
+ 'warning' => new OutputFormatterStyle('yellow'),
+ 'error' => new OutputFormatterStyle('red'),
+ 'critical' => new OutputFormatterStyle('red', 'yellow'),
+ 'alert' => new OutputFormatterStyle('white', 'red', ['bold']),
+ 'emergency' => new OutputFormatterStyle('white', 'red', ['bold', 'underscore']),
]);
}
/**
* @see Stream::getMessageFormat()
* @param mixed $level
- * @param array $context
- * @return string
*/
protected function getMessageFormat($level, array $context = []): string
{
diff --git a/src/LoggerType/Collection.php b/src/LoggerType/Collection.php
index fe82e8e..dd26edf 100644
--- a/src/LoggerType/Collection.php
+++ b/src/LoggerType/Collection.php
@@ -13,7 +13,6 @@
*/
class Collection extends AbstractLogger
{
-
/**
* @var \SplObjectStorage
*/
diff --git a/src/LoggerType/Stream.php b/src/LoggerType/Stream.php
index 803dd91..22591a8 100644
--- a/src/LoggerType/Stream.php
+++ b/src/LoggerType/Stream.php
@@ -33,7 +33,6 @@ class Stream extends AbstractLogger
private $dateFormat = 'Y-m-d H:i:s';
/**
- * @param string $name
* @param resource|string $stream
*/
public function __construct(string $name, $stream)
@@ -62,8 +61,6 @@ public function setMessageFormat(string $format): self
* This method can be overridden by extending classes to modify the behaviour
*
* @param mixed $level
- * @param array $context
- * @return string
*/
protected function getMessageFormat($level, array $context = []): string
{
@@ -85,10 +82,10 @@ public function log($level, $message, array $context = []): void
{
$meta = [
'datetime' => date($this->dateFormat),
- 'name' => $this->name,
- 'level' => $level,
- 'message' => $this->formatMessage((string)$message, $context),
- 'context' => $this->formatContext($context)
+ 'name' => $this->name,
+ 'level' => $level,
+ 'message' => $this->formatMessage((string)$message, $context),
+ 'context' => $this->formatContext($context),
];
$message = static::interpolate($this->getMessageFormat($level, $context), $meta);
@@ -123,8 +120,6 @@ protected function formatContext(array $context): string
* trying to ensure no error, warning or notice is happening
*
* @param mixed $message
- * @param array $context
- * @return string
*/
private static function interpolate($message, array $context): string
{
@@ -144,16 +139,14 @@ private static function interpolate($message, array $context): string
* Converts a context value into its appropriate string representation
*
* @param mixed $val
- * @return string
*/
private static function contextValueToString($val): string
{
-
if (is_bool($val)) {
return var_export($val, true);
} elseif (is_scalar($val)) {
return (string)$val;
- } elseif (is_null($val)) {
+ } elseif ($val === null) {
return 'NULL';
} elseif (is_object($val)) {
if (is_callable([$val, '__toString'])) {
diff --git a/src/Pool.php b/src/Pool.php
index cb9e929..8435229 100644
--- a/src/Pool.php
+++ b/src/Pool.php
@@ -13,7 +13,6 @@
*/
class Pool
{
-
/**
* @var ConfigInterface
*/
@@ -36,7 +35,7 @@ class Pool
public function __construct(ConfigInterface $config, Factory $loggerFactory)
{
- $this->config = $config;
+ $this->config = $config;
$this->loggerFactory = $loggerFactory;
}
@@ -65,7 +64,7 @@ public function getLoggerCollection(string $name): Collection
if (!$logger instanceof Collection) {
$logger = $this->loggerFactory->createCollectionLogger($name, [
- 'loggers' => [$logger]
+ 'loggers' => [$logger],
]);
}
diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php
index 929bc80..a01c70f 100644
--- a/tests/ConfigTest.php
+++ b/tests/ConfigTest.php
@@ -5,21 +5,19 @@
namespace Phlib\Logger\Test;
use Phlib\Logger\Config;
-use Phlib\Logger\Factory;
use PHPUnit\Framework\TestCase;
use Psr\Log\LogLevel;
class ConfigTest extends TestCase
{
-
public function testEmptyConfig()
{
$configArray = [];
$config = new Config($configArray);
$expected = [
- 'type' => 'collection',
- 'loggers' => []
+ 'type' => 'collection',
+ 'loggers' => [],
];
static::assertEquals($expected, $config->getLoggerConfig('test'));
@@ -29,11 +27,11 @@ public function testStream()
{
$streamConfig = [
'type' => 'stream',
- 'path' => '(filename)'
+ 'path' => '(filename)',
];
$configArray = [
- 'test' => $streamConfig
+ 'test' => $streamConfig,
];
$config = new Config($configArray);
@@ -49,17 +47,17 @@ public function testCollectionCoerce()
$configArray = [
'test' => [
- $gelfConfig
- ]
+ $gelfConfig,
+ ],
];
$config = new Config($configArray);
$expected = [
- 'type' => 'collection',
+ 'type' => 'collection',
'loggers' => [
- $gelfConfig
- ]
+ $gelfConfig,
+ ],
];
static::assertEquals($expected, $config->getLoggerConfig('test'));
@@ -68,15 +66,15 @@ public function testCollectionCoerce()
public function testAlias()
{
$streamConfig = [
- 'type' => 'stream',
+ 'type' => 'stream',
'level' => LogLevel::CRITICAL,
- 'path' => '(filename)'
+ 'path' => '(filename)',
];
$configArray = [
- 'test' => 'test1',
+ 'test' => 'test1',
'test1' => 'test2',
- 'test2' => $streamConfig
+ 'test2' => $streamConfig,
];
$config = new Config($configArray);
@@ -87,14 +85,14 @@ public function testAlias()
public function testInvalidLoggerConfigType()
{
$configArray = [
- 'test' => false
+ 'test' => false,
];
$config = new Config($configArray);
$expected = [
- 'type' => 'collection',
- 'loggers' => []
+ 'type' => 'collection',
+ 'loggers' => [],
];
static::assertEquals($expected, $config->getLoggerConfig('test'));
diff --git a/tests/Decorator/DefaultContextTest.php b/tests/Decorator/DefaultContextTest.php
index abc7f00..632b8ee 100644
--- a/tests/Decorator/DefaultContextTest.php
+++ b/tests/Decorator/DefaultContextTest.php
@@ -43,43 +43,43 @@ public function providerAddDefaultContext()
[
[
'hello' => 'world',
- 'foo' => 'bar'
+ 'foo' => 'bar',
],
[],
[
'hello' => 'world',
- 'foo' => 'bar'
- ]
+ 'foo' => 'bar',
+ ],
],
// Defaults, add other log context
[
[
- 'hello' => 'world'
+ 'hello' => 'world',
],
[
- 'foo' => 'bar'
+ 'foo' => 'bar',
],
[
'hello' => 'world',
- 'foo' => 'bar'
- ]
+ 'foo' => 'bar',
+ ],
],
// Overwrite defaults with log context
[
[
'hello' => 'world',
- 'foo' => 'bar'
+ 'foo' => 'bar',
],
[
'hello' => 'new world',
- 'test' => 'abc123'
+ 'test' => 'abc123',
],
[
'hello' => 'new world',
'foo' => 'bar',
- 'test' => 'abc123'
- ]
- ]
+ 'test' => 'abc123',
+ ],
+ ],
];
}
diff --git a/tests/FactoryTest.php b/tests/FactoryTest.php
index e6a8b6e..2233157 100644
--- a/tests/FactoryTest.php
+++ b/tests/FactoryTest.php
@@ -10,13 +10,14 @@
class FactoryTest extends TestCase
{
-
public function testCreateStreamLogger()
{
$factory = new Factory();
$fh = fopen('php://memory', 'a');
- $logger = $factory->createStreamLogger('test', [ 'path' => $fh ]);
+ $logger = $factory->createStreamLogger('test', [
+ 'path' => $fh,
+ ]);
static::assertInstanceOf(\Phlib\Logger\LoggerType\Stream::class, $logger);
}
@@ -25,7 +26,9 @@ public function testCreateGelfLogger()
{
$factory = new Factory();
- $logger = $factory->createGelfLogger('test', [ 'host' => '127.0.0.1' ]);
+ $logger = $factory->createGelfLogger('test', [
+ 'host' => '127.0.0.1',
+ ]);
static::assertInstanceOf(\Gelf\Logger::class, $logger);
}
@@ -33,8 +36,8 @@ public function testCreateGelfLogger()
public function testCreateCollectionLoggerEmpty()
{
$factory = new Factory();
- $logger = $factory->createCollectionLogger('test', [
- 'loggers' => []
+ $logger = $factory->createCollectionLogger('test', [
+ 'loggers' => [],
]);
static::assertInstanceOf(\Phlib\Logger\LoggerType\Collection::class, $logger);
@@ -45,8 +48,8 @@ public function testCreateCollectionLoggerExistingLogger()
$existingLogger = $this->createMock(\Psr\Log\LoggerInterface::class);
$factory = new Factory();
- $logger = $factory->createCollectionLogger('test', [
- 'loggers' => [$existingLogger]
+ $logger = $factory->createCollectionLogger('test', [
+ 'loggers' => [$existingLogger],
]);
static::assertInstanceOf(\Phlib\Logger\LoggerType\Collection::class, $logger);
@@ -56,12 +59,12 @@ public function testCreateCollectionLoggerWithConfig()
{
$gelfConfig = [
'type' => 'gelf',
- 'host' => '127.0.0.1'
+ 'host' => '127.0.0.1',
];
$factory = new Factory();
- $logger = $factory->createCollectionLogger('test', [
- 'loggers' => [$gelfConfig]
+ $logger = $factory->createCollectionLogger('test', [
+ 'loggers' => [$gelfConfig],
]);
static::assertInstanceOf(\Phlib\Logger\LoggerType\Collection::class, $logger);
@@ -78,7 +81,7 @@ public function testCreateCollectionLoggerWithInvalidConfig()
$factory = new Factory();
$factory->createCollectionLogger('test', [
- 'loggers' => [$invalidConfig]
+ 'loggers' => [$invalidConfig],
]);
}
@@ -87,9 +90,9 @@ public function testCreateLoggerStreamUnfiltered()
$fh = fopen('php://memory', 'a');
$factory = new Factory();
- $logger = $factory->createLogger('test', [
+ $logger = $factory->createLogger('test', [
'type' => 'stream',
- 'path' => $fh
+ 'path' => $fh,
]);
static::assertInstanceOf(\Phlib\Logger\LoggerType\Stream::class, $logger);
@@ -98,9 +101,9 @@ public function testCreateLoggerStreamUnfiltered()
public function testCreateLoggerGelfUnfiltered()
{
$factory = new Factory();
- $logger = $factory->createLogger('test', [
+ $logger = $factory->createLogger('test', [
'type' => 'gelf',
- 'host' => '127.0.0.1'
+ 'host' => '127.0.0.1',
]);
static::assertInstanceOf(\Gelf\Logger::class, $logger);
@@ -109,9 +112,9 @@ public function testCreateLoggerGelfUnfiltered()
public function testCreateLoggerCollectionUnfiltered()
{
$factory = new Factory();
- $logger = $factory->createLogger('test', [
- 'type' => 'collection',
- 'loggers' => []
+ $logger = $factory->createLogger('test', [
+ 'type' => 'collection',
+ 'loggers' => [],
]);
static::assertInstanceOf(\Phlib\Logger\LoggerType\Collection::class, $logger);
@@ -170,10 +173,10 @@ public function testCreateLoggerDecoratorNotRegistered()
$factory = new Factory();
$factory->unregisterDecorator('level');
- $logger = $factory->createLogger('test', [
- 'type' => 'stream',
+ $logger = $factory->createLogger('test', [
+ 'type' => 'stream',
'level' => LogLevel::ERROR,
- 'path' => $fh
+ 'path' => $fh,
]);
static::assertNotInstanceOf(\Phlib\Logger\Decorator\LevelFilter::class, $logger);
@@ -187,10 +190,10 @@ public function testCreateLoggerDecorator()
$factory = new Factory();
$factory->unregisterDecorator('level');
$factory->registerDecorator('dummy', \Phlib\Logger\Decorator\LevelFilter::class);
- $logger = $factory->createLogger('test', [
- 'type' => 'stream',
+ $logger = $factory->createLogger('test', [
+ 'type' => 'stream',
'dummy' => LogLevel::ERROR,
- 'path' => $fh
+ 'path' => $fh,
]);
static::assertInstanceOf(\Phlib\Logger\Decorator\LevelFilter::class, $logger);
@@ -206,9 +209,9 @@ public function testRegisterDecoratorMissing()
$factory = new Factory();
$factory->registerDecorator('dummy', '\Phlib\Logger\not\a\class');
$factory->createLogger('test', [
- 'type' => 'stream',
+ 'type' => 'stream',
'dummy' => true,
- 'path' => $fh
+ 'path' => $fh,
]);
}
@@ -221,10 +224,10 @@ public function testRegisterDecoratorInvalid()
$factory = new Factory();
$factory->registerDecorator('dummy', \Phlib\Logger\Config::class);
- $logger = $factory->createLogger('test', [
- 'type' => 'stream',
+ $logger = $factory->createLogger('test', [
+ 'type' => 'stream',
'dummy' => true,
- 'path' => $fh
+ 'path' => $fh,
]);
}
@@ -234,7 +237,9 @@ public function testCreateLoggerMissingLoggerType()
$this->expectExceptionMessage('Logger config missing logger type');
$factory = new Factory();
- $factory->createLogger('test', [ 'path' => 'filename' ]);
+ $factory->createLogger('test', [
+ 'path' => 'filename',
+ ]);
}
public function testCreateLoggerInvalidLogger()
@@ -243,6 +248,9 @@ public function testCreateLoggerInvalidLogger()
$this->expectExceptionMessage('Cannot find a logger type named');
$factory = new Factory();
- $factory->createLogger('test', [ 'type' => 'unknown', 'path' => '(filename)' ]);
+ $factory->createLogger('test', [
+ 'type' => 'unknown',
+ 'path' => '(filename)',
+ ]);
}
}
diff --git a/tests/LoggerType/CollectionTest.php b/tests/LoggerType/CollectionTest.php
index 0c187d7..ca345cc 100644
--- a/tests/LoggerType/CollectionTest.php
+++ b/tests/LoggerType/CollectionTest.php
@@ -17,7 +17,6 @@ public function testIsPsrLog()
static::assertInstanceOf(\Psr\Log\LoggerInterface::class, $logger);
}
-
public function testLog()
{
$logger = new Collection();
diff --git a/tests/LoggerType/StreamTest.php b/tests/LoggerType/StreamTest.php
index 69da1e0..d9d0785 100644
--- a/tests/LoggerType/StreamTest.php
+++ b/tests/LoggerType/StreamTest.php
@@ -10,7 +10,6 @@
class StreamTest extends TestCase
{
-
public function testIsPsrLog()
{
$resource = fopen('php://memory', 'a');
@@ -85,7 +84,7 @@ public function testMessageFormatContext()
'field1' => 'Test Field 1',
'field2' => 'Test Field 2',
'field3' => 'Test Field 3',
- 'exception' => $contextException
+ 'exception' => $contextException,
];
$stream->setMessageFormat('{context}');
@@ -132,7 +131,7 @@ public function testFormatContextBoolean()
$stream->setMessageFormat('{message}');
$stream->log(LogLevel::ALERT, '{myvalue}', [
- 'myvalue' => true
+ 'myvalue' => true,
]);
rewind($resource);
@@ -149,7 +148,7 @@ public function testFormatContextString()
$stream->setMessageFormat('{message}');
$stream->log(LogLevel::ALERT, '{myvalue}', [
- 'myvalue' => 'value'
+ 'myvalue' => 'value',
]);
rewind($resource);
@@ -166,7 +165,7 @@ public function testFormatContextNull()
$stream->setMessageFormat('{message}');
$stream->log(LogLevel::ALERT, '{myvalue}', [
- 'myvalue' => null
+ 'myvalue' => null,
]);
rewind($resource);
@@ -185,7 +184,7 @@ public function testFormatContextClass()
$object = new \stdClass();
$stream->log(LogLevel::ALERT, '{myvalue}', [
- 'myvalue' => $object
+ 'myvalue' => $object,
]);
rewind($resource);
@@ -202,7 +201,7 @@ public function testFormatContextRawType()
$stream->setMessageFormat('{message}');
$stream->log(LogLevel::ALERT, '{myvalue}', [
- 'myvalue' => []
+ 'myvalue' => [],
]);
rewind($resource);
diff --git a/tests/PoolTest.php b/tests/PoolTest.php
index aaae5b7..f986c44 100644
--- a/tests/PoolTest.php
+++ b/tests/PoolTest.php
@@ -10,22 +10,21 @@
class PoolTest extends TestCase
{
-
public function testGetLogger()
{
$loggerConfig = [
- 'type' => 'collection',
- 'loggers' => []
+ 'type' => 'collection',
+ 'loggers' => [],
];
- $config = $this->createMock(\Phlib\Logger\Config::class);
+ $config = $this->createMock(\Phlib\Logger\Config::class);
$config->expects(static::once())
->method('getLoggerConfig')
->with(static::equalTo('test'))
->will(static::returnValue($loggerConfig));
$factory = $this->createMock(\Phlib\Logger\Factory::class);
- $logger = $this->createMock(\Phlib\Logger\LoggerType\Collection::class);
+ $logger = $this->createMock(\Phlib\Logger\LoggerType\Collection::class);
$factory->expects(static::once())
->method('createLogger')
->with(static::equalTo('test'), static::equalTo($loggerConfig))
@@ -40,17 +39,17 @@ public function testGetLoggerAgain()
{
$loggerConfig = [
'type' => 'stream',
- 'path' => '(filename)'
+ 'path' => '(filename)',
];
- $config = $this->createMock(\Phlib\Logger\Config::class);
+ $config = $this->createMock(\Phlib\Logger\Config::class);
$config->expects(static::once())
->method('getLoggerConfig')
->with(static::equalTo('test'))
->will(static::returnValue($loggerConfig));
$factory = $this->createMock(\Phlib\Logger\Factory::class);
- $logger = $this->createMock(\Phlib\Logger\LoggerType\Stream::class);
+ $logger = $this->createMock(\Phlib\Logger\LoggerType\Stream::class);
$factory->expects(static::once())
->method('createLogger')
->with(static::equalTo('test'), static::equalTo($loggerConfig))
@@ -70,19 +69,19 @@ public function testPrefix()
$prefix = 'logger-prefix-';
$loggerConfig = [
- 'type' => 'stream',
+ 'type' => 'stream',
'level' => LogLevel::CRITICAL,
- 'path' => '(filename)'
+ 'path' => '(filename)',
];
- $config = $this->createMock(\Phlib\Logger\Config::class);
+ $config = $this->createMock(\Phlib\Logger\Config::class);
$config->expects(static::once())
->method('getLoggerConfig')
->with(static::equalTo('test'))
->will(static::returnValue($loggerConfig));
$factory = $this->createMock(\Phlib\Logger\Factory::class);
- $logger = $this->createMock(\Phlib\Logger\LoggerType\Stream::class);
+ $logger = $this->createMock(\Phlib\Logger\LoggerType\Stream::class);
$factory->expects(static::once())
->method('createLogger')
->with(static::equalTo($prefix . 'test'))
@@ -97,19 +96,19 @@ public function testPrefix()
public function testGetLoggerCollection()
{
$loggerConfig = [
- 'type' => 'stream',
+ 'type' => 'stream',
'level' => LogLevel::WARNING,
- 'path' => '(filename)'
+ 'path' => '(filename)',
];
- $config = $this->createMock(\Phlib\Logger\Config::class);
+ $config = $this->createMock(\Phlib\Logger\Config::class);
$config->expects(static::once())
->method('getLoggerConfig')
->with(static::equalTo('test'))
->will(static::returnValue($loggerConfig));
- $factory = $this->createMock(\Phlib\Logger\Factory::class);
- $streamLogger = $this->createMock(\Phlib\Logger\LoggerType\Stream::class);
+ $factory = $this->createMock(\Phlib\Logger\Factory::class);
+ $streamLogger = $this->createMock(\Phlib\Logger\LoggerType\Stream::class);
$collectionLogger = $this->createMock(\Phlib\Logger\LoggerType\Collection::class);
$factory->expects(static::once())
->method('createLogger')
@@ -123,7 +122,7 @@ public function testGetLoggerCollection()
->with(
static::equalTo('test'),
static::equalTo([
- 'loggers' => [$streamLogger]
+ 'loggers' => [$streamLogger],
])
)
->will(static::returnValue($collectionLogger));