Remove ResponseRenderer::disable from SchemaExportController
Creates a new Response object instead of using the response from ResponseRenderer class. Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
parent
058ba3d3a2
commit
ad1336feb5
@ -616,7 +616,7 @@ return [
|
||||
],
|
||||
SchemaExportController::class => [
|
||||
'class' => SchemaExportController::class,
|
||||
'arguments' => ['$export' => '@export', '$response' => '@response'],
|
||||
'arguments' => ['@export', '@response', '@' . ResponseFactory::class],
|
||||
],
|
||||
Server\BinlogController::class => [
|
||||
'class' => Server\BinlogController::class,
|
||||
|
||||
@ -2503,11 +2503,6 @@
|
||||
<code><![CDATA[__construct]]></code>
|
||||
</PossiblyUnusedMethod>
|
||||
</file>
|
||||
<file src="src/Controllers/SchemaExportController.php">
|
||||
<PossiblyUnusedReturnValue>
|
||||
<code><![CDATA[Response|null]]></code>
|
||||
</PossiblyUnusedReturnValue>
|
||||
</file>
|
||||
<file src="src/Controllers/Server/BinlogController.php">
|
||||
<DeprecatedMethod>
|
||||
<code><![CDATA[Config::getInstance()]]></code>
|
||||
|
||||
@ -8,6 +8,7 @@ use PhpMyAdmin\Core;
|
||||
use PhpMyAdmin\Exceptions\ExportException;
|
||||
use PhpMyAdmin\Export\Export;
|
||||
use PhpMyAdmin\Html\MySQLDocumentation;
|
||||
use PhpMyAdmin\Http\Factory\ResponseFactory;
|
||||
use PhpMyAdmin\Http\Response;
|
||||
use PhpMyAdmin\Http\ServerRequest;
|
||||
use PhpMyAdmin\Identifiers\DatabaseName;
|
||||
@ -23,8 +24,11 @@ use function mb_strlen;
|
||||
*/
|
||||
final class SchemaExportController implements InvocableController
|
||||
{
|
||||
public function __construct(private readonly Export $export, private readonly ResponseRenderer $response)
|
||||
{
|
||||
public function __construct(
|
||||
private readonly Export $export,
|
||||
private readonly ResponseRenderer $response,
|
||||
private readonly ResponseFactory $responseFactory,
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(ServerRequest $request): Response|null
|
||||
@ -54,14 +58,13 @@ final class SchemaExportController implements InvocableController
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->response->disable();
|
||||
$response = $this->responseFactory->createResponse();
|
||||
Core::downloadHeader(
|
||||
$exportInfo['fileName'],
|
||||
$exportInfo['mediaType'],
|
||||
mb_strlen($exportInfo['fileData'], '8bit'),
|
||||
);
|
||||
echo $exportInfo['fileData'];
|
||||
|
||||
return null;
|
||||
return $response->write($exportInfo['fileData']);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,16 +4,23 @@ declare(strict_types=1);
|
||||
|
||||
namespace PhpMyAdmin\Tests\Controllers;
|
||||
|
||||
use Fig\Http\Message\StatusCodeInterface;
|
||||
use PhpMyAdmin\Controllers\SchemaExportController;
|
||||
use PhpMyAdmin\DatabaseInterface;
|
||||
use PhpMyAdmin\Export\Export;
|
||||
use PhpMyAdmin\Http\Factory\ResponseFactory;
|
||||
use PhpMyAdmin\Http\ServerRequest;
|
||||
use PhpMyAdmin\Tests\AbstractTestCase;
|
||||
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\RunTestsInSeparateProcesses;
|
||||
|
||||
use function function_exists;
|
||||
use function xdebug_get_headers;
|
||||
|
||||
#[CoversClass(SchemaExportController::class)]
|
||||
class SchemaExportControllerTest extends AbstractTestCase
|
||||
#[RunTestsInSeparateProcesses]
|
||||
final class SchemaExportControllerTest extends AbstractTestCase
|
||||
{
|
||||
public function testExport(): void
|
||||
{
|
||||
@ -28,13 +35,20 @@ class SchemaExportControllerTest extends AbstractTestCase
|
||||
'fileData' => 'file data',
|
||||
]);
|
||||
|
||||
$response = new ResponseRenderer();
|
||||
$controller = new SchemaExportController($export, $response);
|
||||
$controller($request);
|
||||
$output = $this->getActualOutputForAssertion();
|
||||
self::assertSame('file data', $output);
|
||||
self::assertTrue($response->isDisabled());
|
||||
self::assertSame('', $response->getHTMLResult());
|
||||
self::assertSame([], $response->getJSONResult());
|
||||
$controller = new SchemaExportController($export, new ResponseRenderer(), ResponseFactory::create());
|
||||
$response = $controller($request);
|
||||
|
||||
self::assertNotNull($response);
|
||||
self::assertSame(StatusCodeInterface::STATUS_OK, $response->getStatusCode());
|
||||
self::assertSame('file data', (string) $response->getBody());
|
||||
|
||||
if (! function_exists('xdebug_get_headers')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$headersList = xdebug_get_headers();
|
||||
self::assertContains('Content-Disposition: attachment; filename="file.svg"', $headersList);
|
||||
self::assertContains('Content-Type: image/svg+xml', $headersList);
|
||||
self::assertContains('Content-Length: 9', $headersList);
|
||||
}
|
||||
}
|
||||
|
||||
@ -172,11 +172,6 @@ class ResponseRenderer extends \PhpMyAdmin\ResponseRenderer
|
||||
return $this->isAjax;
|
||||
}
|
||||
|
||||
public function isDisabled(): bool
|
||||
{
|
||||
return $this->isDisabled;
|
||||
}
|
||||
|
||||
public function getResponse(): Response
|
||||
{
|
||||
return $this->response;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user