8
8
9
9
use Magento \Developer \Console \Command \GeneratePatchCommand ;
10
10
use Magento \Framework \Component \ComponentRegistrar ;
11
+ use Magento \Framework \Filesystem \Directory \Read ;
11
12
use Magento \Framework \Filesystem \Directory \ReadFactory ;
13
+ use Magento \Framework \Filesystem \Directory \Write ;
12
14
use Magento \Framework \Filesystem \Directory \WriteFactory ;
13
15
use Magento \Framework \Filesystem \DirectoryList ;
16
+ use PHPUnit \Framework \MockObject \MockObject ;
17
+ use PHPUnit \Framework \TestCase ;
14
18
use Symfony \Component \Console \Tester \CommandTester ;
15
19
16
- class GeneratePatchCommandTest extends \ PHPUnit \ Framework \ TestCase
20
+ class GeneratePatchCommandTest extends TestCase
17
21
{
18
22
/**
19
- * @var ComponentRegistrar
23
+ * @var ComponentRegistrar|MockObject
20
24
*/
21
- private $ componentRegistrar ;
25
+ private $ componentRegistrarMock ;
22
26
23
27
/**
24
- * @var DirectoryList
28
+ * @var DirectoryList|MockObject
25
29
*/
26
- private $ directoryList ;
30
+ private $ directoryListMock ;
27
31
28
32
/**
29
- * @var ReadFactory
33
+ * @var ReadFactory|MockObject
30
34
*/
31
- private $ readFactory ;
35
+ private $ readFactoryMock ;
32
36
33
37
/**
34
- * @var WriteFactory
38
+ * @var WriteFactory|MockObject
35
39
*/
36
- private $ writeFactory ;
40
+ private $ writeFactoryMock ;
37
41
38
42
/**
39
- * @var GeneratePatchCommand
43
+ * @var GeneratePatchCommand|MockObject
40
44
*/
41
45
private $ command ;
42
46
43
47
protected function setUp ()
44
48
{
45
- $ this ->componentRegistrar = $ this ->createMock (ComponentRegistrar::class);
46
- $ this ->directoryList = $ this ->createMock (DirectoryList::class);
47
- $ this ->readFactory = $ this ->createMock (ReadFactory::class);
48
- $ this ->writeFactory = $ this ->createMock (WriteFactory::class);
49
+ $ this ->componentRegistrarMock = $ this ->createMock (ComponentRegistrar::class);
50
+ $ this ->directoryListMock = $ this ->createMock (DirectoryList::class);
51
+ $ this ->readFactoryMock = $ this ->createMock (ReadFactory::class);
52
+ $ this ->writeFactoryMock = $ this ->createMock (WriteFactory::class);
49
53
50
54
$ this ->command = new GeneratePatchCommand (
51
- $ this ->componentRegistrar ,
52
- $ this ->directoryList ,
53
- $ this ->readFactory ,
54
- $ this ->writeFactory
55
+ $ this ->componentRegistrarMock ,
56
+ $ this ->directoryListMock ,
57
+ $ this ->readFactoryMock ,
58
+ $ this ->writeFactoryMock
55
59
);
56
60
}
57
61
58
62
public function testExecute ()
59
63
{
60
- $ this ->componentRegistrar ->expects ($ this ->once ())
64
+ $ this ->componentRegistrarMock ->expects ($ this ->once ())
61
65
->method ('getPath ' )
62
66
->with ('module ' , 'Vendor_Module ' )
63
67
->willReturn ('/long/path/to/Vendor/Module ' );
64
68
65
- $ read = $ this ->createMock (\ Magento \ Framework \ Filesystem \ Directory \ Read::class);
69
+ $ read = $ this ->createMock (Read::class);
66
70
$ read ->expects ($ this ->at (0 ))
67
71
->method ('readFile ' )
68
72
->with ('patch_template.php.dist ' )
69
73
->willReturn ('something ' );
70
- $ this ->readFactory ->method ('create ' )->willReturn ($ read );
74
+ $ this ->readFactoryMock ->method ('create ' )->willReturn ($ read );
71
75
72
- $ write = $ this ->createMock (\ Magento \ Framework \ Filesystem \ Directory \ Write::class);
76
+ $ write = $ this ->createMock (Write::class);
73
77
$ write ->expects ($ this ->once ())->method ('writeFile ' );
74
- $ this ->writeFactory ->method ('create ' )->willReturn ($ write );
78
+ $ this ->writeFactoryMock ->method ('create ' )->willReturn ($ write );
75
79
76
- $ this ->directoryList ->expects ($ this ->once ())->method ('getRoot ' )->willReturn ('/some/path ' );
80
+ $ this ->directoryListMock ->expects ($ this ->once ())->method ('getRoot ' )->willReturn ('/some/path ' );
77
81
78
82
$ commandTester = new CommandTester ($ this ->command );
79
83
$ commandTester ->execute (
@@ -85,34 +89,31 @@ public function testExecute()
85
89
$ this ->assertContains ('successfully generated ' , $ commandTester ->getDisplay ());
86
90
}
87
91
88
- /**
89
- * @expectedException \RuntimeException
90
- * @expectedExceptionMessage Not enough arguments
91
- */
92
92
public function testWrongParameter ()
93
93
{
94
+ $ this ->expectExceptionMessage ('Not enough arguments ' );
95
+ $ this ->expectException (\RuntimeException::class);
96
+
94
97
$ commandTester = new CommandTester ($ this ->command );
95
98
$ commandTester ->execute ([]);
96
99
}
97
100
98
- /**
99
- * @expectedException \InvalidArgumentException
100
- * @expectedExceptionMessage Cannot find a registered module with name "Fake_Module"
101
- */
102
101
public function testBadModule ()
103
102
{
104
- $ this ->componentRegistrar ->expects ($ this ->once ())
103
+ $ this ->componentRegistrarMock ->expects ($ this ->once ())
105
104
->method ('getPath ' )
106
105
->with ('module ' , 'Fake_Module ' )
107
106
->willReturn (null );
108
107
108
+ $ this ->expectExceptionMessage ('Cannot find a registered module with name "Fake_Module" ' );
109
+ $ this ->expectException (\InvalidArgumentException::class);
110
+
109
111
$ commandTester = new CommandTester ($ this ->command );
110
112
$ commandTester ->execute (
111
113
[
112
114
GeneratePatchCommand::MODULE_NAME => 'Fake_Module ' ,
113
115
GeneratePatchCommand::INPUT_KEY_PATCH_NAME => 'SomePatch '
114
116
]
115
117
);
116
- $ this ->assertContains ('successfully generated ' , $ commandTester ->getDisplay ());
117
118
}
118
119
}
0 commit comments