]> git.mxchange.org Git - friendica.git/blob - tests/src/Util/Logger/ProfilerLoggerTest.php
Merge pull request #7752 from kPherox/develop
[friendica.git] / tests / src / Util / Logger / ProfilerLoggerTest.php
1 <?php
2
3 namespace Friendica\Test\src\Util\Logger;
4
5 use Friendica\Test\MockedTest;
6 use Friendica\Util\Logger\ProfilerLogger;
7 use Friendica\Util\Profiler;
8 use Mockery\MockInterface;
9 use Psr\Log\LoggerInterface;
10 use Psr\Log\LogLevel;
11
12 class ProfilerLoggerTest extends MockedTest
13 {
14         use LoggerDataTrait;
15
16         /**
17          * @var LoggerInterface|MockInterface
18          */
19         private $logger;
20         /**
21          * @var Profiler|MockInterface
22          */
23         private $profiler;
24
25         protected function setUp()
26         {
27                 parent::setUp();
28
29                 $this->logger = \Mockery::mock(LoggerInterface::class);
30                 $this->profiler = \Mockery::mock(Profiler::class);
31         }
32
33         /**
34          * Test if the profiler is profiling data
35          * @dataProvider dataTests
36          */
37         public function testProfiling($function, $message, array $context)
38         {
39                 $logger = new ProfilerLogger($this->logger, $this->profiler);
40
41                 $this->logger->shouldReceive($function)->with($message, $context)->once();
42                 $this->profiler->shouldReceive('saveTimestamp')->with(\Mockery::any(), 'file', \Mockery::any())->once();
43                 $logger->$function($message, $context);
44         }
45
46         /**
47          * Test the log() function
48          */
49         public function testProfilingLog()
50         {
51                 $logger = new ProfilerLogger($this->logger, $this->profiler);
52
53                 $this->logger->shouldReceive('log')->with(LogLevel::WARNING, 'test', ['a' => 'context'])->once();
54                 $this->profiler->shouldReceive('saveTimestamp')->with(\Mockery::any(), 'file', \Mockery::any())->once();
55
56                 $logger->log(LogLevel::WARNING, 'test', ['a' => 'context']);
57         }
58 }