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

testShouldThrowExceptionWhenModuleDoesntExist()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 1
cc 1
eloc 2
nc 1
nop 0
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
     * Mocked command
14
     * @var Mock_ChangeVersionCommand
15
     */
16
    protected $command;
17
18
    /**
19
     * Set up the mocked command for testing
20
     */
21
    public function setup()
22
    {
23
        $moduleListMock = $this->getMockBuilder('Magento\Framework\Module\ModuleList')
24
            ->setMethods(array('getAll'))
25
            ->getMock();
26
27
        $moduleListMock
28
            ->expects($this->once())
29
            ->method('getAll')
30
            ->will($this->returnValue(array('Magento_Catalog' => 'info', 'Magento_Customer' => 'info')));
31
32
        // Test one its children since the framework expects to be testing commands
33
        $this->command = $this->getMockBuilder('N98\Magento\Command\System\Setup\ChangeVersionCommand')
34
            ->setMethods(array('getMagentoModuleList'))
35
            ->getMock();
36
37
        $this->command
38
            ->expects($this->once())
39
            ->method('getMagentoModuleList')
40
            ->will($this->returnValue($moduleListMock));
41
    }
42
43
    /**
44
     * Test the getMagentoModuleName() method returns the actual module name when it exists
45
     * @param string $moduleName
46
     *
47
     * @dataProvider validModuleNameProvider
48
     */
49
    public function testShouldReturnModuleNameForExistingModule($moduleName)
50
    {
51
        $result = $this->command->getMagentoModuleName($moduleName);
52
        $this->assertStringStartsWith('Magento', $result);
53
    }
54
55
    /**
56
     * Provide some inconsistently cased module names
57
     * @return array
58
     */
59
    public function validModuleNameProvider()
60
    {
61
        return array(
62
            array('magento_catalog'),
63
            array('magento_customer'),
64
            array('Magento_Catalog'),
65
            array('MaGeNtO_cUstOmeR')
66
        );
67
    }
68
69
    /**
70
     * Ensure that an exception is thrown when a module doesn't exist
71
     * @expectedException InvalidArgumentException
72
     */
73
    public function testShouldThrowExceptionWhenModuleDoesntExist()
74
    {
75
        $this->command->getMagentoModuleName('Some_Module_That_Will_Never_Exist');
76
    }
77
}
78