Completed
Pull Request — master (#2)
by Tomáš
01:43
created

QueryFieldConverterTest::getQueryField()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 53
Code Lines 13

Duplication

Lines 53
Ratio 100 %

Importance

Changes 0
Metric Value
dl 53
loc 53
rs 9.5797
c 0
b 0
f 0
cc 1
eloc 13
nc 1
nop 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A QueryFieldConverterTest.php$0 ➔ getName() 4 4 1
A QueryFieldConverterTest.php$0 ➔ getType() 4 4 1
A QueryFieldConverterTest.php$0 ➔ getDescription() 4 4 1
A QueryFieldConverterTest.php$0 ➔ getArgs() 6 6 1
A QueryFieldConverterTest.php$0 ➔ resolve() 4 4 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Portiny\GraphQL\Tests\Converter;
4
5
use GraphQL\Type\Definition\StringType;
6
use GraphQL\Type\Definition\Type;
7
use Portiny\GraphQL\Contract\Field\QueryFieldInterface;
8
use Portiny\GraphQL\Converter\QueryFieldConverter;
9
use Portiny\GraphQL\Tests\AbstractContainerTestCase;
10
11
12 View Code Duplication
class QueryFieldConverterTest extends AbstractContainerTestCase
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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