Skip to content

Commit 2c8391f

Browse files
committed
Fix profiler & update phpcs
1 parent a223567 commit 2c8391f

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

Diff for: composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
"static-analysis": [
9292
"phpstan analyse --ansi --memory-limit=1G"
9393
],
94-
"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",
94+
"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",
9595
"fix-cs": [
9696
"@install-cs",
9797
"@php php-cs-fixer.phar fix --diff -v --allow-risky=yes --ansi"

Diff for: src/Controller/ProfilerController.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use GraphQL\Utils\SchemaPrinter;
88
use Overblog\GraphQLBundle\Request\Executor as RequestExecutor;
9+
use Overblog\GraphQLBundle\Resolver\TypeResolver;
910
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
1011
use Symfony\Component\HttpFoundation\Request;
1112
use Symfony\Component\HttpFoundation\Response;
@@ -24,14 +25,16 @@ final class ProfilerController
2425
private ?Profiler $profiler;
2526
private ?Environment $twig;
2627
private string $endpointUrl;
28+
private TypeResolver $typeResolver;
2729
private RequestExecutor $requestExecutor;
2830
private ?string $queryMatch;
2931

30-
public function __construct(?Profiler $profiler, ?Environment $twig, RouterInterface $router, RequestExecutor $requestExecutor, ?string $queryMatch)
32+
public function __construct(?Profiler $profiler, ?Environment $twig, RouterInterface $router, TypeResolver $typeResolver, RequestExecutor $requestExecutor, ?string $queryMatch)
3133
{
3234
$this->profiler = $profiler;
3335
$this->twig = $twig;
3436
$this->endpointUrl = $router->generate('overblog_graphql_endpoint');
37+
$this->typeResolver = $typeResolver;
3538
$this->requestExecutor = $requestExecutor;
3639
$this->queryMatch = $queryMatch;
3740
}
@@ -69,9 +72,11 @@ public function __invoke(Request $request, string $token): Response
6972
}, $this->profiler->find(null, $this->queryMatch ?: $this->endpointUrl, $limit, 'POST', null, null, null)); // @phpstan-ignore-line
7073

7174
$schemas = [];
75+
$this->typeResolver->setIgnoreUnresolvableException(true);
7276
foreach ($this->requestExecutor->getSchemasNames() as $schemaName) {
7377
$schemas[$schemaName] = SchemaPrinter::doPrint($this->requestExecutor->getSchema($schemaName));
7478
}
79+
$this->typeResolver->setIgnoreUnresolvableException(false);
7580

7681
return new Response($this->twig->render('@OverblogGraphQL/profiler/graphql.html.twig', [
7782
'request' => $request,

Diff for: src/Resources/config/profiler.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ services:
55
- "@?profiler"
66
- "@?twig"
77
- "@router"
8+
- '@Overblog\GraphQLBundle\Resolver\TypeResolver'
89
- '@Overblog\GraphQLBundle\Request\Executor'
910
- "%overblog_graphql.profiler.query_match%"
1011

Diff for: tests/Controller/ProfilerControllerTest.php

+17-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
use GraphQL\Type\Schema;
88
use Overblog\GraphQLBundle\Controller\ProfilerController;
99
use Overblog\GraphQLBundle\DataCollector\GraphQLCollector;
10+
use Overblog\GraphQLBundle\Generator\TypeGenerator;
1011
use Overblog\GraphQLBundle\Request\Executor;
12+
use Overblog\GraphQLBundle\Resolver\TypeResolver;
1113
use PHPUnit\Framework\MockObject\MockObject;
1214
use PHPUnit\Framework\TestCase;
1315
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
@@ -45,6 +47,17 @@ protected function getMockExecutor(bool $expected = true): Executor
4547
return $executor;
4648
}
4749

50+
/**
51+
* @return TypeGenerator&MockObject
52+
*/
53+
protected function getMockTypeResolver(int $expected = 2): TypeResolver
54+
{
55+
$typeGenerator = $this->getMockBuilder(TypeResolver::class)->disableOriginalConstructor()->onlyMethods(['setIgnoreUnresolvableException'])->getMock();
56+
$typeGenerator->expects($this->exactly($expected))->method('setIgnoreUnresolvableException');
57+
58+
return $typeGenerator;
59+
}
60+
4861
/**
4962
* @return Profiler&MockObject
5063
*/
@@ -58,7 +71,7 @@ protected function getMockProfiler(): Profiler
5871

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

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

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

7285
$this->expectException(ServiceNotFoundException::class);
7386
$this->expectExceptionMessage('The GraphQL Profiler require twig');
@@ -79,10 +92,11 @@ public function testWithToken(): void
7992
$profilerMock = $this->getMockProfiler();
8093
$executorMock = $this->getMockExecutor();
8194
$routerMock = $this->getMockRouter();
95+
$typeGeneratorMock = $this->getMockTypeResolver();
8296

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

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

0 commit comments

Comments
 (0)