From 730ce88ab732feabcd87345b4f5f5b7e18007dce Mon Sep 17 00:00:00 2001 From: Brian Moon Date: Wed, 10 Sep 2025 15:04:17 -0500 Subject: [PATCH 1/3] Make compatible with PHP 8 --- .github/workflows/ci.yml | 33 ++++++++++++ .gitignore | 1 + composer.json | 5 +- phpunit.xml.dist | 65 ++++++++---------------- src/FluentLogger.php | 2 +- tests/Fluent/Logger/BaseLoggerTest.php | 4 +- tests/Fluent/Logger/EntityTest.php | 2 +- tests/Fluent/Logger/FluentLoggerTest.php | 19 ++++--- tests/Fluent/Logger/JsonPackerTest.php | 4 +- 9 files changed, 74 insertions(+), 61 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..1f8a845 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,33 @@ +name: Testing + +on: [push] + +jobs: + test: + + runs-on: ubuntu-latest + + strategy: + matrix: + php-versions: ['8.0', '8.1', '8.2', '8.3', '8.4'] + include: + - operating-system: 'ubuntu-latest' + php-versions: '8.0' + phpunit-versions: 9 + + steps: + + - name: Checkout + uses: actions/checkout@v3 + + - name: Composer Install + uses: php-actions/composer@v6 + with: + php_version: ${{ matrix.php-versions }} + + - name: PHPUnit tests + uses: php-actions/phpunit@v4 + with: + php_extensions: "pcov" + version: "9.6" + php_version: ${{ matrix.php-versions }} diff --git a/.gitignore b/.gitignore index 3045a86..51626dd 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ builds .idea docs phpunit.xml +.phpunit.result.cache tmp/ *.iml composer.lock diff --git a/composer.json b/composer.json index a992ddc..88b5cd1 100644 --- a/composer.json +++ b/composer.json @@ -20,11 +20,10 @@ } ], "require": { - "php": "^5.6" + "php": "^8.0" }, "require-dev": { - "phpunit/phpunit": "~4.3", - "phpunit/phpunit-mock-objects": "2.3.0" + "phpunit/phpunit": "^9.5" }, "autoload": { "psr-4": {"Fluent\\Logger\\": "src/"} diff --git a/phpunit.xml.dist b/phpunit.xml.dist index ad9ccd3..ce37ae1 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,48 +1,25 @@ - - - - - + + + + + ./src + + + ./tests + ./vendor + + + + + - - tests + + ./tests - - - - - - - - - - src - - examples - tests - cookbooks - builds - - - + + + functional + + diff --git a/src/FluentLogger.php b/src/FluentLogger.php index 027b75f..7f9686f 100644 --- a/src/FluentLogger.php +++ b/src/FluentLogger.php @@ -108,7 +108,7 @@ class FluentLogger implements LoggerInterface public function __construct($host = FluentLogger::DEFAULT_ADDRESS, $port = FluentLogger::DEFAULT_LISTEN_PORT, array $options = array(), - PackerInterface $packer = null) + ?PackerInterface $packer = null) { /* keep original host and port */ $this->host = $host; diff --git a/tests/Fluent/Logger/BaseLoggerTest.php b/tests/Fluent/Logger/BaseLoggerTest.php index b581ca7..bb1cfa6 100644 --- a/tests/Fluent/Logger/BaseLoggerTest.php +++ b/tests/Fluent/Logger/BaseLoggerTest.php @@ -11,7 +11,7 @@ function fluentTests_FluentLogger_DummyFunction() { } -class BaseLoggerTest extends \PHPUnit_Framework_TestCase +class BaseLoggerTest extends \PHPUnit\Framework\TestCase { /** * testing compatible before and after @@ -42,10 +42,10 @@ function () { /** * @dataProvider invalidErrorHandlerProvider - * @expectedException InvalidArgumentException */ public function testRegisterInvalidErrorHandler($eh) { + $this->expectException(\InvalidArgumentException::class); $base = $this->getMockForAbstractClass('Fluent\Logger\FluentLogger'); $base->registerErrorHandler($eh); } diff --git a/tests/Fluent/Logger/EntityTest.php b/tests/Fluent/Logger/EntityTest.php index 725b10c..abee074 100644 --- a/tests/Fluent/Logger/EntityTest.php +++ b/tests/Fluent/Logger/EntityTest.php @@ -3,7 +3,7 @@ use Fluent\Logger\Entity; -class EntityTest extends \PHPUnit_Framework_TestCase +class EntityTest extends \PHPUnit\Framework\TestCase { const TAG = "debug.test"; diff --git a/tests/Fluent/Logger/FluentLoggerTest.php b/tests/Fluent/Logger/FluentLoggerTest.php index 71a2225..489ee17 100644 --- a/tests/Fluent/Logger/FluentLoggerTest.php +++ b/tests/Fluent/Logger/FluentLoggerTest.php @@ -5,13 +5,13 @@ use Fluent\Logger; use Fluent\Logger\FluentLogger; -class FluentLoggerTest extends \PHPUnit_Framework_TestCase +class FluentLoggerTest extends \PHPUnit\Framework\TestCase { const TAG = 'debug.test'; const OBJECT_KEY = 'hello'; const OBJECT_VALUE = 'world'; - public function tearDown() + public function tearDown(): void { FluentLogger::clearInstances(); } @@ -104,7 +104,9 @@ private function setSocket($logger, $socket) private function getMockOfLogger(array $method) { - return $this->getMock("Fluent\Logger\FluentLogger", array("write"), array("localhost")); + return $this->getMockBuilder(\Fluent\Logger\FluentLogger::class) + ->onlyMethods(array("write")) + ->getMock(); } /** @@ -164,12 +166,13 @@ public function testClearInstances() $prop = new \ReflectionProperty("\Fluent\Logger\FluentLogger", "instances"); $prop->setAccessible(true); - FluentLogger::open("localhost", 1191); - FluentLogger::open("localhost", 1192); - $this->assertCount(2, $prop->getValue("FluentLogger")); + $logger = new FluentLogger("localhost"); + $logger::open("localhost", 1191); + $logger::open("localhost", 1192); + $this->assertCount(2, $prop->getValue($logger)); - FluentLogger::clearInstances(); - $this->assertCount(0, $prop->getValue("FluentLogger")); + $logger::clearInstances(); + $this->assertCount(0, $prop->getValue($logger)); } public function testMergeOptions() diff --git a/tests/Fluent/Logger/JsonPackerTest.php b/tests/Fluent/Logger/JsonPackerTest.php index 1d0e97e..09aaf04 100644 --- a/tests/Fluent/Logger/JsonPackerTest.php +++ b/tests/Fluent/Logger/JsonPackerTest.php @@ -4,7 +4,7 @@ use Fluent\Logger\Entity; use Fluent\Logger\JsonPacker; -class JsonPackerTest extends \PHPUnit_Framework_TestCase +class JsonPackerTest extends \PHPUnit\Framework\TestCase { const TAG = "debug.test"; const EXPECTED_TIME = 123456789; @@ -12,7 +12,7 @@ class JsonPackerTest extends \PHPUnit_Framework_TestCase protected $time; protected $expected_data = array(); - public function setUp() + public function setUp(): void { $this->expected_data = array("abc" => "def"); } From 98e137194b9a9eae68694a8688c8f730f00adef6 Mon Sep 17 00:00:00 2001 From: Brian Moon Date: Wed, 10 Sep 2025 15:08:59 -0500 Subject: [PATCH 2/3] Update name --- composer.json | 59 ++++++++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/composer.json b/composer.json index 88b5cd1..c8b977f 100644 --- a/composer.json +++ b/composer.json @@ -1,31 +1,36 @@ { - "name": "fluent/logger", - "type": "library", - "description": "a logging library for Fluentd", - "keywords": ["log","logging"], - "homepage": "http://github.com/fluent/fluent-logger-php", - "license": "Apache", - "authors": [ - { - "name": "Shuhei Tanuma", - "email": "chobieee@gmail.com" - }, - { - "name": "Sotaro Karasawa", - "email": "sotarok@crocos.co.jp" - }, - { - "name": "DQNEO", - "email": "dqneoo@gmail.com" - } - ], - "require": { - "php": "^8.0" + "name": "dealnews/fluent-logger", + "type": "library", + "description": "a logging library for Fluentd", + "keywords": [ + "log", + "logging" + ], + "homepage": "http://github.com/fluent/fluent-logger-php", + "license": "Apache", + "authors": [ + { + "name": "Shuhei Tanuma", + "email": "chobieee@gmail.com" }, - "require-dev": { - "phpunit/phpunit": "^9.5" + { + "name": "Sotaro Karasawa", + "email": "sotarok@crocos.co.jp" }, - "autoload": { - "psr-4": {"Fluent\\Logger\\": "src/"} + { + "name": "DQNEO", + "email": "dqneoo@gmail.com" } -} + ], + "require": { + "php": "^8.0" + }, + "require-dev": { + "phpunit/phpunit": "^9.5" + }, + "autoload": { + "psr-4": { + "Fluent\\Logger\\": "src/" + } + } +} \ No newline at end of file From 58b3850f81af134f5274c2922170d9685a1b9bc0 Mon Sep 17 00:00:00 2001 From: Brian Moon Date: Wed, 10 Sep 2025 15:11:59 -0500 Subject: [PATCH 3/3] Fix license --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c8b977f..0765913 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ "logging" ], "homepage": "http://github.com/fluent/fluent-logger-php", - "license": "Apache", + "license": "Apache-2.0", "authors": [ { "name": "Shuhei Tanuma",