Passed
Pull Request — master (#63)
by David
03:26
created

ResolvableInputObjectTypeTest::testResolve()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 27
rs 9.584
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace TheCodingMachine\GraphQL\Controllers\Types;
4
5
use TheCodingMachine\GraphQL\Controllers\AbstractQueryProviderTest;
6
use TheCodingMachine\GraphQL\Controllers\Fixtures\TestObject;
7
use TheCodingMachine\GraphQL\Controllers\Fixtures\TestObject2;
8
use TheCodingMachine\GraphQL\Controllers\Fixtures\TestObjectWithRecursiveList;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\GraphQL...ObjectWithRecursiveList was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use TheCodingMachine\GraphQL\Controllers\Fixtures\Types\TestFactory;
10
use TheCodingMachine\GraphQL\Controllers\GraphQLException;
11
12
class ResolvableInputObjectTypeTest extends AbstractQueryProviderTest
13
{
14
15
    public function testResolve(): void
16
    {
17
        $inputType = new ResolvableInputObjectType('InputObject',
18
            $this->getControllerQueryProviderFactory(),
19
            $this->getTypeMapper(),
20
            new TestFactory(),
21
            'myFactory',
22
            $this->getHydrator(),
23
            'my comment');
24
25
        $this->assertSame('InputObject', $inputType->name);
26
        $this->assertCount(2, $inputType->getFields());
27
        $this->assertSame('my comment', $inputType->description);
28
29
        $obj = $inputType->resolve(['string' => 'foobar', 'bool' => false]);
30
        $this->assertInstanceOf(TestObject::class, $obj);
31
        $this->assertSame('foobar', $obj->getTest());
32
        $this->assertSame(false, $obj->isTestBool());
33
34
        $obj = $inputType->resolve(['string' => 'foobar']);
35
        $this->assertInstanceOf(TestObject::class, $obj);
36
        $this->assertSame('foobar', $obj->getTest());
37
        $this->assertSame(true, $obj->isTestBool());
38
39
        $this->expectException(GraphQLException::class);
40
        $this->expectExceptionMessage("Expected argument 'string' was not provided in GraphQL input type 'InputObject' used in factory 'TheCodingMachine\GraphQL\Controllers\Fixtures\Types\TestFactory::myFactory()'");
41
        $inputType->resolve([]);
42
    }
43
44
    public function testListResolve(): void
45
    {
46
        $inputType = new ResolvableInputObjectType('InputObject2',
47
            $this->getControllerQueryProviderFactory(),
48
            $this->getTypeMapper(),
49
            new TestFactory(),
50
            'myListFactory',
51
            $this->getHydrator(),
52
            null);
53
54
        $obj = $inputType->resolve(['date' => '2018-12-25', 'stringList' =>
55
            [
56
                'foo',
57
                'bar'
58
            ],
59
            'dateList' => [
60
                '2018-12-25'
61
            ]]);
62
        $this->assertInstanceOf(TestObject2::class, $obj);
63
        $this->assertSame('2018-12-25-foo-bar-1', $obj->getTest2());
64
    }
65
}
66