Replace Config-Cache dependency with Config-Model (no more DB-waiting necessary)

This commit is contained in:
Philipp 2023-01-15 16:12:25 +01:00
parent a6fb683bcd
commit ab6efea9b2
No known key found for this signature in database
GPG key ID: 24A7501396EB5432
18 changed files with 210 additions and 325 deletions

View file

@ -21,7 +21,6 @@
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;
@ -47,12 +46,12 @@ class ProfilerTest extends MockedTest
*/
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);
}
@ -124,13 +123,13 @@ class ProfilerTest extends MockedTest
*/
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);
@ -145,13 +144,13 @@ class ProfilerTest extends MockedTest
*/
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();
@ -208,13 +207,13 @@ class ProfilerTest extends MockedTest
->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) {
@ -233,60 +232,4 @@ class ProfilerTest extends MockedTest
}
}
}
/**
* 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(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());
$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::assertMatchesRegularExpression('/test1: \d+/', $output);
self::assertMatchesRegularExpression('/test2: \d+/', $output);
}
}