MailLogTransportTest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace Illuminate\Tests\Mail;
  3. use Illuminate\Mail\Transport\LogTransport;
  4. use Monolog\Handler\StreamHandler;
  5. use Monolog\Logger;
  6. use Orchestra\Testbench\TestCase;
  7. use Psr\Log\LoggerInterface;
  8. use Psr\Log\NullLogger;
  9. class MailLogTransportTest extends TestCase
  10. {
  11. public function testGetLogTransportWithConfiguredChannel()
  12. {
  13. $this->app['config']->set('mail.driver', 'log');
  14. $this->app['config']->set('mail.log_channel', 'mail');
  15. $this->app['config']->set('logging.channels.mail', [
  16. 'driver' => 'single',
  17. 'path' => 'mail.log',
  18. ]);
  19. $transport = app('mailer')->getSwiftMailer()->getTransport();
  20. $this->assertInstanceOf(LogTransport::class, $transport);
  21. $logger = $transport->logger();
  22. $this->assertInstanceOf(LoggerInterface::class, $logger);
  23. $this->assertInstanceOf(Logger::class, $monolog = $logger->getLogger());
  24. $this->assertCount(1, $handlers = $monolog->getHandlers());
  25. $this->assertInstanceOf(StreamHandler::class, $handler = $handlers[0]);
  26. }
  27. public function testGetLogTransportWithPsrLogger()
  28. {
  29. $this->app['config']->set('mail.driver', 'log');
  30. $logger = $this->app->instance('log', new NullLogger);
  31. $transportLogger = app('mailer')->getSwiftMailer()->getTransport()->logger();
  32. $this->assertEquals($logger, $transportLogger);
  33. }
  34. }