| @@ 12-102 (lines=91) @@ | ||
| 9 | use Portiny\GraphQL\Tests\AbstractContainerTestCase; |
|
| 10 | ||
| 11 | ||
| 12 | final class MutationFieldConverterTest extends AbstractContainerTestCase |
|
| 13 | { |
|
| 14 | ||
| 15 | public function testToArray() |
|
| 16 | { |
|
| 17 | $mutationField = $this->getMutationField(); |
|
| 18 | $output = MutationFieldConverter::toArray($mutationField); |
|
| 19 | ||
| 20 | $this->assertSame('Some name', key($output)); |
|
| 21 | ||
| 22 | $mutationFieldAsArray = reset($output); |
|
| 23 | $this->assertInstanceOf(StringType::class, $mutationFieldAsArray['type']); |
|
| 24 | $this->assertSame('Some description', $mutationFieldAsArray['description']); |
|
| 25 | $this->assertArrayHasKey('someArg', $mutationFieldAsArray['args']); |
|
| 26 | $this->assertArrayHasKey('type', $mutationFieldAsArray['args']['someArg']); |
|
| 27 | $this->assertInstanceOf(StringType::class, $mutationFieldAsArray['args']['someArg']['type']); |
|
| 28 | $this->assertTrue(is_callable($mutationFieldAsArray['resolve'])); |
|
| 29 | } |
|
| 30 | ||
| 31 | ||
| 32 | public function testToObject() |
|
| 33 | { |
|
| 34 | $mutationField = $this->getMutationField(); |
|
| 35 | $mutationFieldAsArray = MutationFieldConverter::toArray($mutationField); |
|
| 36 | $output = MutationFieldConverter::toObject($mutationFieldAsArray); |
|
| 37 | ||
| 38 | $this->assertSame('Some name', $output->getName()); |
|
| 39 | $this->assertInstanceOf(StringType::class, $output->getType()); |
|
| 40 | $this->assertSame('Some description', $output->getDescription()); |
|
| 41 | $this->assertArrayHasKey('someArg', $output->getArgs()); |
|
| 42 | $this->assertArrayHasKey('type', $output->getArgs()['someArg']); |
|
| 43 | $this->assertInstanceOf(StringType::class, $output->getArgs()['someArg']['type']); |
|
| 44 | $this->assertSame('resolved', $output->resolve([], ['someArg' => ''])); |
|
| 45 | } |
|
| 46 | ||
| 47 | ||
| 48 | private function getMutationField(): MutationFieldInterface |
|
| 49 | { |
|
| 50 | return (new class () implements MutationFieldInterface |
|
| 51 | { |
|
| 52 | ||
| 53 | /** |
|
| 54 | * {@inheritdoc} |
|
| 55 | */ |
|
| 56 | public function getName(): string |
|
| 57 | { |
|
| 58 | return 'Some name'; |
|
| 59 | } |
|
| 60 | ||
| 61 | ||
| 62 | /** |
|
| 63 | * {@inheritdoc} |
|
| 64 | */ |
|
| 65 | public function getType(): Type |
|
| 66 | { |
|
| 67 | return Type::string(); |
|
| 68 | } |
|
| 69 | ||
| 70 | ||
| 71 | /** |
|
| 72 | * {@inheritdoc} |
|
| 73 | */ |
|
| 74 | public function getDescription(): string |
|
| 75 | { |
|
| 76 | return 'Some description'; |
|
| 77 | } |
|
| 78 | ||
| 79 | ||
| 80 | /** |
|
| 81 | * {@inheritdoc} |
|
| 82 | */ |
|
| 83 | public function getArgs(): array |
|
| 84 | { |
|
| 85 | return [ |
|
| 86 | 'someArg' => ['type' => Type::string()] |
|
| 87 | ]; |
|
| 88 | } |
|
| 89 | ||
| 90 | ||
| 91 | /** |
|
| 92 | * {@inheritdoc} |
|
| 93 | */ |
|
| 94 | public function resolve(array $root, array $args, $context = NULL) |
|
| 95 | { |
|
| 96 | return 'resolved'; |
|
| 97 | } |
|
| 98 | ||
| 99 | }); |
|
| 100 | } |
|
| 101 | ||
| 102 | } |
|
| 103 | ||
| @@ 12-102 (lines=91) @@ | ||
| 9 | use Portiny\GraphQL\Tests\AbstractContainerTestCase; |
|
| 10 | ||
| 11 | ||
| 12 | class QueryFieldConverterTest extends AbstractContainerTestCase |
|
| 13 | { |
|
| 14 | ||
| 15 | public function testToArray() |
|
| 16 | { |
|
| 17 | $queryField = $this->getQueryField(); |
|
| 18 | $output = QueryFieldConverter::toArray($queryField); |
|
| 19 | ||
| 20 | $this->assertSame('Some name', key($output)); |
|
| 21 | ||
| 22 | $queryFieldAsArray = reset($output); |
|
| 23 | $this->assertInstanceOf(StringType::class, $queryFieldAsArray['type']); |
|
| 24 | $this->assertSame('Some description', $queryFieldAsArray['description']); |
|
| 25 | $this->assertArrayHasKey('someArg', $queryFieldAsArray['args']); |
|
| 26 | $this->assertArrayHasKey('type', $queryFieldAsArray['args']['someArg']); |
|
| 27 | $this->assertInstanceOf(StringType::class, $queryFieldAsArray['args']['someArg']['type']); |
|
| 28 | $this->assertTrue(is_callable($queryFieldAsArray['resolve'])); |
|
| 29 | } |
|
| 30 | ||
| 31 | ||
| 32 | public function testToObject() |
|
| 33 | { |
|
| 34 | $queryField = $this->getQueryField(); |
|
| 35 | $queryFieldAsArray = QueryFieldConverter::toArray($queryField); |
|
| 36 | $output = QueryFieldConverter::toObject($queryFieldAsArray); |
|
| 37 | ||
| 38 | $this->assertSame('Some name', $output->getName()); |
|
| 39 | $this->assertInstanceOf(StringType::class, $output->getType()); |
|
| 40 | $this->assertSame('Some description', $output->getDescription()); |
|
| 41 | $this->assertArrayHasKey('someArg', $output->getArgs()); |
|
| 42 | $this->assertArrayHasKey('type', $output->getArgs()['someArg']); |
|
| 43 | $this->assertInstanceOf(StringType::class, $output->getArgs()['someArg']['type']); |
|
| 44 | $this->assertSame('resolved', $output->resolve([], ['someArg' => ''])); |
|
| 45 | } |
|
| 46 | ||
| 47 | ||
| 48 | private function getQueryField(): QueryFieldInterface |
|
| 49 | { |
|
| 50 | return (new class () implements QueryFieldInterface |
|
| 51 | { |
|
| 52 | ||
| 53 | /** |
|
| 54 | * {@inheritdoc} |
|
| 55 | */ |
|
| 56 | public function getName(): string |
|
| 57 | { |
|
| 58 | return 'Some name'; |
|
| 59 | } |
|
| 60 | ||
| 61 | ||
| 62 | /** |
|
| 63 | * {@inheritdoc} |
|
| 64 | */ |
|
| 65 | public function getType(): Type |
|
| 66 | { |
|
| 67 | return Type::string(); |
|
| 68 | } |
|
| 69 | ||
| 70 | ||
| 71 | /** |
|
| 72 | * {@inheritdoc} |
|
| 73 | */ |
|
| 74 | public function getDescription(): string |
|
| 75 | { |
|
| 76 | return 'Some description'; |
|
| 77 | } |
|
| 78 | ||
| 79 | ||
| 80 | /** |
|
| 81 | * {@inheritdoc} |
|
| 82 | */ |
|
| 83 | public function getArgs(): array |
|
| 84 | { |
|
| 85 | return [ |
|
| 86 | 'someArg' => ['type' => Type::string()] |
|
| 87 | ]; |
|
| 88 | } |
|
| 89 | ||
| 90 | ||
| 91 | /** |
|
| 92 | * {@inheritdoc} |
|
| 93 | */ |
|
| 94 | public function resolve(array $root, array $args, $context = NULL) |
|
| 95 | { |
|
| 96 | return 'resolved'; |
|
| 97 | } |
|
| 98 | ||
| 99 | }); |
|
| 100 | } |
|
| 101 | ||
| 102 | } |
|
| 103 | ||