9
9
use Magento \MagentoCloud \Config \GlobalSection ;
10
10
use Magento \MagentoCloud \Filesystem \DirectoryList ;
11
11
use Magento \MagentoCloud \Filesystem \Driver \File ;
12
+ use Magento \MagentoCloud \Filesystem \FileList ;
12
13
use Magento \MagentoCloud \Patch \Manager ;
13
14
use Magento \MagentoCloud \Shell \ProcessInterface ;
15
+ use Magento \MagentoCloud \Shell \ShellException ;
14
16
use Magento \MagentoCloud \Shell \ShellInterface ;
15
17
use PHPUnit \Framework \MockObject \MockObject ;
16
18
use PHPUnit \Framework \TestCase ;
@@ -56,6 +58,11 @@ class ManagerTest extends TestCase
56
58
*/
57
59
private $ globalSectionMock ;
58
60
61
+ /**
62
+ * @var FileList|MockObject
63
+ */
64
+ private $ fileListMock ;
65
+
59
66
/**
60
67
* @inheritdoc
61
68
*/
@@ -67,82 +74,100 @@ protected function setUp()
67
74
$ this ->fileMock = $ this ->createMock (File::class);
68
75
$ this ->directoryListMock = $ this ->createMock (DirectoryList::class);
69
76
$ this ->globalSectionMock = $ this ->createMock (GlobalSection::class);
77
+ $ this ->fileListMock = $ this ->createMock (FileList::class);
70
78
71
- $ this ->directoryListMock ->method ('getMagentoRoot ' )
79
+ $ this ->directoryListMock ->expects ($ this ->once ())
80
+ ->method ('getMagentoRoot ' )
72
81
->willReturn ('magento_root ' );
82
+ $ this ->fileListMock ->expects ($ this ->once ())
83
+ ->method ('getFrontStaticDist ' )
84
+ ->willReturn ('dist/pub/front-static.php ' );
85
+ $ this ->fileMock ->expects ($ this ->once ())
86
+ ->method ('copy ' )
87
+ ->with (
88
+ 'dist/pub/front-static.php ' ,
89
+ 'magento_root/pub/front-static.php '
90
+ );
91
+ $ this ->loggerMock ->expects ($ this ->once ())
92
+ ->method ('info ' )
93
+ ->with ('File "front-static.php" was copied ' );
73
94
74
95
$ this ->manager = new Manager (
75
96
$ this ->loggerMock ,
76
97
$ this ->shellMock ,
77
98
$ this ->fileMock ,
78
99
$ this ->directoryListMock ,
79
- $ this ->globalSectionMock
100
+ $ this ->globalSectionMock ,
101
+ $ this ->fileListMock
80
102
);
81
103
}
82
104
83
105
public function testApply ()
84
106
{
85
- $ this ->fileMock ->expects ($ this ->once ())
86
- ->method ('isExists ' )
87
- ->with ('magento_root/pub/static.php ' )
88
- ->willReturn (true );
89
- $ this ->fileMock ->expects ($ this ->once ())
90
- ->method ('copy ' )
91
- ->with (
92
- 'magento_root/pub/static.php ' ,
93
- 'magento_root/pub/front-static.php '
94
- );
95
107
$ this ->globalSectionMock ->expects ($ this ->once ())
96
108
->method ('get ' )
97
109
->with (GlobalSection::VAR_DEPLOYED_MAGENTO_VERSION_FROM_GIT )
98
110
->willReturn (false );
99
-
111
+ $ this ->loggerMock ->expects ($ this ->exactly (2 ))
112
+ ->method ('notice ' )
113
+ ->withConsecutive (
114
+ ['Applying patches ' ],
115
+ ['End of applying patches ' ]
116
+ );
100
117
$ processMock = $ this ->getMockForAbstractClass (ProcessInterface::class);
101
118
$ processMock ->method ('getOutput ' )
102
119
->willReturn ('Some patch applied ' );
103
-
104
120
$ this ->shellMock ->expects ($ this ->once ())
105
121
->method ('execute ' )
106
122
->with ('php ./vendor/bin/ece-patches apply ' )
107
123
->willReturn ($ processMock );
108
- $ this ->loggerMock ->method ('info ' )
109
- ->withConsecutive (
110
- ['File static.php was copied ' ]
111
- );
124
+
125
+ $ this ->manager ->apply ();
126
+ }
127
+
128
+ public function testApplyDeployedFromGitAndNoCopy ()
129
+ {
130
+ $ this ->globalSectionMock ->expects ($ this ->once ())
131
+ ->method ('get ' )
132
+ ->with (GlobalSection::VAR_DEPLOYED_MAGENTO_VERSION_FROM_GIT )
133
+ ->willReturn (true );
112
134
$ this ->loggerMock ->method ('notice ' )
113
135
->withConsecutive (
114
136
['Applying patches ' ],
115
137
['End of applying patches ' ]
116
138
);
139
+ $ processMock = $ this ->getMockForAbstractClass (ProcessInterface::class);
140
+ $ processMock ->method ('getOutput ' )
141
+ ->willReturn ('Some patch applied ' );
142
+ $ this ->shellMock ->expects ($ this ->once ())
143
+ ->method ('execute ' )
144
+ ->with ('php ./vendor/bin/ece-patches apply --git-installation 1 ' )
145
+ ->willReturn ($ processMock );
117
146
118
147
$ this ->manager ->apply ();
119
148
}
120
149
121
- public function testApplyDeployedFromGitAndNoCopy ()
150
+ public function testApplyWithException ()
122
151
{
123
- $ this ->fileMock ->expects ($ this ->once ())
124
- ->method ('isExists ' )
125
- ->with ('magento_root/pub/static.php ' )
126
- ->willReturn (false );
127
152
$ this ->globalSectionMock ->expects ($ this ->once ())
128
153
->method ('get ' )
129
154
->with (GlobalSection::VAR_DEPLOYED_MAGENTO_VERSION_FROM_GIT )
130
- ->willReturn (true );
131
-
155
+ ->willReturn (false );
156
+ $ this ->loggerMock ->expects ($ this ->once ())
157
+ ->method ('notice ' )
158
+ ->with ('Applying patches ' );
132
159
$ processMock = $ this ->getMockForAbstractClass (ProcessInterface::class);
133
160
$ processMock ->method ('getOutput ' )
134
161
->willReturn ('Some patch applied ' );
135
-
162
+ $ exception = new ShellException ( ' Some Error ' );
136
163
$ this ->shellMock ->expects ($ this ->once ())
137
164
->method ('execute ' )
138
- ->with ('php ./vendor/bin/ece-patches apply --git-installation 1 ' )
139
- ->willReturn ($ processMock );
140
- $ this ->loggerMock ->method ('notice ' )
141
- ->withConsecutive (
142
- ['File static.php was not found ' ],
143
- ['Applying patches ' ],
144
- ['End of applying patches ' ]
145
- );
165
+ ->with ('php ./vendor/bin/ece-patches apply ' )
166
+ ->willThrowException ($ exception );
167
+ $ this ->loggerMock ->expects ($ this ->once ())
168
+ ->method ('error ' )
169
+ ->with ('Some Error ' );
170
+ $ this ->expectExceptionObject ($ exception );
146
171
147
172
$ this ->manager ->apply ();
148
173
}
0 commit comments