Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 31 additions & 14 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,49 @@ jobs:
strategy:
matrix:
include:
- php: '8.0'
- php: '8.2'
mode: low-deps
- php: '8.1'
mode: high-deps
- php: '8.2'
#mode: experimental
- php: '8.3'
- php: '8.4'
mode: high-deps
fail-fast: false

runs-on: ubuntu-20.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Cache Composer packages
- name: Get Composer cache dir
id: composer-cache
uses: actions/cache@v3
run: echo "dir=$(composer config cache-dir)" >> $GITHUB_OUTPUT

- name: Cache Composer
uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ matrix.mode }}-${{ hashFiles('**/composer.json') }}
restore-keys: |
${{ runner.os }}-php-
${{ runner.os }}-composer-${{ matrix.php }}-${{ matrix.mode }}-
${{ runner.os }}-composer-${{ matrix.php }}-
${{ runner.os }}-composer-

- name: Install Dependencies
run: |
if [[ "${{ matrix.mode }}" = low-deps ]]; then
COMPOSER_OPTIONS="--prefer-lowest"
if [[ "${{ matrix.mode }}" == "low-deps" ]]; then
# Force LTS of Bridge to avoid the bootstrapping big in prefer-lowest
composer require --no-update --dev symfony/phpunit-bridge:^6.4
COMPOSER_OPTIONS="--prefer-lowest --prefer-stable"
# in case of previously cache vendor folder
rm -rf vendor
fi
composer update --ansi --no-interaction --no-scripts --prefer-dist $COMPOSER_OPTIONS

- name: Audit Security
run: composer audit

- name: Execute tests (Unit and Feature tests) via PHPUnit
run: ./vendor/bin/simple-phpunit
env:
SYMFONY_PHPUNIT_VERSION: ${{ matrix.mode == 'low-deps' && '9.5' || '' }}
run: |
composer config --global use-parent-dir false
./vendor/bin/simple-phpunit
2 changes: 1 addition & 1 deletion DependencyInjection/DeamonLoggerExtraExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

