Completed
Pull Request — master (#63)
by David
02:48
created

FactoryHydratorTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 14
dl 0
loc 23
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A testHydratorNotFound() 0 21 1
1
<?php
2
3
namespace TheCodingMachine\GraphQL\Controllers\Hydrators;
4
5
use GraphQL\Type\Definition\InputObjectType;
6
use PHPUnit\Framework\TestCase;
7
use stdClass;
8
use TheCodingMachine\GraphQL\Controllers\Types\ResolvableInputObjectType;
9
10
class FactoryHydratorTest extends TestCase
11
{
12
    public function testHydratorNotFound()
13
    {
14
        $resolvableInputObjectType = $this->getMockBuilder(ResolvableInputObjectType::class)
15
            ->disableOriginalConstructor()
16
            ->setMethods(['resolve'])
17
            ->getMock();
18
        $resolvableInputObjectType->method('resolve')->willReturn(new stdClass());
0 ignored issues
show
Bug introduced by
The method method() does not exist on PHPUnit\Framework\MockObject\MockObject. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

18
        $resolvableInputObjectType->/** @scrutinizer ignore-call */ 
19
                                    method('resolve')->willReturn(new stdClass());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
19
20
        $badObjectType = new InputObjectType([
21
            'name' => 'foo'
22
        ]);
23
24
        $factoryHydrator = new FactoryHydrator();
25
26
        $this->assertTrue($factoryHydrator->canHydrate([], $resolvableInputObjectType));
27
        $this->assertFalse($factoryHydrator->canHydrate([], $badObjectType));
28
29
        $this->assertEquals(new stdClass(), $factoryHydrator->hydrate([], $resolvableInputObjectType));
30
31
        $this->expectException(CannotHydrateException::class);
32
        $factoryHydrator->hydrate([], $badObjectType);
33
    }
34
}
35