4
4
* See COPYING.txt for license details.
5
5
*/
6
6
7
- /**
8
- * Implementation of the @magentoDataFixture DocBlock annotation
9
- */
10
7
namespace Magento \TestFramework \Annotation ;
11
8
9
+ use Magento \Framework \Component \ComponentRegistrar ;
12
10
use PHPUnit \Framework \Exception ;
13
11
12
+ /**
13
+ * Implementation of the @magentoDataFixture DocBlock annotation.
14
+ */
14
15
class DataFixture
15
16
{
16
17
/**
@@ -126,6 +127,8 @@ protected function _getFixtures(\PHPUnit\Framework\TestCase $test, $scope = null
126
127
$ fixtureMethod = [get_class ($ test ), $ fixture ];
127
128
if (is_callable ($ fixtureMethod )) {
128
129
$ result [] = $ fixtureMethod ;
130
+ } elseif ($ this ->isModuleAnnotation ($ fixture )) {
131
+ $ result [] = $ this ->getModulePath ($ fixture );
129
132
} else {
130
133
$ result [] = $ this ->_fixtureBaseDir . '/ ' . $ fixture ;
131
134
}
@@ -135,6 +138,49 @@ protected function _getFixtures(\PHPUnit\Framework\TestCase $test, $scope = null
135
138
}
136
139
137
140
/**
141
+ * Check is the Annotation like Magento_InventoryApi::Test/_files/products.php
142
+ *
143
+ * @param string $fixture
144
+ * @return bool
145
+ */
146
+ private function isModuleAnnotation (string $ fixture )
147
+ {
148
+ return (strpos ($ fixture , ':: ' ) !== false );
149
+ }
150
+
151
+ /**
152
+ * Resolve the Fixture
153
+ *
154
+ * @param string $fixture
155
+ * @return string
156
+ * @throws \Magento\Framework\Exception\LocalizedException
157
+ * @SuppressWarnings(PHPMD.StaticAccess)
158
+ */
159
+ private function getModulePath (string $ fixture )
160
+ {
161
+ $ fixturePathParts = explode (':: ' , $ fixture , 2 );
162
+ $ moduleName = $ fixturePathParts [0 ];
163
+ $ fixtureFile = $ fixturePathParts [1 ];
164
+
165
+ $ objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
166
+ /** @var ComponentRegistrar $componentRegistrar */
167
+ $ componentRegistrar = $ objectManager ->get (ComponentRegistrar::class);
168
+ $ modulePath = $ componentRegistrar ->getPath (ComponentRegistrar::MODULE , $ moduleName );
169
+
170
+ if ($ modulePath === null ) {
171
+ throw new \Magento \Framework \Exception \LocalizedException (
172
+ new \Magento \Framework \Phrase ('Can \'t find registered Module with name %1 . ' , [$ moduleName ])
173
+ );
174
+ }
175
+
176
+ return $ modulePath . '/ ' . $ fixtureFile ;
177
+ }
178
+
179
+ /**
180
+ * Get method annotations.
181
+ *
182
+ * Overwrites class-defined annotations.
183
+ *
138
184
* @param \PHPUnit\Framework\TestCase $test
139
185
* @return array
140
186
*/
0 commit comments