phpmyadmin/tests/unit/Controllers/LogoutControllerTest.php
Maurício Meneghini Fauth d2060c56d5
Change InvocableController to always return a Response
When 'null' is returned, ResponseRenderer::response() is called, so
call it early to always return a Response object.

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
2024-05-22 15:22:56 -03:00

43 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
namespace PhpMyAdmin\Tests\Controllers;
use PhpMyAdmin\Controllers\LogoutController;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Plugins\AuthenticationPlugin;
use PhpMyAdmin\Plugins\AuthenticationPluginFactory;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Tests\AbstractTestCase;
use PhpMyAdmin\Tests\Stubs\ResponseRenderer as ResponseRendererStub;
use PHPUnit\Framework\Attributes\CoversClass;
use ReflectionProperty;
#[CoversClass(LogoutController::class)]
class LogoutControllerTest extends AbstractTestCase
{
public function testValidLogout(): void
{
$responseStub = new ResponseRendererStub();
(new ReflectionProperty(ResponseRenderer::class, 'instance'))->setValue(null, $responseStub);
$GLOBALS['token_mismatch'] = false;
$request = self::createStub(ServerRequest::class);
$request->method('isPost')->willReturn(true);
$authPlugin = self::createMock(AuthenticationPlugin::class);
$authPlugin->expects(self::once())->method('logOut');
$factory = self::createStub(AuthenticationPluginFactory::class);
$factory->method('create')->willReturn($authPlugin);
(new LogoutController($factory))($request);
unset($GLOBALS['token_mismatch']);
(new ReflectionProperty(ResponseRenderer::class, 'instance'))->setValue(null, null);
}
}