7
7
8
8
use Magento \Framework \App \Filesystem \DirectoryList ;
9
9
use Magento \Framework \Component \ComponentFile ;
10
+ use Magento \Framework \Component \ComponentRegistrar ;
10
11
use Magento \Framework \Component \DirSearch ;
12
+ use Magento \Framework \Exception \FileSystemException ;
11
13
use Magento \Framework \Filesystem ;
12
14
use Magento \Framework \Filesystem \Directory \ReadInterface ;
13
15
use Magento \TestFramework \Helper \Bootstrap ;
14
16
use Magento \Ui \Config \Reader \DefinitionMap ;
15
- use Magento \Framework \Component \ComponentRegistrar ;
16
17
18
+ /**
19
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
20
+ */
17
21
class ConfigurationTest extends \PHPUnit \Framework \TestCase
18
22
{
19
23
/**
@@ -26,6 +30,11 @@ class ConfigurationTest extends \PHPUnit\Framework\TestCase
26
30
*/
27
31
private $ appDir ;
28
32
33
+ /**
34
+ * @var ReadInterface
35
+ */
36
+ private $ rootDir ;
37
+
29
38
/**
30
39
* @var \DOMDocument
31
40
*/
@@ -66,9 +75,8 @@ public function setUp()
66
75
67
76
/** @var Filesystem $filesystem */
68
77
$ filesystem = $ objectManager ->create (Filesystem::class);
69
- $ this ->appDir = $ this ->isComposerBuilt ()
70
- ? $ filesystem ->getDirectoryRead (DirectoryList::ROOT )
71
- : $ filesystem ->getDirectoryRead (DirectoryList::APP );
78
+ $ this ->appDir = $ filesystem ->getDirectoryRead (DirectoryList::APP );
79
+ $ this ->rootDir = $ filesystem ->getDirectoryRead (DirectoryList::ROOT );
72
80
}
73
81
74
82
/**
@@ -86,7 +94,14 @@ public function testConfiguration()
86
94
/** @var ComponentFile $file */
87
95
foreach ($ uiConfigurationFiles as $ file ) {
88
96
$ this ->currentFile = $ file ;
89
- $ content = $ this ->appDir ->readFile ($ this ->appDir ->getRelativePath ($ file ->getFullPath ()));
97
+ $ fullPath = $ file ->getFullPath ();
98
+ // by default search files in `app` directory but Magento can be installed via composer
99
+ // or some modules can be in `vendor` directory (like bundled extensions)
100
+ try {
101
+ $ content = $ this ->appDir ->readFile ($ this ->appDir ->getRelativePath ($ fullPath ));
102
+ } catch (FileSystemException $ e ) {
103
+ $ content = $ this ->rootDir ->readFile ($ this ->rootDir ->getRelativePath ($ fullPath ));
104
+ }
90
105
$ this ->assertConfigurationSemantic ($ this ->getDom ($ content ), $ result );
91
106
}
92
107
if (!empty ($ result )) {
@@ -251,20 +266,4 @@ private function getDom($content = null)
251
266
}
252
267
return $ this ->dom ;
253
268
}
254
-
255
- /**
256
- * Check magento modules is in app/code.
257
- *
258
- * @return bool
259
- */
260
- private function isComposerBuilt ()
261
- {
262
- $ result = false ;
263
- $ rootJson = json_decode (file_get_contents (BP . '/composer.json ' ), true );
264
- if (preg_match ('/magento\/project-*/ ' , $ rootJson ['name ' ]) == 1 ) {
265
- $ result = true ;
266
- }
267
-
268
- return $ result ;
269
- }
270
269
}
0 commit comments