MutationTest::testInvalidType()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/*
3
 * This file is a part of GraphQL project.
4
 *
5
 * @author Alexandr Viniychuk <[email protected]>
6
 * created: 2:11 PM 5/19/16
7
 */
8
9
namespace Youshido\Tests\Library\Relay;
10
11
12
use Youshido\GraphQL\Relay\RelayMutation;
13
use Youshido\GraphQL\Type\Scalar\IdType;
14
use Youshido\GraphQL\Type\Scalar\IntType;
15
use Youshido\GraphQL\Type\Scalar\StringType;
16
17
class MutationTest extends \PHPUnit_Framework_TestCase
18
{
19
20
    public function testCreation()
21
    {
22
        $mutation = RelayMutation::buildMutation('ship', [
23
            'name' => new StringType()
24
        ],[
25
            'id' => new IdType(),
26
            'name' => new StringType()
27
        ], function($source, $args, $info) {
0 ignored issues
show
Unused Code introduced by
The parameter $source 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 $info 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...
28
29
        });
30
        $this->assertEquals('ship', $mutation->getName());
31
    }
32
33
    /**
34
     * @expectedException \Exception
35
     */
36
    public function testInvalidType()
37
    {
38
        RelayMutation::buildMutation('ship', [
39
            'name' => new StringType()
40
        ], new IntType(), function($source, $args, $info) {});
0 ignored issues
show
Documentation introduced by
new \Youshido\GraphQL\Type\Scalar\IntType() is of type object<Youshido\GraphQL\Type\Scalar\IntType>, but the function expects a object<Youshido\GraphQL\...stractObjectType>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Unused Code introduced by
The parameter $source 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 $info 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...
41
42
    }
43
44
}
45