3 * @copyright Copyright (C) 2010-2021, the Friendica project
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
22 namespace Friendica\Test\src\Core\Logger;
24 use Friendica\Test\MockedTest;
25 use Friendica\Core\Logger\Type\ProfilerLogger;
26 use Friendica\Util\Profiler;
27 use Mockery\MockInterface;
28 use Psr\Log\LoggerInterface;
31 class ProfilerLoggerTest extends MockedTest
36 * @var LoggerInterface|MockInterface
40 * @var Profiler|MockInterface
44 protected function setUp(): void
48 $this->logger = \Mockery::mock(LoggerInterface::class);
49 $this->profiler = \Mockery::mock(Profiler::class);
53 * Test if the profiler is profiling data
54 * @dataProvider dataTests
55 * @doesNotPerformAssertions
57 public function testProfiling($function, $message, array $context)
59 $logger = new ProfilerLogger($this->logger, $this->profiler);
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);
69 * Test the log() function
70 * @doesNotPerformAssertions
72 public function testProfilingLog()
74 $logger = new ProfilerLogger($this->logger, $this->profiler);
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');
81 $logger->log(LogLevel::WARNING, 'test', ['a' => 'context']);