Skip to content

Commit a92f856

Browse files
committed
Add Laravel 7 support
1 parent 37e9e23 commit a92f856

File tree

6 files changed

+49
-35
lines changed

6 files changed

+49
-35
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Logging and notifications for Laravel console commands.
1515

1616
| Laravel | Console Logger |
1717
| ------- | :-----------------------------------------------------------------------: |
18+
| 7.x | [7.x](https://github.com/dmitry-ivanov/laravel-console-logger/tree/7.x) |
1819
| 6.x | [6.x](https://github.com/dmitry-ivanov/laravel-console-logger/tree/6.x) |
1920
| 5.8.* | [5.8.*](https://github.com/dmitry-ivanov/laravel-console-logger/tree/5.8) |
2021
| 5.7.* | [5.7.*](https://github.com/dmitry-ivanov/laravel-console-logger/tree/5.7) |

composer.json

+11-11
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@
1212
"email": "[email protected]"
1313
}],
1414
"require": {
15-
"php": "^7.2",
15+
"php": "^7.2.5",
1616
"ext-json": "*",
17-
"illuminate/support": "^6.0",
18-
"illuminate/console": "^6.0",
19-
"illuminated/helper-functions": "^6.0",
20-
"monolog/monolog": "^1.12|^2.0",
17+
"illuminate/support": "^7.0",
18+
"illuminate/console": "^7.0",
19+
"illuminated/helper-functions": "^7.0",
20+
"monolog/monolog": "^2.0",
2121
"psr/http-message": "^1.0",
2222
"psr/log": "^1.0",
23-
"symfony/finder": "^4.3"
23+
"symfony/finder": "^5.0"
2424
},
2525
"require-dev": {
26-
"phpunit/phpunit": "^8.3",
27-
"mockery/mockery": "^1.2",
28-
"guzzlehttp/guzzle": "^6.3",
29-
"orchestra/testbench": "^4.0",
30-
"illuminated/testing-tools": "^6.0"
26+
"phpunit/phpunit": "^8.4|^9.0",
27+
"mockery/mockery": "^1.3.1",
28+
"guzzlehttp/guzzle": "^6.3.1|^7.0",
29+
"orchestra/testbench": "^5.0",
30+
"illuminated/testing-tools": "^7.0"
3131
},
3232
"autoload": {
3333
"files": [

src/Exceptions/ExceptionHandler.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace Illuminated\Console\Exceptions;
44

5-
use Exception;
65
use Illuminate\Foundation\Exceptions\Handler;
76
use Psr\Log\LoggerInterface;
7+
use Throwable;
88

99
class ExceptionHandler extends Handler
1010
{
@@ -67,10 +67,10 @@ public function setLogger(LoggerInterface $logger)
6767
* Note that this method doesn't decorate, but overwrite the parent method:
6868
* @see https://github.com/dmitry-ivanov/laravel-console-logger/pull/11
6969
*
70-
* @param \Exception $e
70+
* @param \Throwable $e
7171
* @return void
7272
*/
73-
public function report(Exception $e)
73+
public function report(Throwable $e)
7474
{
7575
$context = [
7676
'code' => $e->getCode(),
@@ -94,10 +94,10 @@ public function report(Exception $e)
9494
/**
9595
* Add Sentry support.
9696
*
97-
* @param \Exception $e
97+
* @param \Throwable $e
9898
* @return void
9999
*/
100-
private function addSentrySupport(Exception $e)
100+
private function addSentrySupport(Throwable $e)
101101
{
102102
if (app()->bound('sentry') && $this->shouldReport($e)) {
103103
app('sentry')->captureException($e);

src/Loggable/Notifications/EmailChannel/EmailChannel.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected function getEmailChannelHandler()
4646
case 'smtp':
4747
case 'sendmail':
4848
/** @var Swift_Mailer $mailer */
49-
$mailer = app('swift.mailer');
49+
$mailer = app('mailer')->getSwiftMailer();
5050

5151
/** @var Swift_Message $message */
5252
$message = $mailer->createMessage();

tests/Loggable/FileChannel/FileChannelTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ public function it_provides_automatic_file_rotation_and_only_30_latest_files_are
3232
$this->createLogFiles($path, 45);
3333
$this->assertFilesCount($path, 45);
3434

35-
$this->runArtisan(new GenericCommand)->emulateFileHandlerClose();
35+
/** @var GenericCommand $command */
36+
$command = $this->runArtisan(new GenericCommand);
37+
$command->emulateFileHandlerClose();
3638

3739
$this->assertFilesCount($path, 30);
3840
}

tests/Loggable/Notifications/EmailChannel/EmailChannelTest.php

+28-17
Original file line numberDiff line numberDiff line change
@@ -18,67 +18,78 @@ class EmailChannelTest extends TestCase
1818
/** @test */
1919
public function it_validates_and_filters_notification_recipients()
2020
{
21-
$handler = $this->runArtisan(new EmailNotificationsInvalidRecipientsCommand)->emailChannelHandler();
22-
$this->assertNotInstanceOf(SwiftMailerHandler::class, $handler);
21+
/** @var EmailNotificationsInvalidRecipientsCommand $command */
22+
$command = $this->runArtisan(new EmailNotificationsInvalidRecipientsCommand);
23+
$this->assertNotInstanceOf(SwiftMailerHandler::class, $command->emailChannelHandler());
2324
}
2425

2526
/** @test */
2627
public function it_is_disabled_on_null_driver()
2728
{
2829
config(['mail.driver' => 'null']);
2930

30-
$handler = $this->runArtisan(new EmailNotificationsCommand)->createEmailChannelHandler();
31+
/** @var EmailNotificationsCommand $command */
32+
$command = $this->runArtisan(new EmailNotificationsCommand);
3133

32-
$this->assertFalse($handler);
34+
$this->assertFalse($command->createEmailChannelHandler());
3335
}
3436

3537
/** @test */
3638
public function it_uses_configured_monolog_swift_mailer_handler_on_mail_driver()
3739
{
3840
config(['mail.driver' => 'mail']);
3941

40-
$handler = $this->runArtisan(new EmailNotificationsCommand)->emailChannelHandler();
42+
/** @var EmailNotificationsCommand $command */
43+
$command = $this->runArtisan(new EmailNotificationsCommand);
4144

42-
$this->assertMailerHandlersEqual($this->composeSwiftMailerHandler(), $handler);
45+
$this->assertMailerHandlersEqual($this->composeSwiftMailerHandler(), $command->emailChannelHandler());
4346
}
4447

4548
/** @test */
4649
public function it_uses_configured_monolog_swift_mailer_handler_on_smtp_driver()
4750
{
48-
config(['mail.driver' => 'smtp']);
51+
config([
52+
'mail.driver' => 'smtp',
53+
'mail.host' => 'example.com',
54+
'mail.port' => 123,
55+
]);
4956

50-
$handler = $this->runArtisan(new EmailNotificationsCommand)->emailChannelHandler();
57+
/** @var EmailNotificationsCommand $command */
58+
$command = $this->runArtisan(new EmailNotificationsCommand);
5159

52-
$this->assertMailerHandlersEqual($this->composeSwiftMailerHandler(), $handler);
60+
$this->assertMailerHandlersEqual($this->composeSwiftMailerHandler(), $command->emailChannelHandler());
5361
}
5462

5563
/** @test */
5664
public function it_uses_configured_monolog_swift_mailer_handler_on_sendmail_driver()
5765
{
5866
config(['mail.driver' => 'sendmail']);
5967

60-
$handler = $this->runArtisan(new EmailNotificationsCommand)->emailChannelHandler();
68+
/** @var EmailNotificationsCommand $command */
69+
$command = $this->runArtisan(new EmailNotificationsCommand);
6170

62-
$this->assertMailerHandlersEqual($this->composeSwiftMailerHandler(), $handler);
71+
$this->assertMailerHandlersEqual($this->composeSwiftMailerHandler(), $command->emailChannelHandler());
6372
}
6473

6574
/** @test */
6675
public function it_uses_configured_monolog_native_mailer_handler_on_other_drivers()
6776
{
6877
config(['mail.driver' => 'any-other']);
6978

70-
$handler = $this->runArtisan(new EmailNotificationsCommand)->emailChannelHandler();
79+
/** @var EmailNotificationsCommand $command */
80+
$command = $this->runArtisan(new EmailNotificationsCommand);
7181

72-
$this->assertMailerHandlersEqual($this->composeNativeMailerHandler(), $handler);
82+
$this->assertMailerHandlersEqual($this->composeNativeMailerHandler(), $command->emailChannelHandler());
7383
}
7484

7585
/** @test */
7686
public function it_uses_configured_monolog_deduplication_handler_if_deduplication_enabled()
7787
{
7888
config(['mail.driver' => 'any-other']);
7989

80-
/** @var \Monolog\Handler\DeduplicationHandler $handler */
81-
$handler = $this->runArtisan(new EmailNotificationsDeduplicationCommand)->emailChannelHandler();
90+
/** @var EmailNotificationsDeduplicationCommand $command */
91+
$command = $this->runArtisan(new EmailNotificationsDeduplicationCommand);
92+
$handler = $command->emailChannelHandler();
8293
$handler->flush();
8394

8495
$this->assertMailerHandlersEqual($this->composeDeduplicationHandler(), $handler);
@@ -91,7 +102,7 @@ public function it_uses_configured_monolog_deduplication_handler_if_deduplicatio
91102
*/
92103
private function composeSwiftMailerHandler()
93104
{
94-
$handler = new SwiftMailerHandler(app('swift.mailer'), $this->composeMailerHandlerMessage(), Logger::NOTICE);
105+
$handler = new SwiftMailerHandler(app('mailer')->getSwiftMailer(), $this->composeMailerHandlerMessage(), Logger::NOTICE);
95106

96107
$handler->setFormatter(new MonologHtmlFormatter);
97108

@@ -144,7 +155,7 @@ private function composeDeduplicationHandler()
144155
private function composeMailerHandlerMessage()
145156
{
146157
/** @var Swift_Message $message */
147-
$message = app('swift.mailer')->createMessage();
158+
$message = app('mailer')->getSwiftMailer()->createMessage();
148159
$message->setSubject('[TESTING] %level_name% in `email-notifications-command` command');
149160
$message->setFrom(to_swiftmailer_emails([
150161
'address' => '[email protected]',

0 commit comments

Comments
 (0)