Completed
Pull Request — master (#31)
by Sebastian
06:26 queued 02:32
created

SchemaTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 10

Importance

Changes 7
Bugs 0 Features 1
Metric Value
wmc 4
c 7
b 0
f 1
lcom 1
cbo 10
dl 0
loc 62
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testInlineSchema() 0 21 1
A testStandaloneEmptySchema() 0 5 1
A testStandaloneSchema() 0 12 1
A testSchemaWithoutClosuresSerializable() 0 16 1
1
<?php
2
/*
3
* This file is a part of GraphQL project.
4
*
5
* @author Alexandr Viniychuk <[email protected]>
6
* created: 5/12/16 10:11 PM
7
*/
8
9
namespace Youshido\Tests\Schema;
10
11
12
use Youshido\GraphQL\Schema\Schema;
13
use Youshido\GraphQL\Type\NonNullType;
14
use Youshido\GraphQL\Type\Object\ObjectType;
15
use Youshido\GraphQL\Type\Scalar\IntType;
16
use Youshido\GraphQL\Type\Scalar\StringType;
17
use Youshido\Tests\DataProvider\TestEmptySchema;
18
use Youshido\Tests\DataProvider\TestObjectType;
19
use Youshido\Tests\DataProvider\TestSchema;
20
21
class SchemaTest extends \PHPUnit_Framework_TestCase
22
{
23
24
    public function testInlineSchema()
25
    {
26
        $queryType = new ObjectType([
0 ignored issues
show
Unused Code introduced by
$queryType is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
27
            'name'   => 'RootQueryType',
28
            'fields' => [
29
                'currentTime' => [
30
                    'type'    => new StringType(),
31
                    'resolve' => function ($value, $args, $type) {
0 ignored issues
show
Unused Code introduced by
The parameter $value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $args is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
32
                        return 'May 5, 9:00am';
33
                    },
34
                    'args'    => [
35
                        'gmt' => [
36
                            'type'    => new IntType(),
37
                            'default' => -5
38
                        ],
39
                    ],
40
                ]
41
            ]
42
        ]);
43
//        $this->assertEquals('May 5, 9:00am', $queryType->getField('currentTime')->resolve([], [],));
0 ignored issues
show
Unused Code Comprehensibility introduced by
78% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
44
    }
45
46
    public function testStandaloneEmptySchema()
47
    {
48
        $schema = new TestEmptySchema();
49
        $this->assertFalse($schema->getQueryType()->hasFields());
50
    }
51
52
    public function testStandaloneSchema()
53
    {
54
        $schema = new TestSchema();
55
        $this->assertTrue($schema->getQueryType()->hasFields());
56
        $this->assertTrue($schema->getMutationType()->hasFields());
57
58
        $this->assertEquals(1, count($schema->getMutationType()->getFields()));
59
60
        $schema->addMutationField('changeUser', ['type' => new TestObjectType(), 'resolve' => function () { }]);
61
        $this->assertEquals(2, count($schema->getMutationType()->getFields()));
62
63
    }
64
65
    public function testSchemaWithoutClosuresSerializable()
66
    {
67
        $schema = new TestEmptySchema();
68
        $schema->getQueryType()->addField('randomInt', [
69
            'type' => new NonNullType(new IntType()),
70
            'resolve' => 'rand',
71
        ]);
72
73
        $serialized = serialize($schema);
74
        /** @var Schema $unserialized */
75
        $unserialized = unserialize($serialized);
76
77
        $this->assertTrue($unserialized->getQueryType()->hasFields());
78
        $this->assertFalse($unserialized->getMutationType()->hasFields());
79
        $this->assertEquals(1, count($unserialized->getQueryType()->getFields()));
80
    }
81
82
}
83