From a7df1e338bac88f663fb52a1027bae98ee0d7066 Mon Sep 17 00:00:00 2001 From: Dmitry Ivanov Date: Fri, 13 Sep 2019 23:05:21 +0300 Subject: [PATCH] Add Laravel 6 support --- .travis.yml | 1 - README.md | 1 + composer.json | 20 +++++++++---------- src/Loggable/FileChannel/MonologFormatter.php | 6 +++--- .../MonologDatabaseHandler.php | 5 +++-- .../EmailChannel/EmailChannel.php | 9 +-------- .../EmailChannel/MonologHtmlFormatter.php | 9 +++++++-- .../EmailChannel/EmailChannelTest.php | 19 ------------------ 8 files changed, 25 insertions(+), 45 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9cfe483..ebe0100 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: php php: - - 7.1 - 7.2 - 7.3 diff --git a/README.md b/README.md index 74e643f..2bdcdf9 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ Logging and notifications for Laravel console commands. | Laravel | Console Logger | | ------- | :-----------------------------------------------------------------------: | +| 6.x | [6.x](https://github.com/dmitry-ivanov/laravel-console-logger/tree/6.x) | | 5.8.* | [5.8.*](https://github.com/dmitry-ivanov/laravel-console-logger/tree/5.8) | | 5.7.* | [5.7.*](https://github.com/dmitry-ivanov/laravel-console-logger/tree/5.7) | | 5.6.* | [5.6.*](https://github.com/dmitry-ivanov/laravel-console-logger/tree/5.6) | diff --git a/composer.json b/composer.json index 6edb692..ba347c4 100644 --- a/composer.json +++ b/composer.json @@ -12,21 +12,21 @@ "email": "dmitry.g.ivanov@gmail.com" }], "require": { - "php": "^7.1.3", - "illuminate/support": "5.8.*", - "illuminate/console": "5.8.*", - "illuminated/helper-functions": "5.8.*", - "monolog/monolog": "^1.12", + "php": "^7.2", + "illuminate/support": "^6.0", + "illuminate/console": "^6.0", + "illuminated/helper-functions": "^6.0", + "monolog/monolog": "^1.12|^2.0", "psr/http-message": "^1.0", "psr/log": "^1.0", - "symfony/finder": "^4.2" + "symfony/finder": "^4.3" }, "require-dev": { - "phpunit/phpunit": "^7.5|^8.0", - "mockery/mockery": "^1.0", + "phpunit/phpunit": "^8.3", + "mockery/mockery": "^1.2", "guzzlehttp/guzzle": "^6.3", - "orchestra/testbench": "3.8.*", - "illuminated/testing-tools": "5.8.*" + "orchestra/testbench": "^4.0", + "illuminated/testing-tools": "^6.0" }, "autoload": { "files": [ diff --git a/src/Loggable/FileChannel/MonologFormatter.php b/src/Loggable/FileChannel/MonologFormatter.php index e02c5ba..5f224fa 100644 --- a/src/Loggable/FileChannel/MonologFormatter.php +++ b/src/Loggable/FileChannel/MonologFormatter.php @@ -9,10 +9,10 @@ class MonologFormatter extends LineFormatter { public function __construct() { - parent::__construct("[%datetime%]: [%level_name%]: %message%\n%context%\n", null, true, true); + parent::__construct("[%datetime%]: [%level_name%]: %message%\n%context%\n", 'Y-m-d H:i:s', true, true); } - public function format(array $record) + public function format(array $record): string { if ($record['message'] == '%separator%') { return str_repeat("\n", 11); @@ -22,7 +22,7 @@ public function format(array $record) return rtrim($output) . "\n"; } - protected function convertToString($data) + protected function convertToString($data): string { if (is_array($data)) { return get_dump($data); diff --git a/src/Loggable/Notifications/DatabaseChannel/MonologDatabaseHandler.php b/src/Loggable/Notifications/DatabaseChannel/MonologDatabaseHandler.php index 4d0cf7a..10d60c8 100644 --- a/src/Loggable/Notifications/DatabaseChannel/MonologDatabaseHandler.php +++ b/src/Loggable/Notifications/DatabaseChannel/MonologDatabaseHandler.php @@ -41,10 +41,11 @@ protected function guaranteeTableExists() }); } - protected function write(array $record) + protected function write(array $record): void { if (!empty($this->callback)) { - return call_user_func($this->callback, $record); + call_user_func($this->callback, $record); + return; } $now = Carbon::now(); diff --git a/src/Loggable/Notifications/EmailChannel/EmailChannel.php b/src/Loggable/Notifications/EmailChannel/EmailChannel.php index d05ba81..cf68934 100644 --- a/src/Loggable/Notifications/EmailChannel/EmailChannel.php +++ b/src/Loggable/Notifications/EmailChannel/EmailChannel.php @@ -3,7 +3,6 @@ namespace Illuminated\Console\Loggable\Notifications\EmailChannel; use Monolog\Logger; -use Monolog\Handler\MandrillHandler; use Monolog\Handler\SwiftMailerHandler; use Monolog\Handler\NativeMailerHandler; use Monolog\Handler\DeduplicationHandler; @@ -34,7 +33,6 @@ protected function getEmailChannelHandler() case 'mail': case 'smtp': case 'sendmail': - case 'mandrill': $mailer = app('swift.mailer'); $message = $mailer->createMessage(); $message->setSubject($subject); @@ -42,12 +40,7 @@ protected function getEmailChannelHandler() $message->setTo(to_swiftmailer_emails($recipients)); $message->setContentType('text/html'); $message->setCharset('utf-8'); - - if ($driver == 'mandrill') { - $mailerHandler = new MandrillHandler(config('services.mandrill.secret'), $message, $level); - } else { - $mailerHandler = new SwiftMailerHandler($mailer, $message, $level); - } + $mailerHandler = new SwiftMailerHandler($mailer, $message, $level); break; default: diff --git a/src/Loggable/Notifications/EmailChannel/MonologHtmlFormatter.php b/src/Loggable/Notifications/EmailChannel/MonologHtmlFormatter.php index d3cdd64..102ae52 100644 --- a/src/Loggable/Notifications/EmailChannel/MonologHtmlFormatter.php +++ b/src/Loggable/Notifications/EmailChannel/MonologHtmlFormatter.php @@ -6,7 +6,12 @@ class MonologHtmlFormatter extends HtmlFormatter { - public function format(array $record) + public function __construct() + { + parent::__construct('Y-m-d H:i:s'); + } + + public function format(array $record): string { $output = ''; $output .= ''; @@ -118,7 +123,7 @@ protected function composeRow($header, $body = ' ') "; } - protected function convertToString($data) + protected function convertToString($data): string { if (is_array($data)) { return get_dump($data); diff --git a/tests/Loggable/Notifications/EmailChannel/EmailChannelTest.php b/tests/Loggable/Notifications/EmailChannel/EmailChannelTest.php index 448c5c8..e86d4b6 100644 --- a/tests/Loggable/Notifications/EmailChannel/EmailChannelTest.php +++ b/tests/Loggable/Notifications/EmailChannel/EmailChannelTest.php @@ -3,7 +3,6 @@ namespace Illuminated\Console\Tests\Loggable\Notifications\EmailChannel; use Monolog\Logger; -use Monolog\Handler\MandrillHandler; use Illuminated\Console\Tests\TestCase; use Monolog\Handler\SwiftMailerHandler; use Monolog\Handler\NativeMailerHandler; @@ -59,15 +58,6 @@ public function it_uses_configured_monolog_swift_mailer_handler_on_sendmail_driv $this->assertMailerHandlersEqual($this->composeSwiftMailerHandler(), $handler); } - /** @test */ - public function it_uses_configured_monolog_mandrill_mailer_handler_on_mandrill_driver() - { - config(['mail.driver' => 'mandrill', 'services.mandrill.secret' => 'secret']); - $handler = $this->runArtisan(new EmailNotificationsCommand)->emailChannelHandler(); - - $this->assertMailerHandlersEqual($this->composeMandrillMailerHandler(), $handler); - } - /** @test */ public function it_uses_configured_monolog_native_mailer_handler_on_other_drivers() { @@ -94,15 +84,6 @@ private function composeSwiftMailerHandler() return $handler; } - private function composeMandrillMailerHandler() - { - $handler = new MandrillHandler( - config('services.mandrill.secret'), $this->composeMailerHandlerMessage(), Logger::NOTICE - ); - $handler->setFormatter(new MonologHtmlFormatter); - return $handler; - } - private function composeNativeMailerHandler($name = 'email-notifications-command') { $handler = new NativeMailerHandler(