ollily / ezlogging
Simplify the usage of - Logging with Monolog - Testing with PHPUnit - Reflection with PHP - Developer shortkeys for composer
Requires
- php: >=7.4
- monolog/monolog: ^2.10
- psr/log: ^1.0||^2.0||^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpstan/phpstan: ^2.1
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^9.6
- psalm/plugin-phpunit: ^0.19
- vimeo/psalm: ^5.26
Suggests
- bamarni/composer-bin-plugin: Having compatible versions
Provides
- psr/log-implementation: ^1.0||^2.0||^3.0
This package is auto-updated.
Last update: 2025-08-22 21:39:34 UTC
README
Table of ContentsDescription
Simplify the usage of
-
Logging with Monolog
-
Testing with PHPUnit
-
Reflection with PHP
-
Developer shortkeys for composer
Usage
Monolog
-
Monolog/ConsoleLogger - Logging to console
-
Log format:
%datetime% [%level%] %class%→%function%() - %message% %context% %extra%
-
-
Monolog/FileLogger - Logging to a file
-
Monolog/PlainLogger - Sending the output "as it is" to the console (raw)
PHPUnit
-
EasyGoingTestCase - All you need is already prepared, so concentrate on unit tests
Reflection
-
UnavailableFieldsTrait - Get value from unaccessable class fields (aka properties)
-
UnavailableMethodsTrait - Call unaccessable class methods
Examples
PHPUnit
Business Class<?php declare(strict_types=1); namespace foo; class FooClazz { public function isValid(): bool { return true; // not very complex, i know ;-) } }Related test class
<?php declare(strict_types=1); namespace foo; require_once __DIR__ . './bootstrap.php'; use PHPUnit\Framework\EasyGoingTestCase; class FooClazzTest extends EasyGoingTestCase { protected function prepareO2t(): FooClazz // cast to business class { return new FooClazz(); } protected function getCasto2t(): FooClazz // cast to business class { return $this->o2t; } public function testFoo(): void { $this->logger->debug('testFoo() - Start'); // test code static::assertTrue($this->getCasto2t()->isValid()); // or static::assertTrue($this->o2t->isValid()); $this->logger->info('testFoo() - End'); } }Log output
PHPUnit 9.6.25 by Sebastian Bergmann and contributors.
20250821-162846.609 [DEBUG ] PHPUnit\Framework\EasyGoingTestCase->testFoo() - testFoo() - Start
20250821-162846.611 [INFO ] PHPUnit\Framework\EasyGoingTestCase->testFoo() - testFoo() - End
..
Reflection
Extended class example<?php declare(strict_types=1); namespace foo; class FooClazz { private $privateFoo = 'privateFooValue'; protected function protectedFoo(): string { return 'protectedFooMethod'; } }Related extended test class example
<?php declare(strict_types=1); namespace foo; require_once __DIR__ . './bootstrap.php'; use ollily\Tools\Reflection\UnavailableFieldsTrait; use ollily\Tools\Reflection\UnavailableMethodsTrait; use PHPUnit\Framework\EasyGoingTestCase; class FooClazzTest extends EasyGoingTestCase { use UnavailableFieldsTrait; use UnavailableMethodsTrait; protected function prepareO2t(): FooClazz // cast to business class { return new FooClazz(); } protected function getCasto2t(): FooClazz // cast to business class { return $this->o2t; } public function testPrivateField(): void { $result = $this->getFieldFromO2t('privateFoo'); // or $result2 = $this->getFieldByReflection(FooClazz::class, 'privateFoo', $this->o2t); $this->logger->info("privateFoo is '${result}' or '${result2}'"); static::assertEquals('privateFooValue', $result); static::assertEquals($result, $result2); } public function testProtectedMethod(): void { $result = $this->callMethodOnO2t('protectedFoo'); // or $result2 = $this->callMethodByReflection(FooClazz::class, 'protectedFoo', $this->o2t); $this->logger->info("protectedFoo returns '${result}' or '${result2}'"); static::assertEquals('protectedFooMethod', $result); static::assertEquals($result, $result2); } }Log output
PHPUnit 9.6.25 by Sebastian Bergmann and contributors.
20250821-162846.588 [INFO ] PHPUnit\Framework\EasyGoingTestCase->testPrivateField() - privateFoo is 'privateFooValue' or 'privateFooValue'
20250821-162846.608 [INFO ] PHPUnit\Framework\EasyGoingTestCase->testProtectedMethod() - protectedFoo returns 'protectedFooMethod' or 'protectedFooMethod'
..
Additional Information
-
Configuration - How to configure
-
Composer Commands - New commands for composer
-
Analysis - Project Status
Notice
Nothing to notice so far.
Reference
(c) 2025 by Oliver Glowa