Skip to content

Commit bc8629c

Browse files
NinerianopencodeGitHub Copilot
committed
test: restore and fix skipped destroy session tests
Restored testDestroyOtherSession and testDestroyOwnSession which had been emptied with markTestSkipped due to PHPUnit 10 incompatibilities. - Replace removed setMethodsExcept()->getMock() with getMock() (PHPUnit 10) - Add gc() stub required by SessionHandlerInterface - Set mock expectations before destroySession() call for correct isolation Co-authored-by: opencode <opencode@noreply.opencode.ai> Co-authored-by: GitHub Copilot <copilot@noreply.github.com>
1 parent 87504bb commit bc8629c

1 file changed

Lines changed: 69 additions & 2 deletions

File tree

test/PluginSessionTest.php

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,13 +469,80 @@ public function testSessionIdCheck()
469469
$this->assertEquals($sessionId, session_id());
470470
}
471471

472+
/**
473+
*
474+
* Test that destroying another session works correctly.
475+
*
476+
* @covers \Staffbase\plugins\sdk\PluginSession::__construct
477+
* @covers \Staffbase\plugins\sdk\SessionHandling\SessionHandlerTrait::destroySession
478+
*/
472479
public function testDestroyOtherSession()
473480
{
474-
$this->markTestSkipped('must be revisited.');
481+
$sessionHash = 'HOjLTR6+D5YIY0/waqJQp3Bg=';
482+
$sessionId = 'HOjLTR6-D5YIY0-waqJQp3Bg-';
483+
484+
$tokenData = $this->tokenData;
485+
$tokenData[SSODataClaimsInterface::CLAIM_SESSION_ID] = $sessionHash;
486+
$token = SSOTokenGenerator::createSignedTokenFromData($this->privateKey, $tokenData);
487+
488+
// First: create the "other" session (no handler, uses real session)
489+
$this->setupEnvironment(null, $token);
490+
new PluginSession($this->pluginId, $this->publicKey);
491+
492+
// Second: create a session with the default token using a session handler mock
493+
$this->setupEnvironment(null, $this->token, false);
494+
495+
/** @var \SessionHandlerInterface&\PHPUnit\Framework\MockObject\MockObject $handler */
496+
$handler = $this->getMockBuilder(\SessionHandlerInterface::class)
497+
->getMock();
498+
499+
$handler->method('close')->willReturn(true);
500+
$handler->method('open')->willReturn(true);
501+
$handler->method('write')->willReturn(true);
502+
$handler->method('gc')->willReturn(1);
503+
$handler->method('read')->willReturn('');
504+
$handler->method('destroy')->willReturn(true);
505+
506+
$session = new PluginSession($this->pluginId, $this->publicKey, $handler);
507+
508+
// After construction, set the expectation: destroy must be called with the compatible session id
509+
$handler->expects($this->once())
510+
->method('destroy')
511+
->with($sessionId);
512+
513+
$session->destroySession($sessionHash);
475514
}
476515

516+
/**
517+
*
518+
* Test that destroying the own session works correctly.
519+
*
520+
* @covers \Staffbase\plugins\sdk\PluginSession::__construct
521+
* @covers \Staffbase\plugins\sdk\SessionHandling\SessionHandlerTrait::destroySession
522+
*/
477523
public function testDestroyOwnSession()
478524
{
479-
$this->markTestSkipped('must be revisited.');
525+
$sessionId = $this->tokenData[SSODataClaimsInterface::CLAIM_SESSION_ID];
526+
$this->setupEnvironment(null, $this->token, false);
527+
528+
/** @var \SessionHandlerInterface&\PHPUnit\Framework\MockObject\MockObject $handler */
529+
$handler = $this->getMockBuilder(\SessionHandlerInterface::class)
530+
->getMock();
531+
532+
$handler->method('close')->willReturn(true);
533+
$handler->method('open')->willReturn(true);
534+
$handler->method('write')->willReturn(true);
535+
$handler->method('gc')->willReturn(1);
536+
$handler->method('read')->willReturn('');
537+
$handler->method('destroy')->willReturn(true);
538+
539+
$session = new PluginSession($this->pluginId, $this->publicKey, $handler);
540+
541+
// After construction, set the expectation: destroy must be called with the session id
542+
$handler->expects($this->once())
543+
->method('destroy')
544+
->with($sessionId);
545+
546+
$session->destroySession($sessionId);
480547
}
481548
}

0 commit comments

Comments
 (0)