Completed
Push — master ( 0727d0...a298fc )
by Robbie
11s
created

SortBlockMutationCreatorTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testSortBlock() 0 13 1
A runMutation() 0 12 1
A assertIdsInOrder() 0 5 1
1
<?php
2
3
namespace DNADesign\Elemental\Tests\GraphQL;
4
5
use DNADesign\Elemental\GraphQL\SortBlockMutationCreator;
6
use DNADesign\Elemental\Tests\Src\TestElement;
7
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...
8
use SilverStripe\Dev\SapphireTest;
9
use SilverStripe\Security\Security;
10
11
class SortBlockMutationCreatorTest extends SapphireTest
12
{
13
    protected static $fixture_file = 'SortBlockMutationCreatorTest.yml';
14
15
    protected static $extra_dataobjects = [
16
        TestElement::class,
17
    ];
18
19
    /**
20
     * Reorders blocks by compounding each result into the next test (rather than isolated sorting tests)
21
     */
22
    public function testSortBlock()
23
    {
24
        $this->runMutation(1, 3);
25
        $this->assertIdsInOrder([2, 3, 1, 4]);
26
27
        $this->runMutation(4, 2);
28
        $this->assertIdsInOrder([2, 4, 3, 1]);
29
30
        $this->runMutation(1, 0);
31
        $this->assertIdsInOrder([1, 2, 4, 3]);
32
33
        $this->runMutation(3, 2);
34
        $this->assertIdsInOrder([1, 2, 3, 4]);
35
    }
36
37
    protected function assertIdsInOrder($ids)
38
    {
39
        $actualIDs = TestElement::get()->sort('Sort')->map()->keys();
40
41
        $this->assertSame($ids, $actualIDs);
42
    }
43
44
    protected function runMutation($id, $afterBlockId)
45
    {
46
        $member = Security::getCurrentUser();
47
48
        $mutation = new SortBlockMutationCreator();
49
        $context = ['currentUser' => $member];
50
        $resolveInfo = new ResolveInfo([]);
51
52
        $mutation->resolve(null, [
53
            'ID' => $id,
54
            'AfterBlockID' => $afterBlockId,
55
        ], $context, $resolveInfo);
56
    }
57
}
58