Skip to content

Commit bde899b

Browse files
authored
ENGCOM-3657: #19575 magentoDataFixture should allow to use Module Prefix - Integrations Test #19679
2 parents 35911a3 + 0033f38 commit bde899b

File tree

1 file changed

+49
-3
lines changed
  • dev/tests/integration/framework/Magento/TestFramework/Annotation

1 file changed

+49
-3
lines changed

dev/tests/integration/framework/Magento/TestFramework/Annotation/DataFixture.php

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
/**
8-
* Implementation of the @magentoDataFixture DocBlock annotation
9-
*/
107
namespace Magento\TestFramework\Annotation;
118

9+
use Magento\Framework\Component\ComponentRegistrar;
1210
use PHPUnit\Framework\Exception;
1311

12+
/**
13+
* Implementation of the @magentoDataFixture DocBlock annotation.
14+
*/
1415
class DataFixture
1516
{
1617
/**
@@ -126,6 +127,8 @@ protected function _getFixtures(\PHPUnit\Framework\TestCase $test, $scope = null
126127
$fixtureMethod = [get_class($test), $fixture];
127128
if (is_callable($fixtureMethod)) {
128129
$result[] = $fixtureMethod;
130+
} elseif ($this->isModuleAnnotation($fixture)) {
131+
$result[] = $this->getModulePath($fixture);
129132
} else {
130133
$result[] = $this->_fixtureBaseDir . '/' . $fixture;
131134
}
@@ -135,6 +138,49 @@ protected function _getFixtures(\PHPUnit\Framework\TestCase $test, $scope = null
135138
}
136139

137140
/**
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+
*
138184
* @param \PHPUnit\Framework\TestCase $test
139185
* @return array
140186
*/

0 commit comments

Comments
 (0)