Adapt tests for PhpUnit 7.5
[friendica.git/.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()
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('saveTimestamp')->with(\Mockery::any(), 'file')->once();
63                 $logger->$function($message, $context);
64         }
65
66         /**
67          * Test the log() function
68          * @doesNotPerformAssertions
69          */
70         public function testProfilingLog()
71         {
72                 $logger = new ProfilerLogger($this->logger, $this->profiler);
73
74                 $this->logger->shouldReceive('log')->with(LogLevel::WARNING, 'test', ['a' => 'context'])->once();
75                 $this->profiler->shouldReceive('saveTimestamp')->with(\Mockery::any(), 'file')->once();
76
77                 $logger->log(LogLevel::WARNING, 'test', ['a' => 'context']);
78         }
79 }