]> git.mxchange.org Git - friendica.git/blob - tests/src/Util/Logger/ProfilerLoggerTest.php
Merge pull request #10104 from nupplaphil/fix/jit_caching
[friendica.git] / tests / src / Util / Logger / ProfilerLoggerTest.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Test\src\Util\Logger;
23
24 use Friendica\Test\MockedTest;
25 use Friendica\Util\Logger\ProfilerLogger;
26 use Friendica\Util\Profiler;
27 use Mockery\MockInterface;
28 use Psr\Log\LoggerInterface;
29 use Psr\Log\LogLevel;
30
31 class ProfilerLoggerTest extends MockedTest
32 {
33         use LoggerDataTrait;
34
35         /**
36          * @var LoggerInterface|MockInterface
37          */
38         private $logger;
39         /**
40          * @var Profiler|MockInterface
41          */
42         private $profiler;
43
44         protected function setUp()
45         {
46                 parent::setUp();
47
48                 $this->logger = \Mockery::mock(LoggerInterface::class);
49                 $this->profiler = \Mockery::mock(Profiler::class);
50         }
51
52         /**
53          * Test if the profiler is profiling data
54          * @dataProvider dataTests
55          */
56         public function testProfiling($function, $message, array $context)
57         {
58                 $logger = new ProfilerLogger($this->logger, $this->profiler);
59
60                 $this->logger->shouldReceive($function)->with($message, $context)->once();
61                 $this->profiler->shouldReceive('saveTimestamp')->with(\Mockery::any(), 'file')->once();
62                 $logger->$function($message, $context);
63         }
64
65         /**
66          * Test the log() function
67          */
68         public function testProfilingLog()
69         {
70                 $logger = new ProfilerLogger($this->logger, $this->profiler);
71
72                 $this->logger->shouldReceive('log')->with(LogLevel::WARNING, 'test', ['a' => 'context'])->once();
73                 $this->profiler->shouldReceive('saveTimestamp')->with(\Mockery::any(), 'file')->once();
74
75                 $logger->log(LogLevel::WARNING, 'test', ['a' => 'context']);
76         }
77 }