From d5c2113c5261d0b9bf1ad71e901faa83f190ebfa Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Tue, 21 Mar 2017 10:29:54 +1300 Subject: [PATCH] Upgrade module loader manifest --- .../Console/Processor/InitProcessor.php | 19 +++++++------- .../Console/Processor/LocatorProcessor.php | 26 ++++++++++++++----- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/SilverStripe/BehatExtension/Console/Processor/InitProcessor.php b/src/SilverStripe/BehatExtension/Console/Processor/InitProcessor.php index 5f52abd..0060c81 100644 --- a/src/SilverStripe/BehatExtension/Console/Processor/InitProcessor.php +++ b/src/SilverStripe/BehatExtension/Console/Processor/InitProcessor.php @@ -2,6 +2,8 @@ namespace SilverStripe\BehatExtension\Console\Processor; +use SilverStripe\Core\Manifest\Module; +use SilverStripe\Core\Manifest\ModuleLoader; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Console\Command\Command; 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) $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 @ + $currentModuleName = $this->container->getParameter('behat.silverstripe_extension.module'); if (preg_match('/^\@([^\/\\\\]+)(.*)$/', $featuresPath, $matches)) { $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) { 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 if ($input->getOption('namespace')) { $namespace = $input->getOption('namespace'); diff --git a/src/SilverStripe/BehatExtension/Console/Processor/LocatorProcessor.php b/src/SilverStripe/BehatExtension/Console/Processor/LocatorProcessor.php index 5b76e58..63d18c2 100644 --- a/src/SilverStripe/BehatExtension/Console/Processor/LocatorProcessor.php +++ b/src/SilverStripe/BehatExtension/Console/Processor/LocatorProcessor.php @@ -2,13 +2,13 @@ namespace SilverStripe\BehatExtension\Console\Processor; +use SilverStripe\Core\Manifest\ModuleLoader; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Behat\Behat\Console\Processor\LocatorProcessor as BaseProcessor; -use SilverStripe\Core\Manifest\ClassLoader; /** * Path locator processor. @@ -61,8 +61,6 @@ class LocatorProcessor extends BaseProcessor $pathSuffix = $this->container->getParameter('behat.silverstripe_extension.context.path_suffix'); $currentModuleName = null; - $modules = ClassLoader::instance()->getManifest()->getModules(); - // get module specified in behat.yml $currentModuleName = $this->container->getParameter('behat.silverstripe_extension.module'); @@ -70,7 +68,11 @@ class LocatorProcessor extends BaseProcessor if ($featuresPath && preg_match('/^\@([^\/\\\\]+)(.*)$/', $featuresPath, $matches)) { $currentModuleName = $matches[1]; // 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( '@'.$currentModuleName, $currentModulePath.DIRECTORY_SEPARATOR.$pathSuffix, @@ -79,17 +81,27 @@ class LocatorProcessor extends BaseProcessor // get module from provided features path } elseif (!$currentModuleName && $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))) { - $currentModuleName = $moduleName; + $currentModuleName = $module->getName(); $currentModulePath = realpath($modulePath); break; } } + if (!$currentModulePath) { + throw new \InvalidArgumentException(sprintf('Module not found in path "%s"', $featuresPath)); + } $featuresPath = $currentModulePath.DIRECTORY_SEPARATOR.$pathSuffix.DIRECTORY_SEPARATOR.$featuresPath; // if module is configured for profile and feature provided } 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; }