Files
kupshop/bundles/KupShop/GraphQLBundle/Tests/GraphQLTestCase.php
2025-08-02 16:30:27 +02:00

69 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace KupShop\GraphQLBundle\Tests;
use KupShop\AdminBundle\Util\AdminTestTrait;
use Symfony\Component\HttpFoundation\Response;
class GraphQLTestCase extends \DatabaseTestCase
{
use AdminTestTrait;
private const ADMIN_AUTH_TOKEN = '7b37429817eaed4';
private $legacyAdminCredentials;
protected function setUp(): void
{
parent::setUp();
$this->adminLogout();
}
public function doAdminRequest(string $query, array $variables = [], bool $includeAuthToken = true, string $uri = '/admin/graphql/', array $headers = []): Response
{
$server = [];
if ($includeAuthToken) {
$server['HTTP_X-Access-Token'] = self::ADMIN_AUTH_TOKEN;
}
$client = $this->createClient([], $server);
$client->request(
'POST',
$uri,
[],
[],
$headers,
json_encode(['query' => $query, 'variables' => $variables])
);
$response = $client->getResponse();
$this->unsetAdminLoginSession();
return $response;
}
public function doRequest(string $query, array $variables = []): Response
{
$client = $this->createClient();
$client->request(
'POST',
'/graphql',
[],
[],
[],
json_encode(['query' => $query, 'variables' => $variables])
);
return $client->getResponse();
}
private function unsetAdminLoginSession(): void
{
global $adminID;
$adminID = null;
$this->adminLogout();
}
}