Skip to content

Commit

Permalink
Merge pull request #1117 from sparklink-pro/master
Browse files Browse the repository at this point in the history
Fix profiler & doc block type guesser
  • Loading branch information
Vincz committed Apr 28, 2023
2 parents f392dbd + 8e48a1b commit f35dda7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/Controller/ProfilerController.php
Expand Up @@ -9,6 +9,7 @@
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\HttpKernel\Profiler\Profiler;
use Symfony\Component\Routing\RouterInterface;
use Twig\Environment;
Expand Down Expand Up @@ -54,6 +55,9 @@ public function __invoke(Request $request, string $token): Response

$profile = $this->profiler->loadProfile($token);

// Type hint as int for the $limit argument of the find method was updated in Symfony 5.4.22 and 6.2.8
$limit = (Kernel::VERSION_ID >= 60208 || (Kernel::MAJOR_VERSION === 5 && Kernel::VERSION_ID >= 50422)) ? 100 : '100'; // @phpstan-ignore-line

$tokens = array_map(function ($tokenData) {
$profile = $this->profiler->loadProfile($tokenData['token']);
if (!$profile->hasCollector('graphql')) {
Expand All @@ -62,7 +66,7 @@ public function __invoke(Request $request, string $token): Response
$tokenData['graphql'] = $profile->getCollector('graphql');

return $tokenData;
}, $this->profiler->find(null, $this->queryMatch ?: $this->endpointUrl, '100', 'POST', null, null, null)); // @phpstan-ignore-line
}, $this->profiler->find(null, $this->queryMatch ?: $this->endpointUrl, $limit, 'POST', null, null, null)); // @phpstan-ignore-line

$schemas = [];
foreach ($this->requestExecutor->getSchemasNames() as $schemaName) {
Expand Down
Expand Up @@ -67,15 +67,22 @@ public function guessSuccessDataProvider(): iterable
/**
* @dataProvider guessErrorDataProvider
*/
public function testGuessError(string $docType, string $reflectorClass, string $match): void
public function testGuessError(string $docType, string $reflectorClass, string $match, bool $canParsingFailed = false): void
{
$docBlockGuesser = new DocBlockTypeGuesser(new ClassesTypesMap());
try {
$docBlockGuesser->guessType(new ReflectionClass(__CLASS__), $this->getMockedReflector($docType, $reflectorClass));
$this->fail(sprintf('The @var "%s" should resolve to GraphQL type "%s"', $docType, $match));
} catch (Exception $e) {
$this->assertInstanceOf(TypeGuessingException::class, $e);
$this->assertStringContainsString($match, $e->getMessage());
if ($canParsingFailed) {
$this->assertThat($e->getMessage(), $this->logicalOr(
$this->equalTo('Doc Block parsing failed with'),
$this->equalTo($e->getMessage())
));
} else {
$this->assertStringContainsString($match, $e->getMessage());
}
}
}

Expand All @@ -88,8 +95,8 @@ public function guessErrorDataProvider(): iterable
yield ['object', $reflectorClass, 'Tag @'.$tag.' found, but type "object" is too generic'];
yield ['mixed[]', $reflectorClass, 'Tag @'.$tag.' found, but the array values cannot be mixed type'];
yield ['array<mixed>', $reflectorClass, 'Tag @'.$tag.' found, but the array values cannot be mixed type'];
yield ['', $reflectorClass, 'No @'.$tag.' tag found in doc block or tag has no type'];
yield ['[]', $reflectorClass, 'No @'.$tag.' tag found in doc block or tag has no type'];
yield ['', $reflectorClass, 'No @'.$tag.' tag found in doc block or tag has no type', true]; // phpDocumentor/ReflectionDocBlock
yield ['[]', $reflectorClass, 'No @'.$tag.' tag found in doc block or tag has no type', true]; // phpDocumentor/ReflectionDocBlock
}
}

Expand Down

0 comments on commit f35dda7

Please sign in to comment.