Completed
Pull Request — master (#114)
by Bart
05:40
created

Unit   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getMock() 0 6 1
A _cleanup() 0 4 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 Codeception\Module;
13
use Codeception\TestCase;
14
use NerdsAndCompany\Schematic\Schematic;
15
use Mockery;
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
35
        $mockApp->expects($test->any())
36
            ->method('__get')
37
            ->willReturnMap([
38
                ['categories', $mockCategoryGroups],
39
                ['elements', $mockElements],
40
                ['globals', $mockGlobals],
41
                ['fields', $mockFields],
42
                ['sites', $mockSites],
43
            ]);
44
45
        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...
46
        Schematic::$force = false;
47
    }
48
49
    /**
50
     * Get a mock object for class.
51
     *
52
     * @param TestCase $test
53
     * @param string   $class
54
     *
55
     * @return Mock
56
     */
57
    private function getMock(TestCase $test, string $class)
58
    {
59
        return $test->getMockBuilder($class)
60
                ->disableOriginalConstructor()
61
                ->getMock();
62
    }
63
64
    /**
65
     * Do cleanup.
66
     *
67
     * @SuppressWarnings(PHPMD.CamelCaseMethodName)
68
     */
69
    public function _cleanup()
70
    {
71
        Mockery::close();
72
    }
73
}
74