aboutsummaryrefslogtreecommitdiffstats
path: root/tests/startsessionlistener.php
blob: c1cec5f6492895044e0fd30fe52396a558d9b959 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php

/**
 * SPDX-FileCopyrightText: 2018-2024 Nextcloud GmbH and Nextcloud contributors
 * SPDX-FileCopyrightText: 2015 ownCloud, Inc.
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */
use OC\Session\Memory;
use OCP\ISession;
use OCP\Server;
use PHPUnit\Framework\Test;
use PHPUnit\Framework\TestListener;
use PHPUnit\Framework\TestListenerDefaultImplementation;

/**
 * Starts a new session before each test execution
 */
class StartSessionListener implements TestListener {
	use TestListenerDefaultImplementation;

	public function endTest(Test $test, float $time): void {
		// reopen the session - only allowed for memory session
		if (Server::get(ISession::class) instanceof Memory) {
			/** @var Memory $session */
			$session = Server::get(ISession::class);
			$session->reopen();
		}
	}
}