Skip to content

#19575 magentoDataFixture should allow to use Module Prefix - Integrations Test #19679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 18, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
/**
* Implementation of the @magentoDataFixture DocBlock annotation
*/

namespace Magento\TestFramework\Annotation;

use Magento\Framework\Component\ComponentRegistrar;
use PHPUnit\Framework\Exception;

class DataFixture
Expand Down Expand Up @@ -126,6 +128,8 @@ protected function _getFixtures(\PHPUnit\Framework\TestCase $test, $scope = null
$fixtureMethod = [get_class($test), $fixture];
if (is_callable($fixtureMethod)) {
$result[] = $fixtureMethod;
} elseif ($this->isModuleAnnotation($fixture)) {
$result[] = $this->getModulePath($fixture);
} else {
$result[] = $this->_fixtureBaseDir . '/' . $fixture;
}
Expand All @@ -134,6 +138,45 @@ protected function _getFixtures(\PHPUnit\Framework\TestCase $test, $scope = null
return $result;
}

/**
* Check is the Annotation like Magento_InventoryApi::Test/_files/products.php
*
* @param string $fixture
* @return bool
*/
private function isModuleAnnotation(string $fixture)
{
return (strpos($fixture, '::') !== false);
}

/**
* Resolve the Fixture
*
* @param string $fixture
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
* @SuppressWarnings(PHPMD.StaticAccess)
*/
private function getModulePath(string $fixture)
{
$fixturePathParts = explode('::', $fixture, 2);
$moduleName = $fixturePathParts[0];
$fixtureFile = $fixturePathParts[1];

$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
/** @var ComponentRegistrar $componentRegistrar */
$componentRegistrar = $objectManager->get(ComponentRegistrar::class);
$modulePath = $componentRegistrar->getPath(ComponentRegistrar::MODULE, $moduleName);

if ($modulePath === null) {
throw new \Magento\Framework\Exception\LocalizedException(
new \Magento\Framework\Phrase('Can\'t find registered Module with name %1 .', [$moduleName])
);
}

return $modulePath . '/' . $fixtureFile;
}

/**
* @param \PHPUnit\Framework\TestCase $test
* @return array
Expand Down