detectMagentoInModmanInfrastructure()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 28
rs 8.8571
cc 1
eloc 14
nc 1
nop 0
1
<?php
2
3
namespace N98\Util\Console\Helper;
4
5
use Symfony\Component\Console\Tester\CommandTester;
6
use N98\Magento\Command\PHPUnit\TestCase;
7
use org\bovigo\vfs\vfsStream;
8
9
10
class MagentoHelperTest extends TestCase
11
{
12
    /**
13
     * @return MagentoHelper
14
     */
15
    protected function getHelper()
16
    {
17
        $inputMock = $this->getMock('Symfony\Component\Console\Input\InputInterface');
18
        $outputMock = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
19
20
        return new MagentoHelper($inputMock, $outputMock);
21
    }
22
23
    /**
24
     * @test
25
     */
26
    public function testHelperInstance()
27
    {
28
        $this->assertInstanceOf('\N98\Util\Console\Helper\MagentoHelper', $this->getHelper());
29
    }
30
31
    /**
32
     * @test
33
     */
34
    public function detectMagentoInStandardFolder()
35
    {
36
        vfsStream::setup('root');
37
        vfsStream::create(
38
            array(
39
                'app' => array(
40
                    'Mage.php' => ''
41
                )
42
            )
43
        );
44
45
        $helper = $this->getHelper();
46
        $helper->detect(vfsStream::url('root'), array());
47
48
        $this->assertEquals(vfsStream::url('root'), $helper->getRootFolder());
49
        $this->assertEquals(\N98\Magento\Application::MAGENTO_MAJOR_VERSION_1, $helper->getMajorVersion());
50
    }
51
52
    /**
53
     * @test
54
     */
55 View Code Duplication
    public function detectMagentoInHtdocsSubfolder()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
    {
57
        vfsStream::setup('root');
58
        vfsStream::create(
59
            array(
60
                'htdocs' => array(
61
                    'app' => array(
62
                        'Mage.php' => ''
63
                    )
64
                )
65
            )
66
        );
67
68
        $helper = $this->getHelper();
69
70
        // vfs cannot resolve relative path so we do 'root/htdocs' etc.
71
        $helper->detect(
72
            vfsStream::url('root'),
73
            array(
74
                vfsStream::url('root/www'),
75
                vfsStream::url('root/public'),
76
                vfsStream::url('root/htdocs'),
77
            )
78
        );
79
80
        $this->assertEquals(vfsStream::url('root/htdocs'), $helper->getRootFolder());
81
        $this->assertEquals(\N98\Magento\Application::MAGENTO_MAJOR_VERSION_1, $helper->getMajorVersion());
82
    }
83
84
    /**
85
     * @test
86
     */
87
    public function detectMagentoFailed()
88
    {
89
        vfsStream::setup('root');
90
        vfsStream::create(
91
            array(
92
                'htdocs' => array()
93
            )
94
        );
95
96
        $helper = $this->getHelper();
97
98
        // vfs cannot resolve relative path so we do 'root/htdocs' etc.
99
        $helper->detect(
100
            vfsStream::url('root')
101
        );
102
103
        $this->assertNull($helper->getRootFolder());
104
    }
105
106
    /**
107
     * @test
108
     */
109
    public function detectMagentoInModmanInfrastructure()
110
    {
111
        vfsStream::setup('root');
112
        vfsStream::create(
113
            array(
114
                '.basedir' => 'root/htdocs/magento_root',
115
                'htdocs' => array(
116
                    'magento_root' => array(
117
                        'app' => array(
118
                            'Mage.php' => ''
119
                        )
120
                    )
121
                )
122
            )
123
        );
124
125
        $helper = $this->getHelper();
126
127
        // vfs cannot resolve relative path so we do 'root/htdocs' etc.
128
        $helper->detect(
129
            vfsStream::url('root')
130
        );
131
132
        // Verify if this could be checked with more elegance
133
        $this->assertEquals(vfsStream::url('root/../root/htdocs/magento_root'), $helper->getRootFolder());
134
135
        $this->assertEquals(\N98\Magento\Application::MAGENTO_MAJOR_VERSION_1, $helper->getMajorVersion());
136
    }
137
138
    /**
139
     * @test
140
     */
141 View Code Duplication
    public function detectMagento2InHtdocsSubfolder()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
142
    {
143
        vfsStream::setup('root');
144
        vfsStream::create(
145
            array(
146
                'htdocs' => array(
147
                    'app' => array(
148
                        'autoload.php'  => '',
149
                        'bootstrap.php' => '',
150
                    )
151
                )
152
            )
153
        );
154
155
        $helper = $this->getHelper();
156
157
        // vfs cannot resolve relative path so we do 'root/htdocs' etc.
158
        $helper->detect(
159
            vfsStream::url('root'),
160
            array(
161
                vfsStream::url('root/www'),
162
                vfsStream::url('root/public'),
163
                vfsStream::url('root/htdocs'),
164
            )
165
        );
166
167
        $this->assertEquals(vfsStream::url('root/htdocs'), $helper->getRootFolder());
168
        $this->assertEquals(\N98\Magento\Application::MAGENTO_MAJOR_VERSION_2, $helper->getMajorVersion());
169
    }
170
}
171