/**
* This is the class that loads and manages your bundle configuration.
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ DeamonLoggerExtra Bundle
![Build status](https://github.com/FrDeamon/logger-extra-bundle/actions/workflows/unit-tests.yml/badge.svg?branch=master)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/FrDeamon/logger-extra-bundle/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/FrDeamon/logger-extra-bundle/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/FrDeamon/logger-extra-bundle/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/FrDeamon/logger-extra-bundle/?branch=master)
![symfony version](https://img.shields.io/badge/symfony->=6.0-blue.svg)
![php version](https://img.shields.io/badge/php->=8.0-blue.svg)
![symfony version](https://img.shields.io/badge/symfony->=7.0-blue.svg)
![php version](https://img.shields.io/badge/php->=8.2-blue.svg)

This project is used to add extra context information in your logs.

If you need compatibility with previous Symfony versions, have a look at previous releases.

Requirements
----------------
php >=8.0.2
php >=8.2

symfony/security-core
symfony/dependency-injection
Expand All @@ -31,7 +31,7 @@ Installation
You need to add a package to your dependency list :
```
// composer.json
"deamon/logger-extra-bundle": "^6.0"
"deamon/logger-extra-bundle": "^7.0"
```

Then enable the bundle into your kernel
Expand Down
13 changes: 5 additions & 8 deletions Tests/DependencyInjection/DeamonLoggerExtraExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function setUp(): void
$this->container = new ContainerBuilder();
}

public function testLoad()
public function testLoad(): void
{
$configs = [
$this->getValidConfigFull(),
Expand All @@ -57,7 +57,7 @@ public function testLoad()
$this->assertEquals('bar', $tag[0]['handler']);
}

public function testDefaultValue()
public function testDefaultValue(): void
{
$configs = [
$this->getValidConfigMin(),
Expand Down Expand Up @@ -98,7 +98,7 @@ public function testDefaultValue()
$this->assertEquals($defaultConfigValues, $definition2->getArgument(0));
}

public function testConvertStringHandlerToArray()
public function testConvertStringHandlerToArray(): void
{
$configs = [
[
Expand All @@ -123,7 +123,7 @@ public function testConvertStringHandlerToArray()
/**
* @return array
*/
private function getValidConfigFull()
private function getValidConfigFull(): array
{
return [
'application' => [
Expand Down Expand Up @@ -155,10 +155,7 @@ private function getValidConfigFull()
];
}

/**
* @return array
*/
private function getValidConfigMin()
private function getValidConfigMin(): array
{
return [
'application' => null,
Expand Down
30 changes: 15 additions & 15 deletions Tests/Processors/Monolog/DeamonLoggerExtraWebProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class DeamonLoggerExtraWebProcessorTest extends TestCase
{

public function testProcessorWithNullContainer()
public function testProcessorWithNullContainer(): void
{
$processor = new DeamonLoggerExtraWebProcessor();
$originalRecord = $this->getRecord();
Expand All @@ -26,7 +26,7 @@ public function testProcessorWithNullContainer()
/**
* @runInSeparateProcess
*/
public function testAddContextInfo()
public function testAddContextInfo(): void
{
$config = $this->getDisplayConfig([
'env' => true,
Expand All @@ -49,7 +49,7 @@ public function testAddContextInfo()
/**
* @runInSeparateProcess
*/
public function testAddContextInfoWithoutLocaleAndVersion()
public function testAddContextInfoWithoutLocaleAndVersion(): void
{
$config = $this->getDisplayConfig([
'env' => true,
Expand All @@ -69,7 +69,7 @@ public function testAddContextInfoWithoutLocaleAndVersion()
$this->assertArrayHasKeyAndEquals('application', $record->extra, 'foo_app');
}

public function testAddRequestInfo()
public function testAddRequestInfo(): void
{
$config = $this->getDisplayConfig(
[
Expand All @@ -92,7 +92,7 @@ public function testAddRequestInfo()
$this->assertArrayHasKeyAndEquals('client_ip', $record->extra, '123.456.789.123');
}

public function testAddOnlyUserInfoOnDefinedClass()
public function testAddOnlyUserInfoOnDefinedClass(): void
{
$config = $this->getDisplayConfig([
'user' => true,
Expand All @@ -109,7 +109,7 @@ public function testAddOnlyUserInfoOnDefinedClass()
$this->assertArrayNotHasKey('user_name', $record->extra);
}

public function testAddUserInfoWithNotExistingClass()
public function testAddUserInfoWithNotExistingClass(): void
{
$config = $this->getDisplayConfig([
'user' => true,
Expand All @@ -121,7 +121,7 @@ public function testAddUserInfoWithNotExistingClass()
$this->assertArrayNotHasKey('user_name', $record->extra);
}

public function testAddUserInfoWithNullClass()
public function testAddUserInfoWithNullClass(): void
{
$config = $this->getDisplayConfig([
'user' => true,
Expand All @@ -133,7 +133,7 @@ public function testAddUserInfoWithNullClass()
$this->assertArrayNotHasKey('user_name', $record->extra);
}

public function testAddUserinfoWithNoTokenStorage()
public function testAddUserinfoWithNoTokenStorage(): void
{
$config = $this->getDisplayConfig([
'user' => true,
Expand All @@ -145,7 +145,7 @@ public function testAddUserinfoWithNoTokenStorage()
$this->assertArrayNotHasKey('user_name', $record->extra);
}

public function testAddUserInfo()
public function testAddUserInfo(): void
{
$config = $this->getDisplayConfig([
'user' => true,
Expand All @@ -164,7 +164,7 @@ public function testAddUserInfo()
$this->assertArrayHasKeyAndEquals('user_name', $record->extra, 'foo');
}

protected function getDisplayConfig($trueValues, $channelPrefix = null, $user_class = '\Symfony\Component\Security\Core\User\UserInterface', $user_methods = null)
protected function getDisplayConfig($trueValues, $channelPrefix = null, $user_class = '\Symfony\Component\Security\Core\User\UserInterface', $user_methods = null): array
{
if (!is_array($user_methods)) {
$user_methods = [
Expand Down Expand Up @@ -195,13 +195,13 @@ protected function getDisplayConfig($trueValues, $channelPrefix = null, $user_cl
];
}

protected function assertArrayHasKeyAndEquals($key, $array, $value, $message = '')
protected function assertArrayHasKeyAndEquals($key, $array, $value, $message = ''): void
{
$this->assertArrayHasKey($key, $array);
$this->assertEquals($value, $array[$key], $message);
}

private function getRequestStack()
private function getRequestStack(): RequestStack
{
$request = new Request([], [], [
'_route' => 'requested_route',
Expand All @@ -217,12 +217,12 @@ private function getRequestStack()
return $stack;
}

private function getLoggerExtraContext($locale = 'fr', $version = null)
private function getLoggerExtraContext($locale = 'fr', $version = null): DeamonLoggerExtraContext
{
return new DeamonLoggerExtraContext('foo_app', $locale, $version);
}

private function getTokenStorage(UserInterface $user = null)
private function getTokenStorage(?UserInterface $user = null): TokenStorage
{
$storage = new TokenStorage();
$storage->setToken(new MyToken($user));
Expand Down Expand Up @@ -265,7 +265,7 @@ public function getSalt(): ?string
//not needed in tests
}

public function eraseCredentials()
public function eraseCredentials(): void
{
//not needed in tests
}
Expand Down
8 changes: 4 additions & 4 deletions Tests/Services/DeamonLoggerExtraContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ class DeamonLoggerExtraContextTest extends TestCase
*
* @param string $locale
*/
public function testGetLocale($locale)
public function testGetLocale($locale): void
{
$context = new DeamonLoggerExtraContext('', $locale);
$this->assertEquals($locale, $context->getLocale(), sprintf('locale should be %s, %s returned.', $locale, $context->getLocale()));
}

public function getLocaleDataset()
public function getLocaleDataset(): array
{
return [
['fr', 'locale should be fr'],
Expand All @@ -31,13 +31,13 @@ public function getLocaleDataset()
*
* @param $applicationName
*/
public function testGetApplicationName($applicationName)
public function testGetApplicationName($applicationName): void
{
$context = new DeamonLoggerExtraContext($applicationName, 'fr');
$this->assertEquals($applicationName, $context->getApplicationName(), sprintf('application_name should be %s, %s returned.', $applicationName, $context->getApplicationName()));
}

public function getApplicationNameDataset()
public function getApplicationNameDataset(): array
{
return [
['github.com/deamon'],
Expand Down
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
"Log"
],
"require": {
"php": ">=8.0.2",
"symfony/security-core": "^6.0",
"symfony/dependency-injection": "^6.0",
"symfony/monolog-bridge": "^6.0",
"php": ">=8.2",
"symfony/security-core": "^7.0",
"symfony/dependency-injection": "^7.0",
"symfony/monolog-bridge": "^7.0",
"monolog/monolog": "^3.0",
"symfony/http-kernel": "^6.0",
"symfony/http-foundation": "^6.0",
"symfony/config": "^6.0"
"symfony/http-kernel": "^7.0",
"symfony/http-foundation": "^7.2",
"symfony/config": "^7.0"
},
"require-dev": {
"symfony/phpunit-bridge": "^6.0"
"symfony/phpunit-bridge": "^7.0"
},
"autoload": {
"psr-4": {
Expand All @@ -36,7 +36,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "6.0.x-dev"
"dev-master": "7.0.x-dev"
}
},
"suggest": {
Expand Down
Loading