X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=tests%2Fsrc%2FUtil%2FProfilerTest.php;h=25d044354c6534a59367a7ae8a50f55432066cc3;hb=2292263780000a50e1e7583bc170cca619d86f42;hp=87796a2f37c4bbea517b3ae64e77796b015ee353;hpb=4375edd63e44b71913bd45bf25a4a554582b581e;p=friendica.git diff --git a/tests/src/Util/ProfilerTest.php b/tests/src/Util/ProfilerTest.php index 87796a2f37..25d044354c 100644 --- a/tests/src/Util/ProfilerTest.php +++ b/tests/src/Util/ProfilerTest.php @@ -1,7 +1,28 @@ . + * + */ -namespace src\Util; +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; @@ -14,11 +35,11 @@ class ProfilerTest extends MockedTest */ private $logger; - protected function setUp() + protected function setUp(): void { parent::setUp(); - $this->logger = \Mockery::mock('Psr\Log\LoggerInterface'); + $this->logger = \Mockery::mock(LoggerInterface::class); } /** @@ -26,7 +47,14 @@ class ProfilerTest extends MockedTest */ 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); } /** @@ -71,14 +99,14 @@ class ProfilerTest extends MockedTest '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 @@ -96,27 +124,39 @@ class ProfilerTest extends MockedTest */ 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() @@ -168,7 +208,13 @@ class ProfilerTest extends MockedTest ->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) { @@ -183,19 +229,64 @@ class ProfilerTest extends MockedTest 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); } } } /** - * Test if no rendertime is set + * Test different enable and disable states of the profiler */ - public function testNoRenderTime() + 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(); + + $profiler = new Profiler($configCache); + + self::assertFalse($profiler->isRendertime()); + self::assertEmpty($profiler->getRendertimeString()); + + $profiler->saveTimestamp(time(), 'network', 'test1'); - $this->assertFalse($profiler->isRendertime()); - $this->assertEmpty($profiler->getRendertimeString()); + $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); } }