5
5
*/
6
6
namespace Magento \MagentoCloud \Test \Unit \Process \Build ;
7
7
8
- use Magento \MagentoCloud \Package \MagentoVersion ;
8
+ use Magento \MagentoCloud \Filesystem \DirectoryList ;
9
+ use Magento \MagentoCloud \Filesystem \Driver \File ;
9
10
use Magento \MagentoCloud \Process \Build \ApplyPatches ;
10
11
use Magento \MagentoCloud \Shell \ShellInterface ;
11
12
use PHPUnit \Framework \TestCase ;
@@ -33,9 +34,14 @@ class ApplyPatchesTest extends TestCase
33
34
private $ shellMock ;
34
35
35
36
/**
36
- * @var MagentoVersion |Mock
37
+ * @var File |Mock
37
38
*/
38
- private $ magentoVersionMock ;
39
+ private $ fileMock ;
40
+
41
+ /**
42
+ * @var DirectoryList|Mock
43
+ */
44
+ private $ directoryListMock ;
39
45
40
46
/**
41
47
* @inheritdoc
@@ -46,48 +52,53 @@ protected function setUp()
46
52
->getMockForAbstractClass ();
47
53
$ this ->shellMock = $ this ->getMockBuilder (ShellInterface::class)
48
54
->getMockForAbstractClass ();
49
- $ this ->magentoVersionMock = $ this ->getMockBuilder (MagentoVersion ::class)
55
+ $ this ->fileMock = $ this ->getMockBuilder (File ::class)
50
56
->disableOriginalConstructor ()
51
57
->getMock ();
58
+ $ this ->directoryListMock = $ this ->createMock (DirectoryList::class);
52
59
53
60
$ this ->process = new ApplyPatches (
54
61
$ this ->shellMock ,
55
62
$ this ->loggerMock ,
56
- $ this ->magentoVersionMock
63
+ $ this ->fileMock ,
64
+ $ this ->directoryListMock
57
65
);
58
66
59
67
parent ::setUp ();
60
68
}
61
69
62
70
public function testExecute ()
63
71
{
72
+ $ this ->directoryListMock ->method ('getMagentoRoot ' )
73
+ ->willReturn ('magento_root ' );
64
74
$ this ->loggerMock ->expects ($ this ->once ())
65
75
->method ('info ' )
66
76
->with ('Applying patches. ' );
67
77
$ this ->shellMock ->expects ($ this ->once ())
68
78
->method ('execute ' )
69
- ->with ('php vendor/bin/m2-apply-patches ' );
70
- $ this ->magentoVersionMock ->method ('isGreaterOrEqual ' )
71
- ->with ('2.2 ' )
79
+ ->with ('php magento_root/ vendor/bin/m2-apply-patches ' );
80
+ $ this ->fileMock ->method ('isExists ' )
81
+ ->with ('magento_root/vendor/bin/m2-apply-patches ' )
72
82
->willReturn (true );
73
83
74
84
$ this ->process ->execute ();
75
85
}
76
86
77
87
public function testExecuteWithoutPatches ()
78
88
{
89
+ $ this ->directoryListMock ->method ('getMagentoRoot ' )
90
+ ->willReturn ('magento_root ' );
79
91
$ this ->loggerMock ->expects ($ this ->once ())
80
92
->method ('info ' )
81
93
->with ('Applying patches. ' );
82
- $ this ->magentoVersionMock ->method ('isGreaterOrEqual ' )
83
- ->with ('2.2 ' )
84
- ->willReturn (true );
94
+ $ this ->fileMock ->method ('isExists ' )
95
+ ->with ('magento_root/vendor/bin/m2-apply-patches ' )
96
+ ->willReturn (false );
85
97
$ this ->loggerMock ->expects ($ this ->once ())
86
98
->method ('warning ' )
87
- ->with ('Patching was failed. Skipping. ' );
88
- $ this ->shellMock ->expects ($ this ->once ())
89
- ->method ('execute ' )
90
- ->willThrowException (new \Exception ('Patching failed. ' ));
99
+ ->with ('Package with patches was not found. ' );
100
+ $ this ->shellMock ->expects ($ this ->never ())
101
+ ->method ('execute ' );
91
102
92
103
$ this ->process ->execute ();
93
104
}
0 commit comments