SortBlockMutationCreatorTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 53
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A assertIdsInOrder() 0 5 1
A runMutation() 0 12 1
A setUp() 0 5 2
A testSortBlock() 0 13 1
1
<?php
2
3
namespace DNADesign\Elemental\Tests\Legacy\GraphQL;
4
5
use DNADesign\Elemental\GraphQL\SortBlockMutationCreator;
6
use DNADesign\Elemental\Tests\Src\TestElement;
7
use SilverStripe\GraphQL\Tests\Fake\FakeResolveInfo;
0 ignored issues
show
Bug introduced by
The type SilverStripe\GraphQL\Tests\Fake\FakeResolveInfo 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\GraphQL\Schema\Schema;
0 ignored issues
show
Bug introduced by
The type SilverStripe\GraphQL\Schema\Schema 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...
10
use SilverStripe\Security\Security;
11
12
class SortBlockMutationCreatorTest extends SapphireTest
13
{
14
    protected static $fixture_file = 'SortBlockMutationCreatorTest.yml';
15
16
    protected static $extra_dataobjects = [
17
        TestElement::class,
18
    ];
19
20
    protected function setUp(): void
21
    {
22
        parent::setUp();
23
        if (class_exists(Schema::class)) {
24
            $this->markTestSkipped('Skipped GraphQL 3 test ' . __CLASS__);
25
        }
26
    }
27
28
    /**
29
     * Reorders blocks by compounding each result into the next test (rather than isolated sorting tests)
30
     */
31
    public function testSortBlock()
32
    {
33
        $this->runMutation(1, 3);
34
        $this->assertIdsInOrder([2, 3, 1, 4]);
35
36
        $this->runMutation(4, 2);
37
        $this->assertIdsInOrder([2, 4, 3, 1]);
38
39
        $this->runMutation(1, 0);
40
        $this->assertIdsInOrder([1, 2, 4, 3]);
41
42
        $this->runMutation(3, 2);
43
        $this->assertIdsInOrder([1, 2, 3, 4]);
44
    }
45
46
    protected function assertIdsInOrder($ids)
47
    {
48
        $actualIDs = TestElement::get()->sort('Sort')->map()->keys();
49
50
        $this->assertSame($ids, $actualIDs);
51
    }
52
53
    protected function runMutation($id, $afterBlockId)
54
    {
55
        $member = Security::getCurrentUser();
56
57
        $mutation = new SortBlockMutationCreator();
0 ignored issues
show
Deprecated Code introduced by
The class DNADesign\Elemental\Grap...ortBlockMutationCreator has been deprecated: 4.8..5.0 Use silverstripe/graphql:^4 functionality. ( Ignorable by Annotation )

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

57
        $mutation = /** @scrutinizer ignore-deprecated */ new SortBlockMutationCreator();
Loading history...
58
        $context = ['currentUser' => $member];
59
        $resolveInfo = new FakeResolveInfo([]);
60
61
        $mutation->resolve(null, [
62
            'id' => $id,
63
            'afterBlockID' => $afterBlockId,
64
        ], $context, $resolveInfo);
65
    }
66
}
67