Completed
Pull Request — master (#114)
by Bart
02:14
created

Unit   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 52
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getMock() 0 6 1
1
<?php
2
3
namespace Helper;
4
5
use Craft;
6
use craft\console\Application;
7
use craft\services\Categories;
8
use craft\services\Elements;
9
use craft\services\Globals;
10
use craft\services\Fields;
11
use craft\services\Sites;
12
use craft\i18n\I18n;
13
use Codeception\Module;
14
use Codeception\TestCase;
15
use NerdsAndCompany\Schematic\Schematic;
16
17
class Unit extends Module
18
{
19
    /**
20
     * Mock craft services.
21
     *
22
     * @SuppressWarnings(PHPMD.CamelCaseMethodName)
23
     *
24
     * @param TestCase $test
25
     */
26
    public function _before(TestCase $test)
27
    {
28
        $mockApp = $this->getMock($test, Application::class);
29
        $mockCategoryGroups = $this->getMock($test, Categories::class);
30
        $mockElements = $this->getMock($test, Elements::class);
31
        $mockFields = $this->getMock($test, Fields::class);
32
        $mockGlobals = $this->getMock($test, Globals::class);
33
        $mockSites = $this->getMock($test, Sites::class);
34
        $mockI18n = $this->getMock($test, I18n::class);
35
36
        $mockApp->expects($test->any())
37
            ->method('__get')
38
            ->willReturnMap([
39
                ['categories', $mockCategoryGroups],
40
                ['elements', $mockElements],
41
                ['globals', $mockGlobals],
42
                ['fields', $mockFields],
43
                ['sites', $mockSites],
44
            ]);
45
46
        $mockApp->expects($test->any())
47
            ->method('getI18n')
48
            ->willReturn($mockI18n);
49
50
        Craft::$app = $mockApp;
0 ignored issues
show
Documentation Bug introduced by
It seems like $mockApp of type object<Helper\Mock> is incompatible with the declared type object<craft\web\Applica...ft\console\Application> of property $app.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
51
        Schematic::$force = false;
52
    }
53
54
    /**
55
     * Get a mock object for class.
56
     *
57
     * @param TestCase $test
58
     * @param string   $class
59
     *
60
     * @return Mock
61
     */
62
    private function getMock(TestCase $test, string $class)
63
    {
64
        return $test->getMockBuilder($class)
65
                ->disableOriginalConstructor()
66
                ->getMock();
67
    }
68
}
69