From bd113e21a04d166668a62fbfa2bf07aff769ea0f Mon Sep 17 00:00:00 2001 From: Simon Podlipsky Date: Sat, 13 Mar 2021 12:45:42 +0100 Subject: [PATCH] Include StarWars fixture It's no longer exported by webonyx/graphql-php --- composer.json | 5 +- tests/Functional/Webonyx/GraphQL/TestCase.php | 2 +- .../Webonyx/GraphQL/fixtures/StarWarsData.php | 174 ++++++++++++++++++ 3 files changed, 176 insertions(+), 5 deletions(-) create mode 100644 tests/Functional/Webonyx/GraphQL/fixtures/StarWarsData.php diff --git a/composer.json b/composer.json index 83000dd..28addd4 100644 --- a/composer.json +++ b/composer.json @@ -17,10 +17,7 @@ "psr-4": { "Overblog\\DataLoader\\Test\\": "tests/", "Overblog\\PromiseAdapter\\Test\\": "lib/promise-adapter/tests/" - }, - "files": [ - "vendor/webonyx/graphql-php/tests/StarWarsData.php" - ] + } }, "replace": { "overblog/promise-adapter": "self.version" diff --git a/tests/Functional/Webonyx/GraphQL/TestCase.php b/tests/Functional/Webonyx/GraphQL/TestCase.php index e5298c7..dba0b27 100644 --- a/tests/Functional/Webonyx/GraphQL/TestCase.php +++ b/tests/Functional/Webonyx/GraphQL/TestCase.php @@ -14,8 +14,8 @@ use GraphQL\Executor\Promise\Promise; use GraphQL\Executor\Promise\PromiseAdapter; use GraphQL\GraphQL; -use GraphQL\Tests\StarWarsData; use Overblog\DataLoader\DataLoader; +use Overblog\DataLoader\Test\Functional\Webonyx\GraphQL\fixtures\StarWarsData; use Overblog\PromiseAdapter\PromiseAdapterInterface; abstract class TestCase extends \PHPUnit\Framework\TestCase diff --git a/tests/Functional/Webonyx/GraphQL/fixtures/StarWarsData.php b/tests/Functional/Webonyx/GraphQL/fixtures/StarWarsData.php new file mode 100644 index 0000000..53284af --- /dev/null +++ b/tests/Functional/Webonyx/GraphQL/fixtures/StarWarsData.php @@ -0,0 +1,174 @@ + self::luke(), + '1001' => self::vader(), + '1002' => self::han(), + '1003' => self::leia(), + '1004' => self::tarkin(), + ]; + } + + private static function luke() + { + return [ + 'id' => '1000', + 'name' => 'Luke Skywalker', + 'friends' => ['1002', '1003', '2000', '2001'], + 'appearsIn' => [4, 5, 6], + 'homePlanet' => 'Tatooine', + ]; + } + + private static function vader() + { + return [ + 'id' => '1001', + 'name' => 'Darth Vader', + 'friends' => ['1004'], + 'appearsIn' => [4, 5, 6], + 'homePlanet' => 'Tatooine', + ]; + } + + private static function han() + { + return [ + 'id' => '1002', + 'name' => 'Han Solo', + 'friends' => ['1000', '1003', '2001'], + 'appearsIn' => [4, 5, 6], + ]; + } + + private static function leia() + { + return [ + 'id' => '1003', + 'name' => 'Leia Organa', + 'friends' => ['1000', '1002', '2000', '2001'], + 'appearsIn' => [4, 5, 6], + 'homePlanet' => 'Alderaan', + ]; + } + + private static function tarkin() + { + return [ + 'id' => '1004', + 'name' => 'Wilhuff Tarkin', + 'friends' => ['1001'], + 'appearsIn' => [4], + ]; + } + + public static function droids() + { + return [ + '2000' => self::threepio(), + '2001' => self::artoo(), + ]; + } + + private static function threepio() + { + return [ + 'id' => '2000', + 'name' => 'C-3PO', + 'friends' => ['1000', '1002', '1003', '2001'], + 'appearsIn' => [4, 5, 6], + 'primaryFunction' => 'Protocol', + ]; + } + + /** + * We export artoo directly because the schema returns him + * from a root field, and hence needs to reference him. + */ + private static function artoo() + { + return [ + + 'id' => '2001', + 'name' => 'R2-D2', + 'friends' => ['1000', '1002', '1003'], + 'appearsIn' => [4, 5, 6], + 'primaryFunction' => 'Astromech', + ]; + } + + /** + * Allows us to query for a character's friends. + */ + public static function getFriends($character) + { + return array_map([self::class, 'getCharacter'], $character['friends']); + } + + /** + * @param int $episode + * + * @return mixed[] + */ + public static function getHero($episode) + { + if ($episode === 5) { + // Luke is the hero of Episode V. + return self::luke(); + } + + // Artoo is the hero otherwise. + return self::artoo(); + } + + /** + * @param string $id + * + * @return mixed|null + */ + public static function getHuman($id) + { + $humans = self::humans(); + + return $humans[$id] ?? null; + } + + /** + * @param string $id + * + * @return mixed|null + */ + public static function getDroid($id) + { + $droids = self::droids(); + + return $droids[$id] ?? null; + } +}