Skip to content

Commit

Permalink
Merge pull request #33668 from nextcloud/tests/fix-session-middleware
Browse files Browse the repository at this point in the history
Fix SessionMiddlewareTest and cover new case with reopening
  • Loading branch information
CarlSchwan authored Aug 25, 2022
2 parents 711a9fd + 64a7489 commit 9b5569f
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions tests/lib/AppFramework/Middleware/SessionMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected function setUp(): void {
* @UseSession
*/
public function testSessionNotClosedOnBeforeController() {
$session = $this->getSessionMock(0);
$session = $this->getSessionMock(0, 1);

$this->reflector->reflect($this, __FUNCTION__);
$middleware = new SessionMiddleware($this->reflector, $session);
Expand All @@ -53,8 +53,20 @@ public function testSessionClosedOnAfterController() {
$middleware->afterController($this->controller, __FUNCTION__, new Response());
}

/**
* @UseSession
*/
public function testSessionReopenedAndClosedOnBeforeController() {
$session = $this->getSessionMock(1, 1);

$this->reflector->reflect($this, __FUNCTION__);
$middleware = new SessionMiddleware($this->reflector, $session);
$middleware->beforeController($this->controller, __FUNCTION__);
$middleware->afterController($this->controller, __FUNCTION__, new Response());
}

public function testSessionClosedOnBeforeController() {
$session = $this->getSessionMock(1);
$session = $this->getSessionMock(0);

$this->reflector->reflect($this, __FUNCTION__);
$middleware = new SessionMiddleware($this->reflector, $session);
Expand All @@ -72,13 +84,15 @@ public function testSessionNotClosedOnAfterController() {
/**
* @return mixed
*/
private function getSessionMock($expectedCloseCount) {
private function getSessionMock(int $expectedCloseCount, int $expectedReopenCount = 0) {
$session = $this->getMockBuilder('\OC\Session\Memory')
->disableOriginalConstructor()
->getMock();

$session->expects($this->exactly($expectedCloseCount))
->method('close');
$session->expects($this->exactly($expectedReopenCount))
->method('reopen');
return $session;
}
}

0 comments on commit 9b5569f

Please sign in to comment.