1
0

EventLoggerTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2017 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace Test\Diagnostics;
  8. use OC\Diagnostics\EventLogger;
  9. use OC\Log;
  10. use OC\SystemConfig;
  11. use Psr\Log\LoggerInterface;
  12. use Test\TestCase;
  13. class EventLoggerTest extends TestCase {
  14. /** @var \OC\Diagnostics\EventLogger */
  15. private $logger;
  16. protected function setUp(): void {
  17. parent::setUp();
  18. $this->logger = new EventLogger(
  19. $this->createMock(SystemConfig::class),
  20. $this->createMock(LoggerInterface::class),
  21. $this->createMock(Log::class)
  22. );
  23. }
  24. public function testQueryLogger(): void {
  25. // Module is not activated and this should not be logged
  26. $this->logger->start('test1', 'testevent1');
  27. $this->logger->end('test1');
  28. $this->logger->log('test2', 'testevent2', microtime(true), microtime(true));
  29. $events = $this->logger->getEvents();
  30. $this->assertSame(0, sizeof($events));
  31. // Activate module and log some query
  32. $this->logger->activate();
  33. // start one event
  34. $this->logger->start('test3', 'testevent3');
  35. // force log of another event
  36. $this->logger->log('test4', 'testevent4', microtime(true), microtime(true));
  37. // log started event
  38. $this->logger->end('test3');
  39. $events = $this->logger->getEvents();
  40. $this->assertSame('test4', $events['test4']->getId());
  41. $this->assertSame('testevent4', $events['test4']->getDescription());
  42. $this->assertSame('test3', $events['test3']->getId());
  43. $this->assertSame('testevent3', $events['test3']->getDescription());
  44. $this->assertSame(2, sizeof($events));
  45. }
  46. }