Skip to content

Commit 725c0af

Browse files
committed
ICL: illuminated/testing-tools used.
1 parent e7dbfeb commit 725c0af

File tree

6 files changed

+25
-61
lines changed

6 files changed

+25
-61
lines changed

tests/Loggable/FileChannel/FileChannelTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
<?php
22

33
use Carbon\Carbon;
4+
use Illuminated\Testing\Asserts\LogFileAsserts;
5+
use Illuminated\Testing\InteractsWithConsole;
46

57
class FileChannelTest extends TestCase
68
{
9+
use InteractsWithConsole;
10+
use LogFileAsserts;
11+
712
/** @test */
813
public function it_creates_log_file_according_to_the_command_name_and_current_date()
914
{
@@ -27,7 +32,7 @@ public function it_provides_automatic_file_rotation_and_only_30_latest_files_are
2732
$this->createBunchOfOldLogsInCount45($path);
2833
$this->assertCount(45, File::files($path));
2934

30-
$this->runViaObject(GenericCommand::class)->emulateFileHandlerClose();
35+
$this->runConsoleCommand(GenericCommand::class)->emulateFileHandlerClose();
3136

3237
$this->assertCount(30, File::files($path));
3338
}

tests/Loggable/Notifications/EmailChannel/EmailChannelTest.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
use Illuminated\Console\Loggable\Notifications\EmailChannel\MonologHtmlFormatter;
4+
use Illuminated\Testing\InteractsWithConsole;
45
use Monolog\Handler\DeduplicationHandler;
56
use Monolog\Handler\MandrillHandler;
67
use Monolog\Handler\NativeMailerHandler;
@@ -9,18 +10,20 @@
910

1011
class EmailChannelTest extends TestCase
1112
{
13+
use InteractsWithConsole;
14+
1215
/** @test */
1316
public function it_validates_and_filters_notification_recipients()
1417
{
15-
$handler = $this->runViaObject(EmailNotificationsInvalidRecipientsCommand::class)->mailerHandler();
18+
$handler = $this->runConsoleCommand(EmailNotificationsInvalidRecipientsCommand::class)->mailerHandler();
1619
$this->assertNotInstanceOf(SwiftMailerHandler::class, $handler);
1720
}
1821

1922
/** @test */
2023
public function it_uses_configured_monolog_swift_mailer_handler_on_mail_driver()
2124
{
2225
config(['mail.driver' => 'mail']);
23-
$handler = $this->runViaObject(EmailNotificationsCommand::class)->mailerHandler();
26+
$handler = $this->runConsoleCommand(EmailNotificationsCommand::class)->mailerHandler();
2427

2528
$this->assertMailerHandlersAreEqual($this->composeSwiftMailerHandler(), $handler);
2629
}
@@ -29,7 +32,7 @@ public function it_uses_configured_monolog_swift_mailer_handler_on_mail_driver()
2932
public function it_uses_configured_monolog_swift_mailer_handler_on_smtp_driver()
3033
{
3134
config(['mail.driver' => 'smtp']);
32-
$handler = $this->runViaObject(EmailNotificationsCommand::class)->mailerHandler();
35+
$handler = $this->runConsoleCommand(EmailNotificationsCommand::class)->mailerHandler();
3336

3437
$this->assertMailerHandlersAreEqual($this->composeSwiftMailerHandler(), $handler);
3538
}
@@ -38,7 +41,7 @@ public function it_uses_configured_monolog_swift_mailer_handler_on_smtp_driver()
3841
public function it_uses_configured_monolog_swift_mailer_handler_on_sendmail_driver()
3942
{
4043
config(['mail.driver' => 'sendmail']);
41-
$handler = $this->runViaObject(EmailNotificationsCommand::class)->mailerHandler();
44+
$handler = $this->runConsoleCommand(EmailNotificationsCommand::class)->mailerHandler();
4245

4346
$this->assertMailerHandlersAreEqual($this->composeSwiftMailerHandler(), $handler);
4447
}
@@ -47,7 +50,7 @@ public function it_uses_configured_monolog_swift_mailer_handler_on_sendmail_driv
4750
public function it_uses_configured_monolog_mandrill_mailer_handler_on_mandrill_driver()
4851
{
4952
config(['mail.driver' => 'mandrill', 'services.mandrill.secret' => 'secret']);
50-
$handler = $this->runViaObject(EmailNotificationsCommand::class)->mailerHandler();
53+
$handler = $this->runConsoleCommand(EmailNotificationsCommand::class)->mailerHandler();
5154

5255
$this->assertMailerHandlersAreEqual($this->composeMandrillMailerHandler(), $handler);
5356
}
@@ -56,7 +59,7 @@ public function it_uses_configured_monolog_mandrill_mailer_handler_on_mandrill_d
5659
public function it_uses_configured_monolog_native_mailer_handler_on_other_drivers()
5760
{
5861
config(['mail.driver' => 'any-other']);
59-
$handler = $this->runViaObject(EmailNotificationsCommand::class)->mailerHandler();
62+
$handler = $this->runConsoleCommand(EmailNotificationsCommand::class)->mailerHandler();
6063

6164
$this->assertMailerHandlersAreEqual($this->composeNativeMailerHandler(), $handler);
6265
}
@@ -65,7 +68,7 @@ public function it_uses_configured_monolog_native_mailer_handler_on_other_driver
6568
public function it_uses_configured_monolog_deduplication_handler_if_deduplication_enabled()
6669
{
6770
config(['mail.driver' => 'any-other']);
68-
$handler = $this->runViaObject(EmailNotificationsDeduplicationCommand::class)->mailerHandler();
71+
$handler = $this->runConsoleCommand(EmailNotificationsDeduplicationCommand::class)->mailerHandler();
6972
$handler->flush();
7073

7174
$this->assertMailerHandlersAreEqual($this->composeDeduplicationHandler(), $handler);

tests/Loggable/Notifications/EmailChannel/MonologHtmlFormatterTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
<?php
22

33
use Illuminated\Console\Loggable\Notifications\EmailChannel\MonologHtmlFormatter;
4+
use Illuminated\Testing\EmulatesEnvironment;
45
use Monolog\Logger;
56

67
class MonologHtmlFormatterTest extends TestCase
78
{
9+
use EmulatesEnvironment;
10+
811
/** @test */
912
public function it_properly_formats_debug_records()
1013
{

tests/LoggableTraitOnMysqlTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
<?php
22

33
use Illuminated\Console\Exceptions\ExceptionHandler;
4+
use Illuminated\Testing\Asserts\LogFileAsserts;
45
use Monolog\Handler\RotatingFileHandler;
56
use Psr\Log\LoggerInterface;
67

78
class LoggableTraitOnMysqlTest extends TestCase
89
{
10+
use LogFileAsserts;
11+
912
protected function setUpDatabase()
1013
{
1114
config([

tests/LoggableTraitTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
<?php
22

33
use Illuminated\Console\Exceptions\ExceptionHandler;
4+
use Illuminated\Testing\Asserts\LogFileAsserts;
45
use Monolog\Handler\RotatingFileHandler;
56
use Psr\Log\LoggerInterface;
67

78
class LoggableTraitTest extends TestCase
89
{
10+
use LogFileAsserts;
11+
912
/** @test */
1013
public function it_writes_to_log_file_information_header_each_iteration()
1114
{

tests/TestCase.php

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
<?php
22

33
use Illuminate\Contracts\Console\Kernel as KernelContract;
4-
use Symfony\Component\Console\Input\ArrayInput;
5-
use Symfony\Component\Console\Output\BufferedOutput;
64
use Symfony\Component\Finder\Finder;
75

86
abstract class TestCase extends \Orchestra\Testbench\TestCase
@@ -38,57 +36,6 @@ protected function resolveApplicationConsoleKernel($app)
3836
$app->singleton(KernelContract::class, Kernel::class);
3937
}
4038

41-
protected function emulateProduction()
42-
{
43-
$this->app->detectEnvironment(function () {
44-
return 'production';
45-
});
46-
}
47-
48-
protected function runViaObject($class)
49-
{
50-
$command = new $class;
51-
$command->setLaravel($this->app);
52-
$command->run(new ArrayInput([]), new BufferedOutput);
53-
54-
return $command;
55-
}
56-
57-
public function assertLogFileExists($path)
58-
{
59-
$this->assertFileExists(storage_path("logs/{$path}"));
60-
}
61-
62-
public function assertLogFileContains($path, $expected)
63-
{
64-
$expected = !is_array($expected) ? [$expected] : $expected;
65-
$content = File::get(storage_path("logs/{$path}"));
66-
67-
foreach ($expected as $item) {
68-
$pattern = $this->normalizeExpectedFileContent($item);
69-
$this->assertRegExp($pattern, $content, "Failed asserting that file contains `{$item}`.");
70-
}
71-
}
72-
73-
public function assertLogFileNotContains($path, $expected)
74-
{
75-
$expected = !is_array($expected) ? [$expected] : $expected;
76-
$content = File::get(storage_path("logs/{$path}"));
77-
78-
foreach ($expected as $item) {
79-
$pattern = $this->normalizeExpectedFileContent($item);
80-
$this->assertNotRegExp($pattern, $content, "Failed asserting that file not contains `{$item}`.");
81-
}
82-
}
83-
84-
private function normalizeExpectedFileContent($content)
85-
{
86-
$content = '/' . preg_quote($content) . (starts_with($content, 'array:') ? '' : '\n') . '/';
87-
$content = str_replace('%datetime%', '\d{4}-\d{2}-\d{2} \d{2}\:\d{2}\:\d{2}', $content);
88-
89-
return $content;
90-
}
91-
9239
protected function tearDown()
9340
{
9441
$this->cleanLogsDirectory();

0 commit comments

Comments
 (0)