Skip to content

Commit

Permalink
Merge pull request #1157 from cfv1000/master
Browse files Browse the repository at this point in the history
fix issue with parsing invalid files
  • Loading branch information
Vincz authored Feb 1, 2024
2 parents a223567 + 81f9687 commit 9516e5b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Config/Parser/MetadataParser/MetadataParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ private static function processFile(SplFileInfo $file, ContainerBuilder $contain
}

return $preProcess ? self::$map->toArray() : $gqlTypes;
} catch (ReflectionException $e) {
return $gqlTypes;
} catch (\InvalidArgumentException $e) {
throw new InvalidArgumentException(sprintf('Failed to parse GraphQL metadata from file "%s".', $file), $e->getCode(), $e);
}
Expand Down
26 changes: 26 additions & 0 deletions tests/Config/Parser/MetadataParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -615,4 +615,30 @@ public function testInvalidProviderMutationOnQuery(): void
$this->assertMatchesRegularExpression('/try to add a mutation on type "RootQuery2"/', $e->getPrevious()->getMessage());
}
}

public function testInvalidPhpFiles(): void
{
$files = [
__DIR__.'/fixtures/annotations/Invalid/HasNoClass.php',
__DIR__.'/fixtures/annotations/Invalid/EmptyPhpFile.php',
__DIR__.'/fixtures/annotations/Invalid/NotAPhpFile',
__DIR__.'/fixtures/annotations/Type/RootQuery.php',
];
$this->parser('reset', $this->parserConfig);

foreach ($files as $file) {
$this->parser('preParse', new SplFileInfo($file), $this->containerBuilder, $this->parserConfig);
}

$config = [];
foreach ($files as $file) {
$config += self::cleanConfig($this->parser('parse', new SplFileInfo($file), $this->containerBuilder, $this->parserConfig));
}

$this->assertSame([
'RootQuery' => [
'type' => 'object',
],
], $config);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

declare(strict_types=1);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

declare(strict_types=1);

return function (): void {};
Empty file.

0 comments on commit 9516e5b

Please sign in to comment.