Completed
Pull Request — develop (#167)
by Robbie
05:20
created

AbstractSetupCommandTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 69
rs 10
c 4
b 0
f 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 22 1
A testShouldReturnModuleNameForExistingModule() 0 5 1
A validModuleNameProvider() 0 9 1
A testShouldThrowExceptionWhenModuleDoesntExist() 0 4 1
1
<?php
2
3
namespace N98\Magento\Command\System\Setup;
4
5
use N98\Magento\Command\PHPUnit\TestCase;
6
7
class AbstractSetupCommandTest extends TestCase
8
{
9
    /**
10
     * Mocked command
11
     * @var Mock_AbstractSetupCommand
12
     */
13
    protected $command;
14
15
    /**
16
     * Set up the mocked command for testing
17
     */
18
    public function setUp()
19
    {
20
        $moduleListMock = $this->getMockBuilder('Magento\Framework\Module\ModuleList')
21
            ->setMethods(array('getAll'))
22
            ->getMock();
23
24
        $moduleListMock
25
            ->expects($this->once())
26
            ->method('getAll')
27
            ->will($this->returnValue(array('Magento_Catalog' => 'info', 'Magento_Customer' => 'info')));
28
29
        // Test one its children since the framework expects to be testing commands
30
        $this->command = $this->getMockBuilder('N98\Magento\Command\System\Setup\AbstractSetupCommand')
31
            ->disableOriginalConstructor()
32
            ->setMethods(array('getMagentoModuleList'))
33
            ->getMockForAbstractClass();
34
35
        $this->command
36
            ->expects($this->once())
37
            ->method('getMagentoModuleList')
38
            ->will($this->returnValue($moduleListMock));
39
    }
40
41
    /**
42
     * Test the getMagentoModuleName() method returns the actual module name when it exists
43
     * @param string $moduleName
44
     *
45
     * @dataProvider validModuleNameProvider
46
     */
47
    public function testShouldReturnModuleNameForExistingModule($moduleName)
48
    {
49
        $result = $this->command->getMagentoModuleName($moduleName);
50
        $this->assertStringStartsWith('Magento', $result);
51
    }
52
53
    /**
54
     * Provide some inconsistently cased module names
55
     * @return array
56
     */
57
    public function validModuleNameProvider()
58
    {
59
        return array(
60
            array('magento_catalog'),
61
            array('magento_customer'),
62
            array('Magento_Catalog'),
63
            array('MaGeNtO_cUstOmeR')
64
        );
65
    }
66
67
    /**
68
     * Ensure that an exception is thrown when a module doesn't exist
69
     * @expectedException InvalidArgumentException
70
     */
71
    public function testShouldThrowExceptionWhenModuleDoesntExist()
72
    {
73
        $this->command->getMagentoModuleName('Some_Module_That_Will_Never_Exist');
74
    }
75
}
76