Skip to content

Commit

Permalink
test(graphql): Scout tests will be run only if Scout installed. (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
LastDragon-ru authored Jan 21, 2024
1 parent afe2eb5 commit a7b3270
Show file tree
Hide file tree
Showing 31 changed files with 4,329 additions and 3,192 deletions.
3 changes: 3 additions & 0 deletions packages/graphql/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
cacheDirectory=".phpunit/result.cache"
executionOrder="random"
colors="true">
<extensions>
<bootstrap class="LastDragon_ru\LaraASP\Testing\Requirements\PhpUnit\Extension"/>
</extensions>
<testsuites>
<testsuite name="package">
<directory suffix="Test.php">./src</directory>
Expand Down
418 changes: 356 additions & 62 deletions packages/graphql/src/Builder/BuilderInfoDetectorTest.php

Large diffs are not rendered by default.

47 changes: 32 additions & 15 deletions packages/graphql/src/SearchBy/Directives/DirectiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
namespace LastDragon_ru\LaraASP\GraphQL\SearchBy\Directives;

use Closure;
use Composer\InstalledVersions;
use Composer\Semver\VersionParser;
use Exception;
use GraphQL\Language\AST\Node;
use GraphQL\Language\AST\TypeDefinitionNode;
Expand Down Expand Up @@ -41,6 +39,7 @@
use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\EloquentBuilderDataProvider;
use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\QueryBuilderDataProvider;
use LastDragon_ru\LaraASP\GraphQL\Testing\Package\DataProviders\ScoutBuilderDataProvider;
use LastDragon_ru\LaraASP\GraphQL\Testing\Package\Requirements\RequiresLaravelScout;
use LastDragon_ru\LaraASP\GraphQL\Testing\Package\TestCase;
use LastDragon_ru\LaraASP\GraphQLPrinter\Testing\GraphQLExpected;
use LastDragon_ru\LaraASP\Testing\Constraints\Json\JsonMatchesFragment;
Expand Down Expand Up @@ -84,10 +83,6 @@ final class DirectiveTest extends TestCase {
* @param Closure(static): void|null $prepare
*/
public function testManipulateArgDefinition(Closure $expected, string $graphql, ?Closure $prepare = null): void {
$directives = Container::getInstance()->make(DirectiveLocator::class);

$directives->setResolved('search', SearchDirective::class);

if ($prepare) {
$prepare($this);
}
Expand All @@ -101,6 +96,33 @@ public function testManipulateArgDefinition(Closure $expected, string $graphql,
);
}

#[RequiresLaravelScout]
public function testManipulateArgDefinitionScoutBuilder(): void {
config([
Package::Name.'.search_by.operators.Date' => [
SearchByOperatorEqualDirective::class,
],
]);

Container::getInstance()->make(DirectiveLocator::class)
->setResolved('search', SearchDirective::class);

$this->useGraphQLSchema(
self::getTestData()->file('~scout.graphql'),
);

self::assertGraphQLSchemaEquals(
new GraphQLExpected(
static::getTestData()->file(
match (true) {
(new RequiresLaravelScout('>=10.3.0'))->isSatisfied() => '~scout-v10.3.0-expected.graphql',
default => '~scout-expected.graphql',
},
),
),
);
}

public function testManipulateArgDefinitionUnknownType(): void {
self::expectExceptionObject(new TypeDefinitionUnknown('UnknownType'));

Expand Down Expand Up @@ -290,6 +312,7 @@ public function testHandleBuilder(
* @param Closure(object, Property): string|null $resolver
* @param Closure():FieldResolver|null $fieldResolver
*/
#[RequiresLaravelScout]
public function testHandleScoutBuilder(
array|Exception $expected,
Closure $builderFactory,
Expand Down Expand Up @@ -365,15 +388,9 @@ public static function dataProviderManipulateArgDefinition(): array {
return [
'full' => [
static function (self $test): GraphQLExpected {
$satisfies = static function (string $version): bool {
return InstalledVersions::satisfies(new VersionParser(), 'laravel/scout', $version);
};
$file = match (true) {
$satisfies('>=10.3.0') => '~full-expected-scout-v10.3.0.graphql',
default => '~full-expected.graphql',
};

return new GraphQLExpected($test::getTestData()->file($file));
return (new GraphQLExpected(
$test::getTestData()->file('~full-expected.graphql'),
));
},
'~full.graphql',
static function (): void {
Expand Down
Loading

0 comments on commit a7b3270

Please sign in to comment.