Completed
Pull Request — master (#11)
by Willem
06:48 queued 03:20
created

backupInitialConfig()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace IntegerNet\GlobalCustomLayout\Test\Integration;
5
6
use Magento\Framework\App\DeploymentConfig\Reader;
7
use Magento\Framework\App\DeploymentConfig\Writer;
8
use Magento\Framework\Config\File\ConfigFilePool;
9
use Magento\Framework\Exception\FileSystemException;
10
use Magento\Framework\Exception\LocalizedException;
11
use Magento\Framework\Exception\RuntimeException;
12
use Magento\Framework\Module\Status as ModuleStatus;
13
use Magento\Framework\ObjectManagerInterface;
14
use Magento\Framework\View\LayoutInterface;
15
use Magento\TestFramework\Helper\Bootstrap;
0 ignored issues
show
Bug introduced by
The type Magento\TestFramework\Helper\Bootstrap 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...
16
use Magento\TestFramework\TestCase\AbstractController;
0 ignored issues
show
Bug introduced by
The type Magento\TestFramework\TestCase\AbstractController 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...
17
18
/**
19
 * @magentoAppIsolation enabled
20
 * @magentoAppArea frontend
21
 * @magentoComponentsDir ../../../../vendor/integer-net/magento2-global-custom-layout/tests/Integration/_files/app/code/IntegerNet
22
 */
23
abstract class AbstractFrontendControllerTest extends AbstractController
24
{
25
    /** @var int */
26
    const STORE_ID = 0;
27
28
    /** @var string */
29
    const GLOBAL_TEST_FILE = 'globalfile';
30
31
    /** @var string */
32
    const DEFAULT_TEST_FILE = 'defaultfile';
33
34
    /** @var int */
35
    const GLOBAL_IDENTIFIER = 0;
36
37
    /** @var ObjectManagerInterface */
38
    protected $objectManager;
39
40
    /** @var LayoutInterface */
41
    protected $layout;
42
43
    /** @var ModuleStatus */
44
    protected $moduleStatus;
45
46
    /** @var Reader */
47
    protected $configReader;
48
49
    /** @var Writer */
50
    protected $configWriter;
51
52
    /** @var array */
53
    protected $initialConfig;
54
55
    /**
56
     * @inheritdoc
57
     * @throws LocalizedException
58
     * @magentoComponentsDir ../../../../vendor/integer-net/magento2-global-custom-layout/tests/Integration/_files/app/code/IntegerNet
59
     */
60
    protected function setUp(): void
61
    {
62
        Bootstrap::getInstance()->reinitialize();
63
        $this->objectManager = Bootstrap::getObjectManager();
64
        $this->layout = $this->objectManager->get(LayoutInterface::class);
65
        $this->configWriter = $this->objectManager->get(Writer::class);
66
67
        $this->backupInitialConfig();
68
        $this->enableTestModuleInConfig();
69
70
        parent::setUp();
71
    }
72
73
    protected function enableTestModuleInConfig()
74
    {
75
        $this->moduleStatus = $this->objectManager->create(ModuleStatus::class);
76
        $this->moduleStatus->setIsEnabled(true, ['IntegerNet_GlobalCustomLayoutTest']);
77
    }
78
79
    /**
80
     * @throws FileSystemException
81
     */
82
    protected function tearDown()
83
    {
84
        $this->restoreInitialConfig();
85
    }
86
87
    /**
88
     * @throws FileSystemException
89
     */
90
    protected function restoreInitialConfig(): void
91
    {
92
        $this->configWriter->saveConfig(
93
            [ConfigFilePool::APP_CONFIG => ['modules' => $this->initialConfig['modules']]],
94
            true
95
        );
96
    }
97
98
    /**
99
     * @throws FileSystemException
100
     * @throws RuntimeException
101
     */
102
    protected function backupInitialConfig(): void
103
    {
104
        if (!$this->initialConfig) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->initialConfig of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
105
            $this->configReader = $this->objectManager->get(Reader::class);
106
            $this->initialConfig = $this->configReader->load();
107
        }
108
    }
109
}
110