Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConsoleLoggerTest.php
Go to the documentation of this file.
1 <?php
8 
10 
11 class ConsoleLoggerTest extends \PHPUnit\Framework\TestCase
12 {
16  private $console;
17 
21  private $consoleLoggerModel;
22 
23  protected function setUp()
24  {
25  $this->console = $this->createMock(\Symfony\Component\Console\Output\OutputInterface::class);
26  $outputFormatter = $this->createMock(\Symfony\Component\Console\Formatter\OutputFormatterInterface::class);
27  $this->console
28  ->expects($this->once())
29  ->method('getFormatter')
30  ->willReturn($outputFormatter);
31  $this->consoleLoggerModel = new ConsoleLogger($this->console);
32  }
33 
34  public function testLogSuccess()
35  {
36  $this->console
37  ->expects($this->once())
38  ->method('writeln')
39  ->with('<info>[SUCCESS]: Success message.</info>');
40  $this->consoleLoggerModel->logSuccess('Success message.');
41  }
42 
43  public function testLogError()
44  {
45  $exception = $this->createMock(\Exception::class);
46  $this->console
47  ->expects($this->once())
48  ->method('writeln')
49  ->with('<error>[ERROR]: </error>');
50  $this->consoleLoggerModel->logError($exception);
51  }
52 
53  public function testLog()
54  {
55  $this->console
56  ->expects($this->once())
57  ->method('writeln')
58  ->with('<detail>Detail message.</detail>');
59  $this->consoleLoggerModel->log('Detail message.');
60  }
61 
62  public function testLogInline()
63  {
64  $this->console
65  ->expects($this->once())
66  ->method('write')
67  ->with('<detail>Detail message.</detail>');
68  $this->consoleLoggerModel->logInline('Detail message.');
69  }
70 
71  public function testLogMeta()
72  {
73  $this->console
74  ->expects($this->once())
75  ->method('writeln')
76  ->with('<metadata>Meta message.</metadata>');
77  $this->consoleLoggerModel->logMeta('Meta message.');
78  }
79 }