<?php
/**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
namespace Friendica\Test\src\Util;
-use Friendica\Core\Config\Cache;
-use Friendica\Core\Config\IConfig;
+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()
{
- $configCache = \Mockery::mock(Cache::class);
- $configCache->shouldReceive('get')
+ $config = \Mockery::mock(IManageConfigValues::class);
+ $config->shouldReceive('get')
->withAnyArgs()
->andReturn(true)
->twice();
- $profiler = new Profiler($configCache);
+ $profiler = new Profiler($config);
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)
{
- $configCache = \Mockery::mock(Cache::class);
- $configCache->shouldReceive('get')
+ $config = \Mockery::mock(IManageConfigValues::class);
+ $config->shouldReceive('get')
->withAnyArgs()
->andReturn(true)
->twice();
- $profiler = new Profiler($configCache);
+ $profiler = new Profiler($config);
foreach ($functions as $function) {
$profiler->saveTimestamp($timestamp, $name, $function);
*/
public function testReset($timestamp, $name)
{
- $configCache = \Mockery::mock(Cache::class);
- $configCache->shouldReceive('get')
+ $config = \Mockery::mock(IManageConfigValues::class);
+ $config->shouldReceive('get')
->withAnyArgs()
->andReturn(true)
->twice();
- $profiler = new Profiler($configCache);
+ $profiler = new Profiler($config);
$profiler->saveTimestamp($timestamp, $name);
$profiler->reset();
->shouldReceive('info')
->once();
- $configCache = \Mockery::mock(Cache::class);
- $configCache->shouldReceive('get')
+ $config = \Mockery::mock(IManageConfigValues::class);
+ $config->shouldReceive('get')
->withAnyArgs()
->andReturn(true)
->twice();
- $profiler = new Profiler($configCache);
+ $profiler = new Profiler($config);
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
- self::assertRegExp('/' . $function . ': \d+/', $output);
+ self::assertMatchesRegularExpression('/' . $function . ': \d+/', $output);
}
}
}
-
- /**
- * Test different enable and disable states of the profiler
- */
- public function testEnableDisable()
- {
- $configCache = \Mockery::mock(Cache::class);
- $configCache->shouldReceive('get')
- ->with('system', 'profiler')
- ->andReturn(true)
- ->once();
- $configCache->shouldReceive('get')
- ->with('rendertime', 'callstack')
- ->andReturn(false)
- ->once();
-
- $profiler = new Profiler($configCache);
-
- self::assertFalse($profiler->isRendertime());
- self::assertEmpty($profiler->getRendertimeString());
-
- $profiler->saveTimestamp(time(), 'network', 'test1');
-
- $config = \Mockery::mock(IConfig::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());
-
- $config->shouldReceive('get')
- ->with('system', 'profiler')
- ->andReturn(true)
- ->once();
- $config->shouldReceive('get')
- ->with('rendertime', 'callstack')
- ->andReturn(true)
- ->once();
-
- $profiler->update($config);
-
- $profiler->saveTimestamp(time(), 'database', 'test2');
-
- self::assertTrue($profiler->isRendertime());
- $output = $profiler->getRendertimeString();
- self::assertRegExp('/test1: \d+/', $output);
- self::assertRegExp('/test2: \d+/', $output);
- }
}