Passed
Pull Request — master (#380)
by
unknown
02:25
created

SortBlockMutationCreatorTest::runMutation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 2
dl 0
loc 12
rs 10
c 0
b 0
f 0
1
<?php
2
namespace DNADesign\Elemental\Tests\GraphQL;
3
4
use DNADesign\Elemental\GraphQL\SortBlockMutationCreator;
5
use DNADesign\Elemental\Tests\Src\TestElement;
6
use GraphQL\Type\Definition\ResolveInfo;
0 ignored issues
show
Bug introduced by
The type GraphQL\Type\Definition\ResolveInfo 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...
7
use SilverStripe\Dev\SapphireTest;
8
use SilverStripe\Security\Security;
9
10
class SortBlockMutationCreatorTest extends SapphireTest
11
{
12
    protected static $fixture_file = 'SortBlockMutationCreatorTest.yml';
13
14
    protected static $extra_dataobjects = [
15
        TestElement::class
16
    ];
17
18
    protected function setUp()
19
    {
20
        parent::setUp();
21
22
        $this->logInWithPermission('ADMIN');
23
    }
24
25
    public function testSortBlock()
26
    {
27
        $this->runMutation(1, 3);
28
        $this->assertIdsInOrder([2,3,1,4]);
29
30
        $this->runMutation(4, 2);
31
        $this->assertIdsInOrder([2,4,3,1]);
32
33
        $this->runMutation(1, 0);
34
        $this->assertIdsInOrder([1,2,4,3]);
35
36
        $this->runMutation(3, 2);
37
        $this->assertIdsInOrder([1,2,3,4]);
38
    }
39
40
    protected function assertIdsInOrder($ids)
41
    {
42
        $actualIDs = TestElement::get()->sort('Sort')->map()->keys();
43
44
        $this->assertSame($ids, $actualIDs);
45
    }
46
47
    protected function runMutation($id, $afterBlockId)
48
    {
49
        $member = Security::getCurrentUser();
50
51
        $mutation = new SortBlockMutationCreator();
52
        $context = ['currentUser' => $member];
53
        $resolveInfo = new ResolveInfo([]);
54
55
        $mutation->resolve(null, [
56
            'ID' => $id,
57
            'AfterBlockID' => $afterBlockId,
58
        ], $context, $resolveInfo);
59
    }
60
}
61