Completed
Pull Request — develop (#167)
by Robbie
04:11
created

testShouldReturnModuleNameForExistingModule()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 7
rs 9.4286
c 1
b 0
f 1
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
namespace N98\Magento\Command\System\Setup;
4
5
use N98\Magento\Command\PHPUnit\TestCase;
6
7
/**
8
 * @runTestsInSeparateProcesses
9
 */
10
class AbstractSetupCommandTest extends TestCase
11
{
12
    /**
13
     * Test the getMagentoModuleName() method returns the actual module name when it exists
14
     * @param  string $moduleName
15
     * @dataProvider validModuleNameProvider
16
     */
17
    public function testShouldReturnModuleNameForExistingModule($moduleName)
18
    {
19
        $subjectMock = $this->getSubjectMock();
20
21
        $result = $subjectMock->getMagentoModuleName($moduleName);
22
        $this->assertStringStartsWith('Magento', $result);
23
    }
24
25
    /**
26
     * Provide some inconsistently cased module names
27
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be string[][]?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
28
     */
29
    public function validModuleNameProvider()
30
    {
31
        return array(
32
            array('magento_catalog'),
33
            array('magento_customer'),
34
            array('Magento_Catalog'),
35
            array('MaGeNtO_cUstOmeR')
36
        );
37
    }
38
39
    /**
40
     * Ensure that an exception is thrown when a module doesn't exist
41
     * @expectedException InvalidArgumentException
42
     */
43
    public function testShouldThrowExceptionWhenModuleDoesntExist()
44
    {
45
        $this->getSubjectMock()->getMagentoModuleName('Some_Module_That_Will_Never_Exist');
46
    }
47
48
    /**
49
     * Return a mocked test subject
50
     * @return Mock_ChangeVersionCommand
51
     */
52
    protected function getSubjectMock()
53
    {
54
        $moduleListMock = $this->getMockBuilder('\Magento\Framework\Module\ModuleList')
55
            ->setMethods(array('getAll'))
56
            ->getMock();
57
58
        $moduleListMock
59
            ->expects($this->once())
60
            ->method('getAll')
61
            ->will($this->returnValue(array('Magento_Catalog' => 'info', 'Magento_Customer' => 'info')));
62
63
        // Test one its children since the framework expects to be testing commands
64
        $subjectMock = $this->getMockBuilder('\N98\Magento\Command\System\Setup\ChangeVersionCommand')
65
            ->setMethods(array('getMagentoModuleList'))
66
            ->getMock();
67
68
        $subjectMock
69
            ->expects($this->once())
70
            ->method('getMagentoModuleList')
71
            ->will($this->returnValue($moduleListMock));
72
73
        return $subjectMock;
74
    }
75
}
76