Completed
Pull Request — develop (#166)
by Robbie
04:29
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
class AbstractSetupCommandTest extends TestCase
8
{
9
    /**
10
     * Test the getModuleName() method returns the actual module name when it exists
11
     * @param  string $moduleName
12
     * @dataProvider validModuleNameProvider
13
     */
14
    public function testShouldReturnModuleNameForExistingModule($moduleName)
15
    {
16
        $subjectMock = $this->getSubjectMock();
17
18
        $result = $subjectMock->getModuleName($moduleName);
19
        $this->assertStringStartsWith('Magento', $result);
20
    }
21
22
    /**
23
     * Provide some inconsistently cased module names
24
     * @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...
25
     */
26
    public function validModuleNameProvider()
27
    {
28
        return array(
29
            array('magento_catalog'),
30
            array('magento_customer'),
31
            array('Magento_Catalog'),
32
            array('MaGeNtO_cUstOmeR')
33
        );
34
    }
35
36
    /**
37
     * Ensure that an exception is thrown when a module doesn't exist
38
     * @expectedException InvalidArgumentException
39
     */
40
    public function testShouldThrowExceptionWhenModuleDoesntExist()
41
    {
42
        $this->getSubjectMock()->getModuleName('Some_Module_That_Will_Never_Exist');
43
    }
44
45
    /**
46
     * Return a mocked test subject
47
     * @return Mock_ChangeVersionCommand
48
     */
49
    protected function getSubjectMock()
50
    {
51
        $moduleListMock = $this->getMockBuilder('\Magento\Framework\Module\ModuleList')
52
            ->setMethods(array('getAll'))
53
            ->getMock();
54
55
        $moduleListMock
56
            ->expects($this->once())
57
            ->method('getAll')
58
            ->will($this->returnValue(array('Magento_Catalog' => 'info', 'Magento_Customer' => 'info')));
59
60
        // Test one its children since the framework expects to be testing commands
61
        $subjectMock = $this->getMockBuilder('\N98\Magento\Command\System\Setup\ChangeVersionCommand')
62
            ->setMethods(array('getModuleList'))
63
            ->getMock();
64
65
        $subjectMock
66
            ->expects($this->once())
67
            ->method('getModuleList')
68
            ->will($this->returnValue($moduleListMock));
69
70
        return $subjectMock;
71
    }
72
}
73