Completed
Pull Request — master (#11)
by Willem
07:13 queued 04:01
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
        $this->objectManager = Bootstrap::getObjectManager();
63
        $this->layout = $this->objectManager->get(LayoutInterface::class);
64
        $this->configWriter = $this->objectManager->get(Writer::class);
65
66
        $this->backupInitialConfig();
67
        $this->enableTestModuleInConfig();
68
69
        parent::setUp();
70
    }
71
72
    protected function enableTestModuleInConfig()
73
    {
74
        $this->moduleStatus = $this->objectManager->create(ModuleStatus::class);
75
        $this->moduleStatus->setIsEnabled(true, ['IntegerNet_GlobalCustomLayoutTest']);
76
77
        $this->objectManager->removeSharedInstance(\Magento\Framework\Module\Manager::class);
0 ignored issues
show
Bug introduced by
The method removeSharedInstance() does not exist on Magento\Framework\ObjectManagerInterface. ( Ignorable by Annotation )

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

77
        $this->objectManager->/** @scrutinizer ignore-call */ 
78
                              removeSharedInstance(\Magento\Framework\Module\Manager::class);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
78
        $this->objectManager->removeSharedInstance(\Magento\Framework\Module\ModuleList::class);
79
        $this->objectManager->removeSharedInstance(\Magento\Framework\View\Model\Layout\Merge::class);
80
    }
81
82
    /**
83
     * @throws FileSystemException
84
     */
85
    protected function tearDown()
86
    {
87
        $this->restoreInitialConfig();
88
    }
89
90
    /**
91
     * @throws FileSystemException
92
     */
93
    protected function restoreInitialConfig(): void
94
    {
95
        $this->configWriter->saveConfig(
96
            [ConfigFilePool::APP_CONFIG => ['modules' => $this->initialConfig['modules']]],
97
            true
98
        );
99
    }
100
101
    /**
102
     * @throws FileSystemException
103
     * @throws RuntimeException
104
     */
105
    protected function backupInitialConfig(): void
106
    {
107
        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...
108
            $this->configReader = $this->objectManager->get(Reader::class);
109
            $this->initialConfig = $this->configReader->load();
110
        }
111
    }
112
}
113