startsessionlistener.php 760 B

123456789101112131415161718192021222324252627
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2015 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. use OC\Session\Memory;
  8. use PHPUnit\Framework\Test;
  9. use PHPUnit\Framework\TestListener;
  10. use PHPUnit\Framework\TestListenerDefaultImplementation;
  11. /**
  12. * Starts a new session before each test execution
  13. */
  14. class StartSessionListener implements TestListener {
  15. use TestListenerDefaultImplementation;
  16. public function endTest(Test $test, float $time): void {
  17. // reopen the session - only allowed for memory session
  18. if (\OC::$server->getSession() instanceof Memory) {
  19. /** @var Memory $session */
  20. $session = \OC::$server->getSession();
  21. $session->reopen();
  22. }
  23. }
  24. }