EventLoggerTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * @author Piotr Mrowczynski <piotr@owncloud.com>
  4. *
  5. * @copyright Copyright (c) 2017, ownCloud GmbH
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. namespace Test\Diagnostics;
  22. use Psr\Log\LoggerInterface;
  23. use OC\Diagnostics\EventLogger;
  24. use OC\Log;
  25. use OC\SystemConfig;
  26. use Test\TestCase;
  27. class EventLoggerTest extends TestCase {
  28. /** @var \OC\Diagnostics\EventLogger */
  29. private $logger;
  30. protected function setUp(): void {
  31. parent::setUp();
  32. $this->logger = new EventLogger(
  33. $this->createMock(SystemConfig::class),
  34. $this->createMock(LoggerInterface::class),
  35. $this->createMock(Log::class)
  36. );
  37. }
  38. public function testQueryLogger() {
  39. // Module is not activated and this should not be logged
  40. $this->logger->start("test1", "testevent1");
  41. $this->logger->end("test1");
  42. $this->logger->log("test2", "testevent2", microtime(true), microtime(true));
  43. $events = $this->logger->getEvents();
  44. $this->assertSame(0, sizeof($events));
  45. // Activate module and log some query
  46. $this->logger->activate();
  47. // start one event
  48. $this->logger->start("test3", "testevent3");
  49. // force log of another event
  50. $this->logger->log("test4", "testevent4", microtime(true), microtime(true));
  51. // log started event
  52. $this->logger->end("test3");
  53. $events = $this->logger->getEvents();
  54. $this->assertSame("test4", $events['test4']->getId());
  55. $this->assertSame("testevent4", $events['test4']->getDescription());
  56. $this->assertSame("test3", $events['test3']->getId());
  57. $this->assertSame("testevent3", $events['test3']->getDescription());
  58. $this->assertSame(2, sizeof($events));
  59. }
  60. }