7
7
8
8
namespace Magento \MagentoCloud \Test \Unit \Config \Validator \Build ;
9
9
10
+ use Composer \Package \PackageInterface ;
10
11
use Magento \MagentoCloud \Config \Validator \Build \ComposerFile ;
11
12
use Magento \MagentoCloud \Config \Validator \ResultFactory ;
12
13
use Magento \MagentoCloud \Filesystem \Driver \File ;
13
14
use Magento \MagentoCloud \Filesystem \FileList ;
14
15
use Magento \MagentoCloud \Package \MagentoVersion ;
16
+ use Magento \MagentoCloud \Package \Manager ;
15
17
use Magento \MagentoCloud \Package \UndefinedPackageException ;
16
18
use PHPUnit \Framework \MockObject \MockObject ;
17
19
use PHPUnit \Framework \TestCase ;
@@ -41,24 +43,34 @@ class ComposerFileTest extends TestCase
41
43
*/
42
44
private $ resultFactoryMock ;
43
45
46
+ /**
47
+ * @var Manager|MockObject
48
+ */
49
+ private $ managerMock ;
50
+
44
51
/**
45
52
* @inheritdoc
46
53
*/
47
- protected function setUp ()
54
+ protected function setUp (): void
48
55
{
49
56
$ this ->fileListMock = $ this ->createMock (FileList::class);
50
57
$ this ->magentoVersionMock = $ this ->createMock (MagentoVersion::class);
51
58
$ this ->resultFactoryMock = $ this ->createMock (ResultFactory::class);
59
+ $ this ->managerMock = $ this ->createMock (Manager::class);
52
60
53
61
$ this ->validator = new ComposerFile (
54
62
$ this ->fileListMock ,
55
63
new File (),
56
64
$ this ->magentoVersionMock ,
57
- $ this ->resultFactoryMock
65
+ $ this ->resultFactoryMock ,
66
+ $ this ->managerMock
58
67
);
59
68
}
60
69
61
- public function testValidateCorrectComposerJson ()
70
+ /**
71
+ * @throws UndefinedPackageException
72
+ */
73
+ public function testValidateCorrectComposerJson (): void
62
74
{
63
75
$ this ->magentoVersionMock ->expects ($ this ->once ())
64
76
->method ('isGreaterOrEqual ' )
@@ -73,7 +85,28 @@ public function testValidateCorrectComposerJson()
73
85
$ this ->validator ->validate ();
74
86
}
75
87
76
- public function testValidateWrongComposerJson ()
88
+ /**
89
+ * @throws UndefinedPackageException
90
+ */
91
+ public function testValidateCorrectLaminasComposerJson (): void
92
+ {
93
+ $ this ->magentoVersionMock ->expects ($ this ->once ())
94
+ ->method ('isGreaterOrEqual ' )
95
+ ->with ('2.3 ' )
96
+ ->willReturn (true );
97
+ $ this ->fileListMock ->expects ($ this ->once ())
98
+ ->method ('getMagentoComposer ' )
99
+ ->willReturn (__DIR__ . '/_files/correct_composer_2.3_2.json ' );
100
+ $ this ->resultFactoryMock ->expects ($ this ->once ())
101
+ ->method ('success ' );
102
+
103
+ $ this ->validator ->validate ();
104
+ }
105
+
106
+ /**
107
+ * @throws UndefinedPackageException
108
+ */
109
+ public function testValidateWrongComposerJson (): void
77
110
{
78
111
$ this ->magentoVersionMock ->expects ($ this ->once ())
79
112
->method ('isGreaterOrEqual ' )
@@ -83,12 +116,25 @@ public function testValidateWrongComposerJson()
83
116
->method ('getMagentoComposer ' )
84
117
->willReturn (__DIR__ . '/_files/wrong_composer_2.3.json ' );
85
118
$ this ->resultFactoryMock ->expects ($ this ->once ())
86
- ->method ('error ' );
119
+ ->method ('error ' )
120
+ ->with (
121
+ 'Required configuration is missed in autoload section of composer.json file. ' ,
122
+ 'Add ("Laminas\Mvc\Controller\: "setup/src/Zend/Mvc/Controller/") to autoload -> psr-4 ' .
123
+ 'section and re-run "composer update" command locally. Then commit new composer.json ' .
124
+ 'and composer.lock files. '
125
+ );
126
+ $ this ->managerMock ->expects ($ this ->once ())
127
+ ->method ('has ' )
128
+ ->with ('laminas/laminas-mvc ' )
129
+ ->willReturn (true );
87
130
88
131
$ this ->validator ->validate ();
89
132
}
90
133
91
- public function testValidateMagentoLover2dot3 ()
134
+ /**
135
+ * @throws UndefinedPackageException
136
+ */
137
+ public function testValidateMagentoLower23 (): void
92
138
{
93
139
$ this ->magentoVersionMock ->expects ($ this ->once ())
94
140
->method ('isGreaterOrEqual ' )
@@ -102,7 +148,10 @@ public function testValidateMagentoLover2dot3()
102
148
$ this ->validator ->validate ();
103
149
}
104
150
105
- public function testValidateComposerFileNotExists ()
151
+ /**
152
+ * @throws UndefinedPackageException
153
+ */
154
+ public function testValidateComposerFileNotExists (): void
106
155
{
107
156
$ this ->magentoVersionMock ->expects ($ this ->once ())
108
157
->method ('isGreaterOrEqual ' )
@@ -118,7 +167,10 @@ public function testValidateComposerFileNotExists()
118
167
$ this ->validator ->validate ();
119
168
}
120
169
121
- public function testValidateCantGetMagentoVersion ()
170
+ /**
171
+ * @throws UndefinedPackageException
172
+ */
173
+ public function testValidateCantGetMagentoVersion (): void
122
174
{
123
175
$ this ->magentoVersionMock ->expects ($ this ->once ())
124
176
->method ('isGreaterOrEqual ' )
0 commit comments