]> git.mxchange.org Git - friendica.git/blob - tests/src/Util/Logger/ProfilerLoggerTest.php
Merge pull request #10693 from nupplaphil/feat/config_dir
[friendica.git] / tests / src / Util / Logger / ProfilerLoggerTest.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, the Friendica project
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(): void
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          * @doesNotPerformAssertions
56          */
57         public function testProfiling($function, $message, array $context)
58         {
59                 $logger = new ProfilerLogger($this->logger, $this->profiler);
60
61                 $this->logger->shouldReceive($function)->with($message, $context)->once();
62                 $this->profiler->shouldReceive('startRecording')->with('file')->once();
63                 $this->profiler->shouldReceive('stopRecording');
64                 $this->profiler->shouldReceive('saveTimestamp');
65                 $logger->$function($message, $context);
66         }
67
68         /**
69          * Test the log() function
70          * @doesNotPerformAssertions
71          */
72         public function testProfilingLog()
73         {
74                 $logger = new ProfilerLogger($this->logger, $this->profiler);
75
76                 $this->logger->shouldReceive('log')->with(LogLevel::WARNING, 'test', ['a' => 'context'])->once();
77                 $this->profiler->shouldReceive('startRecording')->with('file')->once();
78                 $this->profiler->shouldReceive('stopRecording');
79                 $this->profiler->shouldReceive('saveTimestamp');
80
81                 $logger->log(LogLevel::WARNING, 'test', ['a' => 'context']);
82         }
83 }