Skip to content

Commit

Permalink
Add Laravel 6 support
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-ivanov committed Sep 13, 2019
1 parent c49405e commit a7df1e3
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 45 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: php

php:
- 7.1
- 7.2
- 7.3

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Expand Down
20 changes: 10 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
6 changes: 3 additions & 3 deletions src/Loggable/FileChannel/MonologFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 1 addition & 8 deletions src/Loggable/Notifications/EmailChannel/EmailChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -34,20 +33,14 @@ protected function getEmailChannelHandler()
case 'mail':
case 'smtp':
case 'sendmail':
case 'mandrill':
$mailer = app('swift.mailer');
$message = $mailer->createMessage();
$message->setSubject($subject);
$message->setFrom(to_swiftmailer_emails($from));
$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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<!DOCTYPE html>';
$output .= '<html>';
Expand Down Expand Up @@ -118,7 +123,7 @@ protected function composeRow($header, $body = ' ')
</tr>";
}

protected function convertToString($data)
protected function convertToString($data): string
{
if (is_array($data)) {
return get_dump($data);
Expand Down
19 changes: 0 additions & 19 deletions tests/Loggable/Notifications/EmailChannel/EmailChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
{
Expand All @@ -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(
Expand Down

0 comments on commit a7df1e3

Please sign in to comment.