EventLoggerTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 OC\Diagnostics\EventLogger;
  23. use Test\TestCase;
  24. class EventLoggerTest extends TestCase {
  25. /** @var \OC\Diagnostics\EventLogger */
  26. private $logger;
  27. public function setUp() {
  28. parent::setUp();
  29. $this->logger = new EventLogger();
  30. }
  31. public function testQueryLogger() {
  32. // Module is not activated and this should not be logged
  33. $this->logger->start("test1", "testevent1");
  34. $this->logger->end("test1");
  35. $this->logger->log("test2", "testevent2", microtime(true), microtime(true));
  36. $events = $this->logger->getEvents();
  37. $this->assertSame(0, sizeof($events));
  38. // Activate module and log some query
  39. $this->logger->activate();
  40. // start one event
  41. $this->logger->start("test3", "testevent3");
  42. // force log of another event
  43. $this->logger->log("test4", "testevent4", microtime(true), microtime(true));
  44. // log started event
  45. $this->logger->end("test3");
  46. $events = $this->logger->getEvents();
  47. $this->assertSame("test4", $events['test4']->getId());
  48. $this->assertSame("testevent4", $events['test4']->getDescription());
  49. $this->assertSame("test3", $events['test3']->getId());
  50. $this->assertSame("testevent3", $events['test3']->getDescription());
  51. $this->assertSame(2, sizeof($events));
  52. }
  53. }