|
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; |
|
|
|
|
|
|
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
|
|
|
|
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..