QueryLoggerTest.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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\QueryLogger;
  9. use Test\TestCase;
  10. class QueryLoggerTest extends TestCase {
  11. /** @var \OC\Diagnostics\QueryLogger */
  12. private $logger;
  13. protected function setUp(): void {
  14. parent::setUp();
  15. $this->logger = new QueryLogger();
  16. }
  17. public function testQueryLogger(): void {
  18. // Module is not activated and this should not be logged
  19. $this->logger->startQuery('SELECT', ['testuser', 'count'], ['string', 'int']);
  20. $this->logger->stopQuery();
  21. $queries = $this->logger->getQueries();
  22. $this->assertSame(0, sizeof($queries));
  23. // Activate module and log some query
  24. $this->logger->activate();
  25. $this->logger->startQuery('SELECT', ['testuser', 'count'], ['string', 'int']);
  26. $this->logger->stopQuery();
  27. $queries = $this->logger->getQueries();
  28. $this->assertSame(1, sizeof($queries));
  29. }
  30. }