Code Duplication    Length = 80-80 lines in 2 locations

tests/Converter/MutationFieldConverterTest.php 1 location

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

tests/Converter/QueryFieldConverterTest.php 1 location

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