Skip to content

Commit f664a93

Browse files
committed
Support Laravel 9
1 parent a61d773 commit f664a93

File tree

10 files changed

+70
-98
lines changed

10 files changed

+70
-98
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
strategy:
1818
fail-fast: false
1919
matrix:
20-
php: [7.3, 7.4, 8.0]
20+
php: [8.0, 8.1]
2121
stability: [prefer-lowest, prefer-stable]
2222

2323
name: PHP ${{ matrix.php }} / ${{ matrix.stability }}

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
Logging and Notifications for Laravel Console Commands.
1717

1818
| Laravel | Console Logger |
19-
| ------- | :-----------------------------------------------------------------------: |
19+
|---------|---------------------------------------------------------------------------|
20+
| 9.x | [9.x](https://github.com/dmitry-ivanov/laravel-console-logger/tree/9.x) |
2021
| 8.x | [8.x](https://github.com/dmitry-ivanov/laravel-console-logger/tree/8.x) |
2122
| 7.x | [7.x](https://github.com/dmitry-ivanov/laravel-console-logger/tree/7.x) |
2223
| 6.x | [6.x](https://github.com/dmitry-ivanov/laravel-console-logger/tree/6.x) |

composer.json

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,21 @@
1212
"email": "[email protected]"
1313
}],
1414
"require": {
15-
"php": "^7.3|^8.0",
16-
"ext-json": "*",
17-
"illuminate/console": "^8.0",
18-
"illuminate/support": "^8.0",
19-
"illuminated/helper-functions": "^8.0",
15+
"php": "^8.0.2",
16+
"illuminate/console": "^9.0",
17+
"illuminate/support": "^9.0",
18+
"illuminated/helper-functions": "^9.0",
2019
"monolog/monolog": "^2.0",
2120
"psr/http-message": "^1.0",
22-
"psr/log": "^1.0|^2.0",
23-
"symfony/finder": "^5.1"
21+
"psr/log": "^1.0|^2.0|^3.0",
22+
"symfony/finder": "^6.0"
2423
},
2524
"require-dev": {
26-
"phpunit/phpunit": "^9.1",
27-
"mockery/mockery": "^1.3.2",
28-
"guzzlehttp/guzzle": "^6.5.5|^7.0.1",
29-
"orchestra/testbench": "^6.0",
30-
"illuminated/testing-tools": "^8.0"
25+
"phpunit/phpunit": "^9.5.10",
26+
"mockery/mockery": "^1.4.4",
27+
"guzzlehttp/guzzle": "^7.2",
28+
"orchestra/testbench": "^7.0",
29+
"illuminated/testing-tools": "^9.0"
3130
},
3231
"autoload": {
3332
"files": [

phpunit.xml.dist

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
4-
beStrictAboutTestsThatDoNotTestAnything="false"
5-
beStrictAboutOutputDuringTests="true"
6-
bootstrap="vendor/autoload.php"
7-
colors="true"
8-
convertErrorsToExceptions="true"
9-
convertNoticesToExceptions="true"
10-
convertWarningsToExceptions="true"
11-
processIsolation="false"
12-
stopOnError="false"
13-
stopOnFailure="false"
14-
verbose="true"
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
3+
backupGlobals="false"
4+
backupStaticAttributes="false"
5+
beStrictAboutTestsThatDoNotTestAnything="false"
6+
beStrictAboutOutputDuringTests="true"
7+
bootstrap="vendor/autoload.php"
8+
colors="true"
9+
convertErrorsToExceptions="true"
10+
convertNoticesToExceptions="true"
11+
convertWarningsToExceptions="true"
12+
processIsolation="false"
13+
stopOnError="false"
14+
stopOnFailure="false"
15+
verbose="true"
1516
>
1617
<testsuites>
1718
<testsuite name="Laravel Console Logger Test Suite">
1819
<directory suffix="Test.php">./tests</directory>
1920
</testsuite>
2021
</testsuites>
21-
<filter>
22-
<whitelist processUncoveredFilesFromWhitelist="true">
22+
23+
<coverage processUncoveredFiles="true">
24+
<include>
2325
<directory suffix=".php">./src</directory>
24-
</whitelist>
25-
</filter>
26+
</include>
27+
</coverage>
2628
</phpunit>

src/Loggable/Notifications/EmailChannel/EmailChannel.php

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44

55
use Illuminate\Support\Str;
66
use Monolog\Handler\DeduplicationHandler;
7-
use Monolog\Handler\SwiftMailerHandler;
7+
use Monolog\Handler\SymfonyMailerHandler;
88
use Monolog\Logger;
9-
use Swift_Mailer;
10-
use Swift_Message;
9+
use Symfony\Component\Mime\Email;
1110

1211
trait EmailChannel
1312
{
@@ -24,7 +23,7 @@ protected function useEmailNotifications()
2423
/**
2524
* Get the email channel handler.
2625
*
27-
* @return \Monolog\Handler\NativeMailerHandler|\Monolog\Handler\SwiftMailerHandler|\Monolog\Handler\DeduplicationHandler|false
26+
* @return \Monolog\Handler\SymfonyMailerHandler|\Monolog\Handler\DeduplicationHandler|false
2827
*/
2928
protected function getEmailChannelHandler()
3029
{
@@ -37,18 +36,13 @@ protected function getEmailChannelHandler()
3736
$from = $this->getEmailNotificationsFrom();
3837
$level = $this->getEmailNotificationsLevel();
3938

40-
/** @var Swift_Mailer $mailer */
41-
$mailer = app('mailer')->getSwiftMailer();
39+
$message = (new Email)
40+
->subject($subject)
41+
->from(...to_symfony_emails($from))
42+
->to(...to_symfony_emails($recipients));
4243

43-
/** @var Swift_Message $message */
44-
$message = $mailer->createMessage();
45-
$message->setSubject($subject);
46-
$message->setFrom(to_swiftmailer_emails($from));
47-
$message->setTo(to_swiftmailer_emails($recipients));
48-
$message->setContentType('text/html');
49-
$message->setCharset('utf-8');
50-
51-
$mailerHandler = new SwiftMailerHandler($mailer, $message, $level);
44+
$mailer = app('mailer')->getSymfonyTransport();
45+
$mailerHandler = new SymfonyMailerHandler($mailer, $message, $level);
5246
$mailerHandler->setFormatter(new MonologHtmlFormatter);
5347

5448
if ($this->useEmailNotificationsDeduplication()) {

tests/Loggable/Notifications/EmailChannel/EmailChannelTest.php

Lines changed: 23 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
use Illuminated\Console\Tests\App\Console\Commands\EmailNotificationsInvalidRecipientsCommand;
99
use Illuminated\Console\Tests\TestCase;
1010
use Monolog\Handler\DeduplicationHandler;
11-
use Monolog\Handler\SwiftMailerHandler;
11+
use Monolog\Handler\Handler;
12+
use Monolog\Handler\SymfonyMailerHandler;
1213
use Monolog\Logger;
13-
use Swift_Message;
14+
use Symfony\Component\Mime\Email;
1415

1516
class EmailChannelTest extends TestCase
1617
{
@@ -19,22 +20,22 @@ public function it_validates_and_filters_notification_recipients()
1920
{
2021
/** @var EmailNotificationsInvalidRecipientsCommand $command */
2122
$command = $this->runArtisan(new EmailNotificationsInvalidRecipientsCommand);
22-
$this->assertNotInstanceOf(SwiftMailerHandler::class, $command->emailChannelHandler());
23+
$this->assertNotInstanceOf(SymfonyMailerHandler::class, $command->emailChannelHandler());
2324
}
2425

2526
/** @test */
26-
public function it_uses_configured_monolog_swift_mailer_handler_on_mail_driver()
27+
public function it_uses_configured_monolog_symfony_mailer_handler_on_mail_driver()
2728
{
2829
config(['mail.driver' => 'mail']);
2930

3031
/** @var EmailNotificationsCommand $command */
3132
$command = $this->runArtisan(new EmailNotificationsCommand);
3233

33-
$this->assertMailerHandlersEqual($this->composeSwiftMailerHandler(), $command->emailChannelHandler());
34+
$this->assertMailerHandlersEqual($this->composeSymfonyMailerHandler(), $command->emailChannelHandler());
3435
}
3536

3637
/** @test */
37-
public function it_uses_configured_monolog_swift_mailer_handler_on_smtp_driver()
38+
public function it_uses_configured_monolog_symfony_mailer_handler_on_smtp_driver()
3839
{
3940
config([
4041
'mail.driver' => 'smtp',
@@ -45,18 +46,18 @@ public function it_uses_configured_monolog_swift_mailer_handler_on_smtp_driver()
4546
/** @var EmailNotificationsCommand $command */
4647
$command = $this->runArtisan(new EmailNotificationsCommand);
4748

48-
$this->assertMailerHandlersEqual($this->composeSwiftMailerHandler(), $command->emailChannelHandler());
49+
$this->assertMailerHandlersEqual($this->composeSymfonyMailerHandler(), $command->emailChannelHandler());
4950
}
5051

5152
/** @test */
52-
public function it_uses_configured_monolog_swift_mailer_handler_on_sendmail_driver()
53+
public function it_uses_configured_monolog_symfony_mailer_handler_on_sendmail_driver()
5354
{
5455
config(['mail.driver' => 'sendmail']);
5556

5657
/** @var EmailNotificationsCommand $command */
5758
$command = $this->runArtisan(new EmailNotificationsCommand);
5859

59-
$this->assertMailerHandlersEqual($this->composeSwiftMailerHandler(), $command->emailChannelHandler());
60+
$this->assertMailerHandlersEqual($this->composeSymfonyMailerHandler(), $command->emailChannelHandler());
6061
}
6162

6263
/** @test */
@@ -73,14 +74,11 @@ public function it_uses_configured_monolog_deduplication_handler_if_deduplicatio
7374
}
7475

7576
/**
76-
* Compose "swift mailer" handler.
77-
*
78-
* @param string $command
79-
* @return \Monolog\Handler\SwiftMailerHandler
77+
* Compose "symfony mailer" handler.
8078
*/
81-
private function composeSwiftMailerHandler($command = 'email-notifications-command')
79+
private function composeSymfonyMailerHandler(string $command = 'email-notifications-command'): SymfonyMailerHandler
8280
{
83-
$handler = new SwiftMailerHandler(app('mailer')->getSwiftMailer(), $this->composeMailerHandlerMessage($command), Logger::NOTICE);
81+
$handler = new SymfonyMailerHandler(app('mailer')->getSymfonyTransport(), $this->composeMailerHandlerMessage($command), Logger::NOTICE);
8482

8583
$handler->setFormatter(new MonologHtmlFormatter);
8684

@@ -89,49 +87,29 @@ private function composeSwiftMailerHandler($command = 'email-notifications-comma
8987

9088
/**
9189
* Compose "deduplication" handler.
92-
*
93-
* @return \Monolog\Handler\DeduplicationHandler
9490
*/
95-
private function composeDeduplicationHandler()
91+
private function composeDeduplicationHandler(): DeduplicationHandler
9692
{
9793
return new DeduplicationHandler(
98-
$this->composeSwiftMailerHandler('email-notifications-deduplication-command'), null, Logger::NOTICE, 60
94+
$this->composeSymfonyMailerHandler('email-notifications-deduplication-command'), null, Logger::NOTICE, 60
9995
);
10096
}
10197

10298
/**
10399
* Compose mailer handler message.
104-
*
105-
* @param string $command
106-
* @return \Swift_Message
107100
*/
108-
private function composeMailerHandlerMessage($command)
101+
private function composeMailerHandlerMessage(string $command): Email
109102
{
110-
/** @var Swift_Message $message */
111-
$message = app('mailer')->getSwiftMailer()->createMessage();
112-
$message->setSubject("[TESTING] %level_name% in `{$command}` command");
113-
$message->setFrom(to_swiftmailer_emails([
114-
'address' => '[email protected]',
115-
'name' => 'ICLogger Notification',
116-
]));
117-
$message->setTo(to_swiftmailer_emails([
118-
['address' => '[email protected]', 'name' => 'John Doe'],
119-
['address' => '[email protected]', 'name' => 'Jane Smith'],
120-
]));
121-
$message->setContentType('text/html');
122-
$message->setCharset('utf-8');
123-
124-
return $message;
103+
return (new Email())
104+
->subject("[TESTING] %level_name% in `{$command}` command")
105+
->from('ICLogger Notification <[email protected]>')
106+
->to('John Doe <[email protected]>', 'Jane Smith <[email protected]>');
125107
}
126108

127109
/**
128110
* Assert mailer handlers are equal.
129-
*
130-
* @param mixed $handler1
131-
* @param mixed $handler2
132-
* @return void
133111
*/
134-
protected function assertMailerHandlersEqual($handler1, $handler2)
112+
protected function assertMailerHandlersEqual(Handler $handler1, Handler $handler2): void
135113
{
136114
$handler1 = $this->normalizeMailerHandlerDump(get_dump($handler1));
137115
$handler2 = $this->normalizeMailerHandlerDump(get_dump($handler2));
@@ -141,13 +119,11 @@ protected function assertMailerHandlersEqual($handler1, $handler2)
141119
/**
142120
* Normalize the mailer handler dump.
143121
*
144-
* @param string $dump
145-
* @return string
122+
* @noinspection PhpUnnecessaryLocalVariableInspection
146123
*/
147-
private function normalizeMailerHandlerDump(string $dump)
124+
private function normalizeMailerHandlerDump(string $dump): string
148125
{
149126
$dump = preg_replace('/{#\d*/', '{', $dump);
150-
$dump = preg_replace('/".*[email protected]"/', '"normalized"', $dump);
151127
$dump = preg_replace('/\+"date": ".*?\.\d*"/', '+date: "normalized"', $dump);
152128
$dump = preg_replace('/date: .*?\.\d*/', 'date: "normalized"', $dump);
153129
$dump = preg_replace('/-dateTime: DateTimeImmutable @\d*/', '-dateTime: DateTimeImmutable @normalized', $dump);

tests/fixture/app/Console/Commands/EmailNotificationsCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function handle()
4242
/**
4343
* Create the email channel handler.
4444
*
45-
* @return \Monolog\Handler\NativeMailerHandler|\Monolog\Handler\SwiftMailerHandler|\Monolog\Handler\DeduplicationHandler|false
45+
* @return \Monolog\Handler\SymfonyMailerHandler|\Monolog\Handler\DeduplicationHandler|false
4646
*/
4747
public function createEmailChannelHandler()
4848
{
@@ -52,7 +52,7 @@ public function createEmailChannelHandler()
5252
/**
5353
* Get the email channel handler.
5454
*
55-
* @return \Monolog\Handler\NativeMailerHandler|\Monolog\Handler\SwiftMailerHandler|\Monolog\Handler\DeduplicationHandler|false
55+
* @return \Monolog\Handler\SymfonyMailerHandler|\Monolog\Handler\DeduplicationHandler|false
5656
*/
5757
public function emailChannelHandler()
5858
{

tests/fixture/app/Console/Commands/EmailNotificationsDeduplicationCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function handle()
5252
/**
5353
* Get the email channel handler.
5454
*
55-
* @return \Monolog\Handler\NativeMailerHandler|\Monolog\Handler\SwiftMailerHandler|\Monolog\Handler\DeduplicationHandler|false
55+
* @return \Monolog\Handler\SymfonyMailerHandler|\Monolog\Handler\DeduplicationHandler|false
5656
*/
5757
public function emailChannelHandler()
5858
{

tests/fixture/app/Console/Commands/EmailNotificationsInvalidRecipientsCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function handle()
4444
/**
4545
* Get the email channel handler.
4646
*
47-
* @return \Monolog\Handler\NativeMailerHandler|\Monolog\Handler\SwiftMailerHandler|\Monolog\Handler\DeduplicationHandler|false
47+
* @return \Monolog\Handler\SymfonyMailerHandler|\Monolog\Handler\DeduplicationHandler|false
4848
*/
4949
public function emailChannelHandler()
5050
{

tests/fixture/app/Console/Kernel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Illuminated\Console\Tests\App\Console\Commands\NamespacedCommand;
1414
use Illuminated\Console\Tests\App\Console\Commands\SeparatorLoggingCommand;
1515

16-
class Kernel extends \Orchestra\Testbench\Console\Kernel
16+
class Kernel extends \Orchestra\Testbench\Foundation\Console\Kernel
1717
{
1818
/**
1919
* The Artisan commands provided by your application.

0 commit comments

Comments
 (0)