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

FactoryHydratorTest::testHydratorNotFound()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 21
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 0
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