wiki.techinc.nl/tests/phpunit/unit/includes/Rest/SessionHelperTestTrait.php
Daimona Eaytoy 948910d692 tests: Remove unused argument to createMock
Follow-up: I9dec6d4accd5de2bd1bde352d45f82c433913d54
Change-Id: Ia84984b7dc64b407337224b85733063b645539b0
2023-05-23 20:58:37 +02:00

36 lines
1.1 KiB
PHP

<?php
namespace MediaWiki\Tests\Rest\Handler;
use MediaWiki\Session\Session;
use MediaWiki\Session\SessionId;
use MediaWiki\Session\SessionProviderInterface;
use PHPUnit\Framework\MockObject\MockObject;
/**
* A trait for testing Handler classes.
* This trait is intended to be used on subclasses of MediaWikiUnitTestCase
* or MediaWikiIntegrationTestCase.
*
* @stable to use
* @package MediaWiki\Tests\Rest
*/
trait SessionHelperTestTrait {
/**
* @param bool $csrfSafe
* @return Session&MockObject
*/
public function getSession( bool $csrfSafe ) {
/** @var SessionProviderInterface&MockObject $session */
$sessionProvider = $this->createMock( SessionProviderInterface::class );
$sessionProvider->method( 'safeAgainstCsrf' )->willReturn( $csrfSafe );
/** @var Session&MockObject $session */
$session = $this->createMock( Session::class );
$session->method( 'getSessionId' )->willReturn( new SessionId( 'test' ) );
$session->method( 'getProvider' )->willReturn( $sessionProvider );
$session->method( 'isPersistent' )->willReturn( true );
return $session;
}
}