mirror of
https://github.com/friendica/friendica
synced 2025-04-27 01:10:14 +00:00
Replace Config-Cache dependency with Config-Model (no more DB-waiting necessary)
This commit is contained in:
parent
a6fb683bcd
commit
ab6efea9b2
18 changed files with 210 additions and 325 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue