Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix profiler & update phpcs #1155

Merged
merged 4 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ jobs:
uses: "shivammathur/setup-php@v2"
with:
tools: flex
php-version: "8.1"
php-version: "8.2"
coverage: "none"

- name: "Install dependencies"
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"static-analysis": [
"phpstan analyse --ansi --memory-limit=1G"
],
"install-cs": "test -f php-cs-fixer.phar || wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v3.17.0/php-cs-fixer.phar -O php-cs-fixer.phar",
"install-cs": "test -f php-cs-fixer.phar || wget https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/releases/download/v3.48.0/php-cs-fixer.phar -O php-cs-fixer.phar",
"fix-cs": [
"@install-cs",
"@php php-cs-fixer.phar fix --diff -v --allow-risky=yes --ansi"
Expand Down
1 change: 1 addition & 0 deletions src/Config/TypeDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ protected function validationSection(int $level): ArrayNodeDefinition
return $value;
}
}

// validation: [list of constraints]
return ['constraints' => $value];
}
Expand Down
7 changes: 6 additions & 1 deletion src/Controller/ProfilerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use GraphQL\Utils\SchemaPrinter;
use Overblog\GraphQLBundle\Request\Executor as RequestExecutor;
use Overblog\GraphQLBundle\Resolver\TypeResolver;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -24,14 +25,16 @@ final class ProfilerController
private ?Profiler $profiler;
private ?Environment $twig;
private string $endpointUrl;
private TypeResolver $typeResolver;
private RequestExecutor $requestExecutor;
private ?string $queryMatch;

public function __construct(?Profiler $profiler, ?Environment $twig, RouterInterface $router, RequestExecutor $requestExecutor, ?string $queryMatch)
public function __construct(?Profiler $profiler, ?Environment $twig, RouterInterface $router, TypeResolver $typeResolver, RequestExecutor $requestExecutor, ?string $queryMatch)
{
$this->profiler = $profiler;
$this->twig = $twig;
$this->endpointUrl = $router->generate('overblog_graphql_endpoint');
$this->typeResolver = $typeResolver;
$this->requestExecutor = $requestExecutor;
$this->queryMatch = $queryMatch;
}
Expand Down Expand Up @@ -69,9 +72,11 @@ public function __invoke(Request $request, string $token): Response
}, $this->profiler->find(null, $this->queryMatch ?: $this->endpointUrl, $limit, 'POST', null, null, null)); // @phpstan-ignore-line

$schemas = [];
$this->typeResolver->setIgnoreUnresolvableException(true);
foreach ($this->requestExecutor->getSchemasNames() as $schemaName) {
$schemas[$schemaName] = SchemaPrinter::doPrint($this->requestExecutor->getSchema($schemaName));
}
$this->typeResolver->setIgnoreUnresolvableException(false);

return new Response($this->twig->render('@OverblogGraphQL/profiler/graphql.html.twig', [
'request' => $request,
Expand Down
2 changes: 0 additions & 2 deletions src/Relay/Connection/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public function setEdges(iterable $edges): void;

/**
* Get the page info.
*
* @return PageInfoInterface
*/
public function getPageInfo(): ?PageInfoInterface;

Expand Down
12 changes: 0 additions & 12 deletions src/Relay/Connection/Output/PageInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ public function __construct(string $startCursor = null, string $endCursor = null
$this->hasNextPage = $hasNextPage;
}

/**
* @return string
*/
public function getStartCursor(): ?string
{
return $this->startCursor;
Expand All @@ -36,9 +33,6 @@ public function setStartCursor(string $startCursor): void
$this->startCursor = $startCursor;
}

/**
* @return string
*/
public function getEndCursor(): ?string
{
return $this->endCursor;
Expand All @@ -49,9 +43,6 @@ public function setEndCursor(string $endCursor): void
$this->endCursor = $endCursor;
}

/**
* @return bool
*/
public function getHasPreviousPage(): ?bool
{
return $this->hasPreviousPage;
Expand All @@ -62,9 +53,6 @@ public function setHasPreviousPage(bool $hasPreviousPage): void
$this->hasPreviousPage = $hasPreviousPage;
}

/**
* @return bool
*/
public function getHasNextPage(): ?bool
{
return $this->hasNextPage;
Expand Down
12 changes: 0 additions & 12 deletions src/Relay/Connection/PageInfoInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,18 @@

interface PageInfoInterface
{
/**
* @return string
*/
public function getStartCursor(): ?string;

public function setStartCursor(string $startCursor): void;

/**
* @return string
*/
public function getEndCursor(): ?string;

public function setEndCursor(string $endCursor): void;

/**
* @return bool
*/
public function getHasPreviousPage(): ?bool;

public function setHasPreviousPage(bool $hasPreviousPage): void;

/**
* @return bool
*/
public function getHasNextPage(): ?bool;

public function setHasNextPage(bool $hasNextPage): void;
Expand Down
2 changes: 0 additions & 2 deletions src/Resolver/TypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ protected function onLoadSolution($solution): void

/**
* @param string $alias
*
* @return Type
*/
public function resolve($alias): ?Type
{
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/profiler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ services:
- "@?profiler"
- "@?twig"
- "@router"
- '@Overblog\GraphQLBundle\Resolver\TypeResolver'
- '@Overblog\GraphQLBundle\Request\Executor'
- "%overblog_graphql.profiler.query_match%"

Expand Down
3 changes: 0 additions & 3 deletions src/Upload/Type/GraphQLUploadType.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@

final class GraphQLUploadType extends ScalarType
{
/**
* @param string $name
*/
public function __construct(string $name = null)
{
parent::__construct([
Expand Down
2 changes: 1 addition & 1 deletion src/Validator/InputValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function __construct(
/**
* @throws ArgumentsValidationException
*/
public function validate(string|array|null $groups = null, bool $throw = true): ?ConstraintViolationListInterface
public function validate(string|array $groups = null, bool $throw = true): ?ConstraintViolationListInterface
{
$rootNode = new ValidationNode(
$this->info->parentType,
Expand Down
6 changes: 3 additions & 3 deletions tests/Config/Parser/fixtures/graphql/schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@
'type' => 'custom-scalar',
'config' => [
'description' => null,
'serialize' => [\Overblog\GraphQLBundle\Config\Parser\GraphQL\ASTConverter\CustomScalarNode::class, 'mustOverrideConfig'],
'parseValue' => [\Overblog\GraphQLBundle\Config\Parser\GraphQL\ASTConverter\CustomScalarNode::class, 'mustOverrideConfig'],
'parseLiteral' => [\Overblog\GraphQLBundle\Config\Parser\GraphQL\ASTConverter\CustomScalarNode::class, 'mustOverrideConfig'],
'serialize' => [Overblog\GraphQLBundle\Config\Parser\GraphQL\ASTConverter\CustomScalarNode::class, 'mustOverrideConfig'],
'parseValue' => [Overblog\GraphQLBundle\Config\Parser\GraphQL\ASTConverter\CustomScalarNode::class, 'mustOverrideConfig'],
'parseLiteral' => [Overblog\GraphQLBundle\Config\Parser\GraphQL\ASTConverter\CustomScalarNode::class, 'mustOverrideConfig'],
],
],
];
19 changes: 16 additions & 3 deletions tests/Controller/ProfilerControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Overblog\GraphQLBundle\Controller\ProfilerController;
use Overblog\GraphQLBundle\DataCollector\GraphQLCollector;
use Overblog\GraphQLBundle\Request\Executor;
use Overblog\GraphQLBundle\Resolver\TypeResolver;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
Expand Down Expand Up @@ -45,6 +46,17 @@ protected function getMockExecutor(bool $expected = true): Executor
return $executor;
}

/**
* @return TypeResolver&MockObject
*/
protected function getMockTypeResolver(int $expected = 2): TypeResolver
{
$typeGenerator = $this->getMockBuilder(TypeResolver::class)->disableOriginalConstructor()->onlyMethods(['setIgnoreUnresolvableException'])->getMock();
$typeGenerator->expects($this->exactly($expected))->method('setIgnoreUnresolvableException');

return $typeGenerator;
}

/**
* @return Profiler&MockObject
*/
Expand All @@ -58,7 +70,7 @@ protected function getMockProfiler(): Profiler

public function testInvokeWithoutProfiler(): void
{
$controller = new ProfilerController(null, null, $this->getMockRouter(), $this->getMockExecutor(false), null);
$controller = new ProfilerController(null, null, $this->getMockRouter(), $this->getMockTypeResolver(0), $this->getMockExecutor(false), null);

$this->expectException(ServiceNotFoundException::class);
$this->expectExceptionMessage('The profiler must be enabled.');
Expand All @@ -67,7 +79,7 @@ public function testInvokeWithoutProfiler(): void

public function testInvokeWithoutTwig(): void
{
$controller = new ProfilerController($this->getMockProfiler(), null, $this->getMockRouter(), $this->getMockExecutor(false), null);
$controller = new ProfilerController($this->getMockProfiler(), null, $this->getMockRouter(), $this->getMockTypeResolver(0), $this->getMockExecutor(false), null);

$this->expectException(ServiceNotFoundException::class);
$this->expectExceptionMessage('The GraphQL Profiler require twig');
Expand All @@ -79,10 +91,11 @@ public function testWithToken(): void
$profilerMock = $this->getMockProfiler();
$executorMock = $this->getMockExecutor();
$routerMock = $this->getMockRouter();
$typeGeneratorMock = $this->getMockTypeResolver();

/** @var Environment&MockObject $twigMock */
$twigMock = $this->getMockBuilder(Environment::class)->disableOriginalConstructor()->onlyMethods(['render'])->getMock();
$controller = new ProfilerController($profilerMock, $twigMock, $routerMock, $executorMock, null);
$controller = new ProfilerController($profilerMock, $twigMock, $routerMock, $typeGeneratorMock, $executorMock, null);

/** @var Profiler&MockObject $profilerMock */
$profilerMock->expects($this->once())->method('disable');
Expand Down
Loading