<?php
+/**
+ * @copyright Copyright (C) 2010-2023, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
namespace Friendica\Test\src\Util;
+use Friendica\Core\Config\ValueObject\Cache;
+use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Test\MockedTest;
use Friendica\Util\Profiler;
use Mockery\MockInterface;
*/
private $logger;
- protected function setUp()
+ protected function setUp(): void
{
parent::setUp();
*/
public function testSetUp()
{
- $profiler = new Profiler(true, true);
+ $configCache = \Mockery::mock(Cache::class);
+ $configCache->shouldReceive('get')
+ ->withAnyArgs()
+ ->andReturn(true)
+ ->twice();
+ $profiler = new Profiler($configCache);
+
+ self::assertInstanceOf(Profiler::class, $profiler);
}
/**
'name' => 'rendering',
'functions' => ['test', 'it7'],
],
- 'parser' => [
+ 'session' => [
'timestamp' => time(),
- 'name' => 'parser',
+ 'name' => 'session',
'functions' => ['test', 'it8'],
],
'marktime' => [
'timestamp' => time(),
- 'name' => 'parser',
+ 'name' => 'session',
'functions' => ['test'],
],
// This one isn't set during reset
*/
public function testSaveTimestamp($timestamp, $name, array $functions)
{
- $profiler = new Profiler(true, true);
+ $configCache = \Mockery::mock(Cache::class);
+ $configCache->shouldReceive('get')
+ ->withAnyArgs()
+ ->andReturn(true)
+ ->twice();
+
+ $profiler = new Profiler($configCache);
foreach ($functions as $function) {
$profiler->saveTimestamp($timestamp, $name, $function);
}
- $this->assertGreaterThanOrEqual(0, $profiler->get($name));
+ self::assertGreaterThanOrEqual(0, $profiler->get($name));
}
/**
* Test the Profiler reset
* @dataProvider dataPerformance
*/
- public function testReset($timestamp, $name, array $functions)
+ public function testReset($timestamp, $name)
{
- $profiler = new Profiler(true, true);
+ $configCache = \Mockery::mock(Cache::class);
+ $configCache->shouldReceive('get')
+ ->withAnyArgs()
+ ->andReturn(true)
+ ->twice();
+
+ $profiler = new Profiler($configCache);
$profiler->saveTimestamp($timestamp, $name);
$profiler->reset();
- $this->assertEquals(0, $profiler->get($name));
+ self::assertEquals(0, $profiler->get($name));
}
public function dataBig()
->shouldReceive('info')
->once();
- $profiler = new Profiler(true, true);
+ $configCache = \Mockery::mock(Cache::class);
+ $configCache->shouldReceive('get')
+ ->withAnyArgs()
+ ->andReturn(true)
+ ->twice();
+
+ $profiler = new Profiler($configCache);
foreach ($data as $perf => $items) {
foreach ($items['functions'] as $function) {
foreach ($data as $perf => $items) {
foreach ($items['functions'] as $function) {
// assert that the output contains the functions
- $this->assertRegExp('/' . $function . ': \d+/', $output);
+ self::assertMatchesRegularExpression('/' . $function . ': \d+/', $output);
}
}
}
*/
public function testEnableDisable()
{
- $profiler = new Profiler(true, false);
+ $configCache = \Mockery::mock(Cache::class);
+ $configCache->shouldReceive('get')
+ ->with('system', 'profiler')
+ ->andReturn(true)
+ ->once();
+ $configCache->shouldReceive('get')
+ ->with('rendertime', 'callstack')
+ ->andReturn(false)
+ ->once();
- $this->assertFalse($profiler->isRendertime());
- $this->assertEmpty($profiler->getRendertimeString());
+ $profiler = new Profiler($configCache);
+
+ self::assertFalse($profiler->isRendertime());
+ self::assertEmpty($profiler->getRendertimeString());
$profiler->saveTimestamp(time(), 'network', 'test1');
- $profiler->update(false, false);
+ $config = \Mockery::mock(IManageConfigValues::class);
+ $config->shouldReceive('get')
+ ->with('system', 'profiler')
+ ->andReturn(false)
+ ->once();
+ $config->shouldReceive('get')
+ ->with('rendertime', 'callstack')
+ ->andReturn(false)
+ ->once();
+
+ $profiler->update($config);
+
+ self::assertFalse($profiler->isRendertime());
+ self::assertEmpty($profiler->getRendertimeString());
- $this->assertFalse($profiler->isRendertime());
- $this->assertEmpty($profiler->getRendertimeString());
+ $config->shouldReceive('get')
+ ->with('system', 'profiler')
+ ->andReturn(true)
+ ->once();
+ $config->shouldReceive('get')
+ ->with('rendertime', 'callstack')
+ ->andReturn(true)
+ ->once();
- $profiler->update(true, true);
+ $profiler->update($config);
$profiler->saveTimestamp(time(), 'database', 'test2');
- $this->assertTrue($profiler->isRendertime());
+ self::assertTrue($profiler->isRendertime());
$output = $profiler->getRendertimeString();
- $this->assertRegExp('/test1: \d+/', $output);
- $this->assertRegExp('/test2: \d+/', $output);
+ self::assertMatchesRegularExpression('/test1: \d+/', $output);
+ self::assertMatchesRegularExpression('/test2: \d+/', $output);
}
}