mirror of
https://github.com/silverstripe/silverstripe-behat-extension
synced 2024-10-22 17:05:32 +02:00
Upgrade module loader manifest
This commit is contained in:
parent
f0ca8eb84b
commit
d5c2113c52
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace SilverStripe\BehatExtension\Console\Processor;
|
namespace SilverStripe\BehatExtension\Console\Processor;
|
||||||
|
|
||||||
|
use SilverStripe\Core\Manifest\Module;
|
||||||
|
use SilverStripe\Core\Manifest\ModuleLoader;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
@ -76,24 +78,23 @@ class InitProcessor extends BaseProcessor
|
|||||||
|
|
||||||
// Can't use 'behat.paths.base' since that's locked at this point to base folder (not module)
|
// Can't use 'behat.paths.base' since that's locked at this point to base folder (not module)
|
||||||
$pathSuffix = $this->container->getParameter('behat.silverstripe_extension.context.path_suffix');
|
$pathSuffix = $this->container->getParameter('behat.silverstripe_extension.context.path_suffix');
|
||||||
$currentModuleName = null;
|
|
||||||
$modules = ClassLoader::instance()->getManifest()->getModules();
|
|
||||||
$currentModuleName = $this->container->getParameter('behat.silverstripe_extension.module');
|
|
||||||
|
|
||||||
// get module from short notation if path starts from @
|
// get module from short notation if path starts from @
|
||||||
|
$currentModuleName = $this->container->getParameter('behat.silverstripe_extension.module');
|
||||||
if (preg_match('/^\@([^\/\\\\]+)(.*)$/', $featuresPath, $matches)) {
|
if (preg_match('/^\@([^\/\\\\]+)(.*)$/', $featuresPath, $matches)) {
|
||||||
$currentModuleName = $matches[1];
|
$currentModuleName = $matches[1];
|
||||||
// TODO Replace with proper module loader once AJShort's changes are merged into core
|
|
||||||
if (!array_key_exists($currentModuleName, $modules)) {
|
|
||||||
throw new \InvalidArgumentException(sprintf('Module "%s" not found', $currentModuleName));
|
|
||||||
}
|
}
|
||||||
$currentModulePath = $modules[$currentModuleName];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$currentModuleName) {
|
if (!$currentModuleName) {
|
||||||
throw new \InvalidArgumentException('Can not find module to initialize suite.');
|
throw new \InvalidArgumentException('Can not find module to initialize suite.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get path for module
|
||||||
|
$module = ModuleLoader::instance()->getManifest()->getModule($currentModuleName);
|
||||||
|
if (!$module) {
|
||||||
|
throw new \InvalidArgumentException(sprintf('Module "%s" not found', $currentModuleName));
|
||||||
|
}
|
||||||
|
$currentModulePath = $module->getPath();
|
||||||
|
|
||||||
// TODO Retrieve from module definition once that's implemented
|
// TODO Retrieve from module definition once that's implemented
|
||||||
if ($input->getOption('namespace')) {
|
if ($input->getOption('namespace')) {
|
||||||
$namespace = $input->getOption('namespace');
|
$namespace = $input->getOption('namespace');
|
||||||
|
@ -2,13 +2,13 @@
|
|||||||
|
|
||||||
namespace SilverStripe\BehatExtension\Console\Processor;
|
namespace SilverStripe\BehatExtension\Console\Processor;
|
||||||
|
|
||||||
|
use SilverStripe\Core\Manifest\ModuleLoader;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Behat\Behat\Console\Processor\LocatorProcessor as BaseProcessor;
|
use Behat\Behat\Console\Processor\LocatorProcessor as BaseProcessor;
|
||||||
use SilverStripe\Core\Manifest\ClassLoader;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Path locator processor.
|
* Path locator processor.
|
||||||
@ -61,8 +61,6 @@ class LocatorProcessor extends BaseProcessor
|
|||||||
$pathSuffix = $this->container->getParameter('behat.silverstripe_extension.context.path_suffix');
|
$pathSuffix = $this->container->getParameter('behat.silverstripe_extension.context.path_suffix');
|
||||||
|
|
||||||
$currentModuleName = null;
|
$currentModuleName = null;
|
||||||
$modules = ClassLoader::instance()->getManifest()->getModules();
|
|
||||||
|
|
||||||
// get module specified in behat.yml
|
// get module specified in behat.yml
|
||||||
$currentModuleName = $this->container->getParameter('behat.silverstripe_extension.module');
|
$currentModuleName = $this->container->getParameter('behat.silverstripe_extension.module');
|
||||||
|
|
||||||
@ -70,7 +68,11 @@ class LocatorProcessor extends BaseProcessor
|
|||||||
if ($featuresPath && preg_match('/^\@([^\/\\\\]+)(.*)$/', $featuresPath, $matches)) {
|
if ($featuresPath && preg_match('/^\@([^\/\\\\]+)(.*)$/', $featuresPath, $matches)) {
|
||||||
$currentModuleName = $matches[1];
|
$currentModuleName = $matches[1];
|
||||||
// TODO Replace with proper module loader once AJShort's changes are merged into core
|
// TODO Replace with proper module loader once AJShort's changes are merged into core
|
||||||
$currentModulePath = $modules[$currentModuleName];
|
$module = ModuleLoader::instance()->getManifest()->getModule($currentModuleName);
|
||||||
|
if (!$module) {
|
||||||
|
throw new \InvalidArgumentException(sprintf('Module "%s" not found', $currentModuleName));
|
||||||
|
}
|
||||||
|
$currentModulePath = $module->getPath();
|
||||||
$featuresPath = str_replace(
|
$featuresPath = str_replace(
|
||||||
'@'.$currentModuleName,
|
'@'.$currentModuleName,
|
||||||
$currentModulePath.DIRECTORY_SEPARATOR.$pathSuffix,
|
$currentModulePath.DIRECTORY_SEPARATOR.$pathSuffix,
|
||||||
@ -79,17 +81,27 @@ class LocatorProcessor extends BaseProcessor
|
|||||||
// get module from provided features path
|
// get module from provided features path
|
||||||
} elseif (!$currentModuleName && $featuresPath) {
|
} elseif (!$currentModuleName && $featuresPath) {
|
||||||
$path = realpath(preg_replace('/\.feature\:.*$/', '.feature', $featuresPath));
|
$path = realpath(preg_replace('/\.feature\:.*$/', '.feature', $featuresPath));
|
||||||
foreach ($modules as $moduleName => $modulePath) {
|
$modules = ModuleLoader::instance()->getManifest()->getModules();
|
||||||
|
$currentModulePath = null;
|
||||||
|
foreach ($modules as $module) {
|
||||||
|
$modulePath = $module->getPath();
|
||||||
if (false !== strpos($path, realpath($modulePath))) {
|
if (false !== strpos($path, realpath($modulePath))) {
|
||||||
$currentModuleName = $moduleName;
|
$currentModuleName = $module->getName();
|
||||||
$currentModulePath = realpath($modulePath);
|
$currentModulePath = realpath($modulePath);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!$currentModulePath) {
|
||||||
|
throw new \InvalidArgumentException(sprintf('Module not found in path "%s"', $featuresPath));
|
||||||
|
}
|
||||||
$featuresPath = $currentModulePath.DIRECTORY_SEPARATOR.$pathSuffix.DIRECTORY_SEPARATOR.$featuresPath;
|
$featuresPath = $currentModulePath.DIRECTORY_SEPARATOR.$pathSuffix.DIRECTORY_SEPARATOR.$featuresPath;
|
||||||
// if module is configured for profile and feature provided
|
// if module is configured for profile and feature provided
|
||||||
} elseif ($currentModuleName && $featuresPath) {
|
} elseif ($currentModuleName && $featuresPath) {
|
||||||
$currentModulePath = $modules[$currentModuleName];
|
$module = ModuleLoader::instance()->getManifest()->getModule($currentModuleName);
|
||||||
|
if (!$module) {
|
||||||
|
throw new \InvalidArgumentException(sprintf('Module "%s" not found', $currentModuleName));
|
||||||
|
}
|
||||||
|
$currentModulePath = $module->getPath();
|
||||||
$featuresPath = $currentModulePath.DIRECTORY_SEPARATOR.$pathSuffix.DIRECTORY_SEPARATOR.$featuresPath;
|
$featuresPath = $currentModulePath.DIRECTORY_SEPARATOR.$pathSuffix.DIRECTORY_SEPARATOR.$featuresPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user