diff --git a/composer.json b/composer.json index aa5b75e..8c96b9a 100644 --- a/composer.json +++ b/composer.json @@ -14,12 +14,12 @@ "puli/repository": "^1.0-beta9", "puli/discovery": "^1.0-beta9", "puli/url-generator": "^1.0-beta4", - "puli/manager": "^1.0-beta10", + "puli/manager": "^1.0-beta11@dev", "webmozart/console": "^1.0-beta4", "webmozart/path-util": "^2.2.2", "webmozart/expression": "^1.0", "webmozart/glob": "^4.0", - "webmozart/json": "^1.2.2", + "webmozart/json": "^1.2.2@dev", "padraic/phar-updater": "^1.0.1" }, "require-dev": { diff --git a/src/Handler/BindCommandHandler.php b/src/Handler/BindCommandHandler.php index 71a909f..6d6d483 100644 --- a/src/Handler/BindCommandHandler.php +++ b/src/Handler/BindCommandHandler.php @@ -19,8 +19,8 @@ use Puli\Manager\Api\Discovery\BindingDescriptor; use Puli\Manager\Api\Discovery\BindingState; use Puli\Manager\Api\Discovery\DiscoveryManager; -use Puli\Manager\Api\Package\PackageCollection; -use Puli\Manager\Api\Package\RootPackage; +use Puli\Manager\Api\Module\ModuleList; +use Puli\Manager\Api\Module\RootModule; use RuntimeException; use Webmozart\Console\Api\Args\Args; use Webmozart\Console\Api\IO\IO; @@ -43,9 +43,9 @@ class BindCommandHandler private $discoveryManager; /** - * @var PackageCollection + * @var ModuleList */ - private $packages; + private $modules; /** * @var string @@ -55,40 +55,40 @@ class BindCommandHandler /** * Creates the handler. * - * @param DiscoveryManager $discoveryManager The discovery manager. - * @param PackageCollection $packages The loaded packages. + * @param DiscoveryManager $discoveryManager The discovery manager + * @param ModuleList $modules The loaded modules */ - public function __construct(DiscoveryManager $discoveryManager, PackageCollection $packages) + public function __construct(DiscoveryManager $discoveryManager, ModuleList $modules) { $this->discoveryManager = $discoveryManager; - $this->packages = $packages; + $this->modules = $modules; } /** * Handles the "bind --list" command. * - * @param Args $args The console arguments. - * @param IO $io The I/O. + * @param Args $args The console arguments + * @param IO $io The I/O * - * @return int The status code. + * @return int The status code */ public function handleList(Args $args, IO $io) { - $packageNames = ArgsUtil::getPackageNames($args, $this->packages); + $moduleNames = ArgsUtil::getModuleNames($args, $this->modules); $bindingStates = $this->getBindingStates($args); $printBindingState = count($bindingStates) > 1; - $printPackageName = count($packageNames) > 1; - $printHeaders = $printBindingState || $printPackageName; + $printModuleName = count($moduleNames) > 1; + $printHeaders = $printBindingState || $printModuleName; $printAdvice = true; - $indentation = $printBindingState && $printPackageName ? 8 - : ($printBindingState || $printPackageName ? 4 : 0); + $indentation = $printBindingState && $printModuleName ? 8 + : ($printBindingState || $printModuleName ? 4 : 0); foreach ($bindingStates as $bindingState) { $bindingStatePrinted = !$printBindingState; - foreach ($packageNames as $packageName) { - $expr = Expr::method('getContainingPackage', Expr::method('getName', Expr::same($packageName))) + foreach ($moduleNames as $moduleName) { + $expr = Expr::method('getContainingModule', Expr::method('getName', Expr::same($moduleName))) ->andMethod('getState', Expr::same($bindingState)); $descriptors = $this->discoveryManager->findBindingDescriptors($expr); @@ -104,9 +104,9 @@ public function handleList(Args $args, IO $io) $bindingStatePrinted = true; } - if ($printPackageName) { + if ($printModuleName) { $prefix = $printBindingState ? ' ' : ''; - $io->writeLine(sprintf('%sPackage: %s', $prefix, $packageName)); + $io->writeLine(sprintf('%sModule: %s', $prefix, $moduleName)); $io->writeLine(''); } @@ -128,9 +128,9 @@ public function handleList(Args $args, IO $io) /** * Handles the "bind " command. * - * @param Args $args The console arguments. + * @param Args $args The console arguments * - * @return int The status code. + * @return int The status code */ public function handleAdd(Args $args) { @@ -167,9 +167,9 @@ public function handleAdd(Args $args) /** * Handles the "bind --update " command. * - * @param Args $args The console arguments. + * @param Args $args The console arguments * - * @return int The status code. + * @return int The status code */ public function handleUpdate(Args $args) { @@ -181,10 +181,10 @@ public function handleUpdate(Args $args) $descriptorToUpdate = $this->getBindingByUuidPrefix($args->getArgument('uuid')); $bindingToUpdate = $descriptorToUpdate->getBinding(); - if (!$descriptorToUpdate->getContainingPackage() instanceof RootPackage) { + if (!$descriptorToUpdate->getContainingModule() instanceof RootModule) { throw new RuntimeException(sprintf( - 'Can only update bindings in the package "%s".', - $this->packages->getRootPackageName() + 'Can only update bindings in the module "%s".', + $this->modules->getRootModuleName() )); } @@ -213,18 +213,18 @@ public function handleUpdate(Args $args) /** * Handles the "bind --delete" command. * - * @param Args $args The console arguments. + * @param Args $args The console arguments * - * @return int The status code. + * @return int The status code */ public function handleDelete(Args $args) { $bindingToRemove = $this->getBindingByUuidPrefix($args->getArgument('uuid')); - if (!$bindingToRemove->getContainingPackage() instanceof RootPackage) { + if (!$bindingToRemove->getContainingModule() instanceof RootModule) { throw new RuntimeException(sprintf( - 'Can only delete bindings from the package "%s".', - $this->packages->getRootPackageName() + 'Can only delete bindings from the module "%s".', + $this->modules->getRootModuleName() )); } @@ -236,18 +236,18 @@ public function handleDelete(Args $args) /** * Handles the "bind --enable" command. * - * @param Args $args The console arguments. + * @param Args $args The console arguments * - * @return int The status code. + * @return int The status code */ public function handleEnable(Args $args) { $bindingToEnable = $this->getBindingByUuidPrefix($args->getArgument('uuid')); - if ($bindingToEnable->getContainingPackage() instanceof RootPackage) { + if ($bindingToEnable->getContainingModule() instanceof RootModule) { throw new RuntimeException(sprintf( - 'Cannot enable bindings in the package "%s".', - $bindingToEnable->getContainingPackage()->getName() + 'Cannot enable bindings in the module "%s".', + $bindingToEnable->getContainingModule()->getName() )); } @@ -259,18 +259,18 @@ public function handleEnable(Args $args) /** * Handles the "bind --disable" command. * - * @param Args $args The console arguments. + * @param Args $args The console arguments * - * @return int The status code. + * @return int The status code */ public function handleDisable(Args $args) { $bindingToDisable = $this->getBindingByUuidPrefix($args->getArgument('uuid')); - if ($bindingToDisable->getContainingPackage() instanceof RootPackage) { + if ($bindingToDisable->getContainingModule() instanceof RootModule) { throw new RuntimeException(sprintf( - 'Cannot disable bindings in the package "%s".', - $bindingToDisable->getContainingPackage()->getName() + 'Cannot disable bindings in the module "%s".', + $bindingToDisable->getContainingModule()->getName() )); } @@ -282,9 +282,9 @@ public function handleDisable(Args $args) /** * Returns the binding states selected in the console arguments. * - * @param Args $args The console arguments. + * @param Args $args The console arguments * - * @return int[] The selected {@link BindingState} constants. + * @return int[] The selected {@link BindingState} constants */ private function getBindingStates(Args $args) { @@ -306,12 +306,12 @@ private function getBindingStates(Args $args) /** * Prints a list of binding descriptors. * - * @param IO $io The I/O. - * @param BindingDescriptor[] $descriptors The binding descriptors. - * @param int $indentation The number of spaces to indent. + * @param IO $io The I/O + * @param BindingDescriptor[] $descriptors The binding descriptors + * @param int $indentation The number of spaces to indent * @param bool $enabled Whether the binding descriptors * are enabled. If not, the output - * is printed in red. + * is printed in red */ private function printBindingTable(IO $io, array $descriptors, $indentation = 0, $enabled = true) { @@ -372,8 +372,8 @@ private function printBindingTable(IO $io, array $descriptors, $indentation = 0, /** * Prints the header for a binding state. * - * @param IO $io The I/O. - * @param int $bindingState The {@link BindingState} constant. + * @param IO $io The I/O + * @param int $bindingState The {@link BindingState} constant */ private function printBindingStateHeader(IO $io, $bindingState) { diff --git a/src/Handler/ConfigCommandHandler.php b/src/Handler/ConfigCommandHandler.php index 81e32e0..d073215 100644 --- a/src/Handler/ConfigCommandHandler.php +++ b/src/Handler/ConfigCommandHandler.php @@ -13,7 +13,7 @@ use Puli\Cli\Style\PuliTableStyle; use Puli\Cli\Util\StringUtil; -use Puli\Manager\Api\Package\RootPackageFileManager; +use Puli\Manager\Api\Module\RootModuleFileManager; use Webmozart\Console\Api\Args\Args; use Webmozart\Console\Api\IO\IO; use Webmozart\Console\UI\Component\Table; @@ -28,16 +28,16 @@ class ConfigCommandHandler { /** - * @var RootPackageFileManager + * @var RootModuleFileManager */ private $manager; /** * Creates the handler. * - * @param RootPackageFileManager $manager The root package file manager. + * @param RootModuleFileManager $manager The root module file manager */ - public function __construct(RootPackageFileManager $manager) + public function __construct(RootModuleFileManager $manager) { $this->manager = $manager; } @@ -45,10 +45,10 @@ public function __construct(RootPackageFileManager $manager) /** * Handles the "config" command. * - * @param Args $args The console arguments. - * @param IO $io The I/O. + * @param Args $args The console arguments + * @param IO $io The I/O * - * @return int The status code. + * @return int The status code */ public function handleList(Args $args, IO $io) { @@ -77,10 +77,10 @@ public function handleList(Args $args, IO $io) /** * Handles the "config " command. * - * @param Args $args The console arguments. - * @param IO $io The I/O. + * @param Args $args The console arguments + * @param IO $io The I/O * - * @return int The status code. + * @return int The status code */ public function handleShow(Args $args, IO $io) { @@ -95,9 +95,9 @@ public function handleShow(Args $args, IO $io) /** * Handles the "config " command. * - * @param Args $args The console arguments. + * @param Args $args The console arguments * - * @return int The status code. + * @return int The status code */ public function handleSet(Args $args) { @@ -111,9 +111,9 @@ public function handleSet(Args $args) /** * Handles the "config -r " command. * - * @param Args $args The console arguments. + * @param Args $args The console arguments * - * @return int The status code. + * @return int The status code */ public function handleReset(Args $args) { diff --git a/src/Handler/MapCommandHandler.php b/src/Handler/MapCommandHandler.php index cc30244..4b99e40 100644 --- a/src/Handler/MapCommandHandler.php +++ b/src/Handler/MapCommandHandler.php @@ -13,7 +13,7 @@ use Puli\Cli\Style\PuliTableStyle; use Puli\Cli\Util\ArgsUtil; -use Puli\Manager\Api\Package\PackageCollection; +use Puli\Manager\Api\Module\ModuleList; use Puli\Manager\Api\Repository\PathConflict; use Puli\Manager\Api\Repository\PathMapping; use Puli\Manager\Api\Repository\PathMappingState; @@ -40,9 +40,9 @@ class MapCommandHandler private $repoManager; /** - * @var PackageCollection + * @var ModuleList */ - private $packages; + private $modules; /** * @var string @@ -52,40 +52,40 @@ class MapCommandHandler /** * Creates the handler. * - * @param RepositoryManager $repoManager The repository manager. - * @param PackageCollection $packages The loaded packages. + * @param RepositoryManager $repoManager The repository manager + * @param ModuleList $modules The loaded modules */ - public function __construct(RepositoryManager $repoManager, PackageCollection $packages) + public function __construct(RepositoryManager $repoManager, ModuleList $modules) { $this->repoManager = $repoManager; - $this->packages = $packages; + $this->modules = $modules; } /** * Handles the "puli map --list" command. * - * @param Args $args The console arguments. - * @param IO $io The I/O. + * @param Args $args The console arguments + * @param IO $io The I/O * - * @return int The status code. + * @return int The status code */ public function handleList(Args $args, IO $io) { - $packageNames = ArgsUtil::getPackageNames($args, $this->packages); + $moduleNames = ArgsUtil::getModuleNames($args, $this->modules); $states = $this->getPathMappingStates($args); $printState = count($states) > 1; - $printPackageName = count($packageNames) > 1; - $printHeaders = $printState || $printPackageName; + $printModuleName = count($moduleNames) > 1; + $printHeaders = $printState || $printModuleName; $printAdvice = true; - $indentation = ($printState && $printPackageName) ? 8 - : ($printState || $printPackageName ? 4 : 0); + $indentation = ($printState && $printModuleName) ? 8 + : ($printState || $printModuleName ? 4 : 0); foreach ($states as $state) { $statePrinted = !$printState; if (PathMappingState::CONFLICT === $state) { - $expr = Expr::method('getContainingPackage', Expr::method('getName', Expr::in($packageNames))) + $expr = Expr::method('getContainingModule', Expr::method('getName', Expr::in($moduleNames))) ->andMethod('getState', Expr::same($state)); $mappings = $this->repoManager->findPathMappings($expr); @@ -109,8 +109,8 @@ public function handleList(Args $args, IO $io) continue; } - foreach ($packageNames as $packageName) { - $expr = Expr::method('getContainingPackage', Expr::method('getName', Expr::same($packageName))) + foreach ($moduleNames as $moduleName) { + $expr = Expr::method('getContainingModule', Expr::method('getName', Expr::same($moduleName))) ->andMethod('getState', Expr::same($state)); $mappings = $this->repoManager->findPathMappings($expr); @@ -126,9 +126,9 @@ public function handleList(Args $args, IO $io) $statePrinted = true; } - if ($printPackageName) { + if ($printModuleName) { $prefix = $printState ? ' ' : ''; - $io->writeLine(sprintf('%sPackage: %s', $prefix, $packageName)); + $io->writeLine(sprintf('%sModule: %s', $prefix, $moduleName)); $io->writeLine(''); } @@ -150,9 +150,9 @@ public function handleList(Args $args, IO $io) /** * Handles the "puli map" command. * - * @param Args $args The console arguments. + * @param Args $args The console arguments * - * @return int The status code. + * @return int The status code */ public function handleAdd(Args $args) { @@ -170,9 +170,9 @@ public function handleAdd(Args $args) /** * Handles the "puli map --update" command. * - * @param Args $args The console arguments. + * @param Args $args The console arguments * - * @return int The status code. + * @return int The status code */ public function handleUpdate(Args $args) { @@ -211,9 +211,9 @@ public function handleUpdate(Args $args) /** * Handles the "puli map --delete" command. * - * @param Args $args The console arguments. + * @param Args $args The console arguments * - * @return int The status code. + * @return int The status code */ public function handleDelete(Args $args) { @@ -221,9 +221,9 @@ public function handleDelete(Args $args) if (!$this->repoManager->hasRootPathMapping($repositoryPath)) { throw new RuntimeException(sprintf( - 'The path "%s" is not mapped in the package "%s".', + 'The path "%s" is not mapped in the module "%s".', $repositoryPath, - $this->packages->getRootPackageName() + $this->modules->getRootModuleName() )); } @@ -235,12 +235,12 @@ public function handleDelete(Args $args) /** * Prints a list of path mappings. * - * @param IO $io The I/O. - * @param PathMapping[] $mappings The path mappings. + * @param IO $io The I/O + * @param PathMapping[] $mappings The path mappings * @param int $indentation The number of spaces to indent the - * output. + * output * @param bool $enabled Whether the path mappings are enabled. - * If not, the output is printed in red. + * If not, the output is printed in red */ private function printMappingTable(IO $io, array $mappings, $indentation = 0, $enabled = true) { @@ -281,10 +281,10 @@ private function printMappingTable(IO $io, array $mappings, $indentation = 0, $e /** * Prints a list of conflicting path mappings. * - * @param IO $io The I/O. - * @param PathMapping[] $mappings The path mappings. + * @param IO $io The I/O + * @param PathMapping[] $mappings The path mappings * @param int $indentation The number of spaces to indent the - * output. + * output */ private function printConflictTable(IO $io, array $mappings, $indentation = 0) { @@ -310,11 +310,11 @@ private function printConflictTable(IO $io, array $mappings, $indentation = 0) $table = new Table(PuliTableStyle::borderless()); - $table->setHeaderRow(array('Package', 'Puli Path', 'Real Path(s)')); + $table->setHeaderRow(array('Module', 'Puli Path', 'Real Path(s)')); foreach ($conflict->getMappings() as $mapping) { $table->addRow(array( - ''.$mapping->getContainingPackage()->getName().'', + ''.$mapping->getContainingModule()->getName().'', ''.$mapping->getRepositoryPath().'', ''.implode(', ', $mapping->getPathReferences()).'', )); @@ -332,9 +332,9 @@ private function printConflictTable(IO $io, array $mappings, $indentation = 0) /** * Returns the path mapping states selected in the console arguments. * - * @param Args $args The console arguments. + * @param Args $args The console arguments * - * @return int[] The selected {@link PathMappingState} constants. + * @return int[] The selected {@link PathMappingState} constants */ private function getPathMappingStates(Args $args) { @@ -354,8 +354,8 @@ private function getPathMappingStates(Args $args) /** * Prints the header for a path mapping state. * - * @param IO $io The I/O. - * @param int $pathMappingState The {@link PathMappingState} constant. + * @param IO $io The I/O + * @param int $pathMappingState The {@link PathMappingState} constant */ private function printPathMappingStateHeader(IO $io, $pathMappingState) { @@ -372,7 +372,7 @@ private function printPathMappingStateHeader(IO $io, $pathMappingState) return; case PathMappingState::CONFLICT: $io->writeLine('Some path mappings have conflicting paths:'); - $io->writeLine(' (add the package names to the "override-order" key in puli.json to resolve)'); + $io->writeLine(' (add the module names to the "override-order" key in puli.json to resolve)'); $io->writeLine(''); return; diff --git a/src/Handler/ModuleCommandHandler.php b/src/Handler/ModuleCommandHandler.php new file mode 100644 index 0000000..1f5dab8 --- /dev/null +++ b/src/Handler/ModuleCommandHandler.php @@ -0,0 +1,392 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Puli\Cli\Handler; + +use Puli\Cli\Style\PuliTableStyle; +use Puli\Cli\Util\StringUtil; +use Puli\Manager\Api\Environment; +use Puli\Manager\Api\Module\Module; +use Puli\Manager\Api\Module\ModuleList; +use Puli\Manager\Api\Module\ModuleManager; +use Puli\Manager\Api\Module\ModuleState; +use RuntimeException; +use Webmozart\Console\Api\Args\Args; +use Webmozart\Console\Api\IO\IO; +use Webmozart\Console\UI\Component\Table; +use Webmozart\Expression\Expr; +use Webmozart\PathUtil\Path; + +/** + * Handles the "module" command. + * + * @since 1.0 + * + * @author Bernhard Schussek + */ +class ModuleCommandHandler +{ + /** + * @var array + */ + private static $stateStrings = array( + ModuleState::ENABLED => 'enabled', + ModuleState::NOT_FOUND => 'not-found', + ModuleState::NOT_LOADABLE => 'not-loadable', + ); + + /** + * @var ModuleManager + */ + private $moduleManager; + + /** + * Creates the handler. + * + * @param ModuleManager $moduleManager The module manager + */ + public function __construct(ModuleManager $moduleManager) + { + $this->moduleManager = $moduleManager; + } + + /** + * Handles the "module --list" command. + * + * @param Args $args The console arguments + * @param IO $io The I/O + * + * @return int The status code + */ + public function handleList(Args $args, IO $io) + { + $modules = $this->getSelectedModules($args); + + if ($args->isOptionSet('format')) { + $this->printModulesWithFormat($io, $modules, $args->getOption('format')); + } else { + $this->printModulesByState($io, $modules, $this->getSelectedStates($args)); + } + + return 0; + } + + /** + * Handles the "module --install" command. + * + * @param Args $args The console arguments + * + * @return int The status code + */ + public function handleInstall(Args $args) + { + $moduleName = $args->getArgument('name'); + $installPath = Path::makeAbsolute($args->getArgument('path'), getcwd()); + $installer = $args->getOption('installer'); + $env = $args->isOptionSet('dev') ? Environment::DEV : Environment::PROD; + + $this->moduleManager->installModule($installPath, $moduleName, $installer, $env); + + return 0; + } + + /** + * Handles the "module --rename" command. + * + * @param Args $args The console arguments + * + * @return int The status code + */ + public function handleRename(Args $args) + { + $moduleName = $args->getArgument('name'); + $newName = $args->getArgument('new-name'); + + $this->moduleManager->renameModule($moduleName, $newName); + + return 0; + } + + /** + * Handles the "module --delete" command. + * + * @param Args $args The console arguments + * + * @return int The status code + */ + public function handleDelete(Args $args) + { + $moduleName = $args->getArgument('name'); + + if (!$this->moduleManager->hasModule($moduleName)) { + throw new RuntimeException(sprintf( + 'The module "%s" is not installed.', + $moduleName + )); + } + + $this->moduleManager->removeModule($moduleName); + + return 0; + } + + /** + * Handles the "module --clean" command. + * + * @param Args $args The console arguments + * @param IO $io The I/O + * + * @return int The status code + */ + public function handleClean(Args $args, IO $io) + { + $expr = Expr::method('getState', Expr::same(ModuleState::NOT_FOUND)); + + foreach ($this->moduleManager->findModules($expr) as $module) { + $io->writeLine('Removing '.$module->getName()); + $this->moduleManager->removeModule($module->getName()); + } + + return 0; + } + + /** + * Returns the module states that should be displayed for the given + * console arguments. + * + * @param Args $args The console arguments + * + * @return int[] A list of {@link ModuleState} constants + */ + private function getSelectedStates(Args $args) + { + $states = array(); + + if ($args->isOptionSet('enabled')) { + $states[] = ModuleState::ENABLED; + } + + if ($args->isOptionSet('not-found')) { + $states[] = ModuleState::NOT_FOUND; + } + + if ($args->isOptionSet('not-loadable')) { + $states[] = ModuleState::NOT_LOADABLE; + } + + return $states ?: ModuleState::all(); + } + + /** + * Returns the modules that should be displayed for the given console + * arguments. + * + * @param Args $args The console arguments + * + * @return ModuleList The modules + */ + private function getSelectedModules(Args $args) + { + $states = $this->getSelectedStates($args); + $expr = Expr::true(); + $envs = array(); + + if ($states !== ModuleState::all()) { + $expr = $expr->andMethod('getState', Expr::in($states)); + } + + if ($args->isOptionSet('installer')) { + $expr = $expr->andMethod('getInstallInfo', Expr::method('getInstallerName', Expr::same($args->getOption('installer')))); + } + + if ($args->isOptionSet('prod')) { + $envs[] = Environment::PROD; + } + + if ($args->isOptionSet('dev')) { + $envs[] = Environment::DEV; + } + + if (count($envs) > 0) { + $expr = $expr->andMethod('getInstallInfo', Expr::method('getEnvironment', Expr::in($envs))); + } + + return $this->moduleManager->findModules($expr); + } + + /** + * Prints modules with intermediate headers for the module states. + * + * @param IO $io The I/O + * @param ModuleList $modules The modules to print + * @param int[] $states The states to print + */ + private function printModulesByState(IO $io, ModuleList $modules, array $states) + { + $printStates = count($states) > 1; + + foreach ($states as $state) { + $filteredModules = array_filter($modules->toArray(), function (Module $module) use ($state) { + return $state === $module->getState(); + }); + + if (0 === count($filteredModules)) { + continue; + } + + if ($printStates) { + $this->printModuleState($io, $state); + } + + if (ModuleState::NOT_LOADABLE === $state) { + $this->printNotLoadableModules($io, $filteredModules, $printStates); + } else { + $styleTag = ModuleState::ENABLED === $state ? null : 'bad'; + $this->printModuleTable($io, $filteredModules, $styleTag, $printStates); + } + + if ($printStates) { + $io->writeLine(''); + } + } + } + + /** + * Prints modules using the given format. + * + * @param IO $io The I/O + * @param ModuleList $modules The modules to print + * @param string $format The format string + */ + private function printModulesWithFormat(IO $io, ModuleList $modules, $format) + { + /** @var Module $module */ + foreach ($modules as $module) { + $installInfo = $module->getInstallInfo(); + + $io->writeLine(strtr($format, array( + '%name%' => $module->getName(), + '%installer%' => $installInfo ? $installInfo->getInstallerName() : '', + '%install_path%' => $module->getInstallPath(), + '%state%' => self::$stateStrings[$module->getState()], + '%env%' => $installInfo ? $installInfo->getEnvironment() : Environment::PROD, + ))); + } + } + + /** + * Prints the heading for a given module state. + * + * @param IO $io The I/O + * @param int $ModuleState The {@link ModuleState} constant + */ + private function printModuleState(IO $io, $ModuleState) + { + switch ($ModuleState) { + case ModuleState::ENABLED: + $io->writeLine('The following modules are currently enabled:'); + $io->writeLine(''); + + return; + case ModuleState::NOT_FOUND: + $io->writeLine('The following modules could not be found:'); + $io->writeLine(' (use "puli module --clean" to remove)'); + $io->writeLine(''); + + return; + case ModuleState::NOT_LOADABLE: + $io->writeLine('The following modules could not be loaded:'); + $io->writeLine(''); + + return; + } + } + + /** + * Prints a list of modules in a table. + * + * @param IO $io The I/O + * @param Module[] $modules The modules + * @param string|null $styleTag The tag used to style the output. If `null`, + * the default colors are used + * @param bool $indent Whether to indent the output + */ + private function printModuleTable(IO $io, array $modules, $styleTag = null, $indent = false) + { + $table = new Table(PuliTableStyle::borderless()); + $table->setHeaderRow(array('Module Name', 'Installer', 'Env', 'Install Path')); + + $installerTag = $styleTag ?: 'c1'; + $envTag = $styleTag ?: 'c1'; + $pathTag = $styleTag ?: 'c2'; + + ksort($modules); + + foreach ($modules as $module) { + $moduleName = $module->getName(); + $installInfo = $module->getInstallInfo(); + $installPath = $installInfo ? $installInfo->getInstallPath() : '.'; + $installer = $installInfo ? $installInfo->getInstallerName() : ''; + $env = $installInfo ? $installInfo->getEnvironment() : Environment::PROD; + + $table->addRow(array( + $styleTag ? sprintf('<%s>%s', $styleTag, $moduleName, $styleTag) : $moduleName, + $installer ? sprintf('<%s>%s', $installerTag, $installer, $installerTag) : '', + sprintf('<%s>%s', $envTag, $env, $envTag), + sprintf('<%s>%s', $pathTag, $installPath, $pathTag), + )); + } + + $table->render($io, $indent ? 4 : 0); + } + + /** + * Prints not-loadable modules in a table. + * + * @param IO $io The I/O + * @param Module[] $modules The not-loadable modules + * @param bool $indent Whether to indent the output + */ + private function printNotLoadableModules(IO $io, array $modules, $indent = false) + { + $rootDir = $this->moduleManager->getContext()->getRootDirectory(); + $table = new Table(PuliTableStyle::borderless()); + $table->setHeaderRow(array('Module Name', 'Error')); + + ksort($modules); + + foreach ($modules as $module) { + $moduleName = $module->getName(); + $loadErrors = $module->getLoadErrors(); + $errorMessage = ''; + + foreach ($loadErrors as $loadError) { + $errorMessage .= StringUtil::getShortClassName(get_class($loadError)).': '.$loadError->getMessage()."\n"; + } + + $errorMessage = rtrim($errorMessage); + + if (!$errorMessage) { + $errorMessage = 'Unknown error.'; + } + + // Remove root directory + $errorMessage = str_replace($rootDir.'/', '', $errorMessage); + + $table->addRow(array( + sprintf('%s', $moduleName), + sprintf('%s', $errorMessage), + )); + } + + $table->render($io, $indent ? 4 : 0); + } +} diff --git a/src/Handler/PackageCommandHandler.php b/src/Handler/PackageCommandHandler.php deleted file mode 100644 index 11d1772..0000000 --- a/src/Handler/PackageCommandHandler.php +++ /dev/null @@ -1,391 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Puli\Cli\Handler; - -use Puli\Cli\Style\PuliTableStyle; -use Puli\Cli\Util\StringUtil; -use Puli\Manager\Api\Environment; -use Puli\Manager\Api\Package\Package; -use Puli\Manager\Api\Package\PackageCollection; -use Puli\Manager\Api\Package\PackageManager; -use Puli\Manager\Api\Package\PackageState; -use RuntimeException; -use Webmozart\Console\Api\Args\Args; -use Webmozart\Console\Api\IO\IO; -use Webmozart\Console\UI\Component\Table; -use Webmozart\Expression\Expr; -use Webmozart\PathUtil\Path; - -/** - * Handles the "package" command. - * - * @since 1.0 - * - * @author Bernhard Schussek - */ -class PackageCommandHandler -{ - /** - * @var array - */ - private static $stateStrings = array( - PackageState::ENABLED => 'enabled', - PackageState::NOT_FOUND => 'not-found', - PackageState::NOT_LOADABLE => 'not-loadable', - ); - - /** - * @var PackageManager - */ - private $packageManager; - - /** - * Creates the handler. - * - * @param PackageManager $packageManager The package manager. - */ - public function __construct(PackageManager $packageManager) - { - $this->packageManager = $packageManager; - } - - /** - * Handles the "package --list" command. - * - * @param Args $args The console arguments. - * @param IO $io The I/O. - * - * @return int The status code. - */ - public function handleList(Args $args, IO $io) - { - $packages = $this->getSelectedPackages($args); - - if ($args->isOptionSet('format')) { - $this->printPackagesWithFormat($io, $packages, $args->getOption('format')); - } else { - $this->printPackagesByState($io, $packages, $this->getSelectedStates($args)); - } - - return 0; - } - - /** - * Handles the "package --install" command. - * - * @param Args $args The console arguments. - * - * @return int The status code. - */ - public function handleInstall(Args $args) - { - $packageName = $args->getArgument('name'); - $installPath = Path::makeAbsolute($args->getArgument('path'), getcwd()); - $installer = $args->getOption('installer'); - $env = $args->isOptionSet('dev') ? Environment::DEV : Environment::PROD; - - $this->packageManager->installPackage($installPath, $packageName, $installer, $env); - - return 0; - } - - /** - * Handles the "package --rename" command. - * - * @param Args $args The console arguments. - * - * @return int The status code. - */ - public function handleRename(Args $args) - { - $packageName = $args->getArgument('name'); - $newName = $args->getArgument('new-name'); - - $this->packageManager->renamePackage($packageName, $newName); - - return 0; - } - - /** - * Handles the "package --delete" command. - * - * @param Args $args The console arguments. - * - * @return int The status code. - */ - public function handleDelete(Args $args) - { - $packageName = $args->getArgument('name'); - - if (!$this->packageManager->hasPackage($packageName)) { - throw new RuntimeException(sprintf( - 'The package "%s" is not installed.', - $packageName - )); - } - - $this->packageManager->removePackage($packageName); - - return 0; - } - - /** - * Handles the "package --clean" command. - * - * @param Args $args The console arguments. - * @param IO $io The I/O. - * - * @return int The status code. - */ - public function handleClean(Args $args, IO $io) - { - $expr = Expr::method('getState', Expr::same(PackageState::NOT_FOUND)); - - foreach ($this->packageManager->findPackages($expr) as $package) { - $io->writeLine('Removing '.$package->getName()); - $this->packageManager->removePackage($package->getName()); - } - - return 0; - } - - /** - * Returns the package states that should be displayed for the given - * console arguments. - * - * @param Args $args The console arguments. - * - * @return int[] A list of {@link PackageState} constants. - */ - private function getSelectedStates(Args $args) - { - $states = array(); - - if ($args->isOptionSet('enabled')) { - $states[] = PackageState::ENABLED; - } - - if ($args->isOptionSet('not-found')) { - $states[] = PackageState::NOT_FOUND; - } - - if ($args->isOptionSet('not-loadable')) { - $states[] = PackageState::NOT_LOADABLE; - } - - return $states ?: PackageState::all(); - } - - /** - * Returns the packages that should be displayed for the given console - * arguments. - * - * @param Args $args The console arguments. - * - * @return PackageCollection The packages. - */ - private function getSelectedPackages(Args $args) - { - $states = $this->getSelectedStates($args); - $expr = Expr::true(); - $envs = array(); - - if ($states !== PackageState::all()) { - $expr = $expr->andMethod('getState', Expr::in($states)); - } - - if ($args->isOptionSet('installer')) { - $expr = $expr->andMethod('getInstallInfo', Expr::method('getInstallerName', Expr::same($args->getOption('installer')))); - } - - if ($args->isOptionSet('prod')) { - $envs[] = Environment::PROD; - } - - if ($args->isOptionSet('dev')) { - $envs[] = Environment::DEV; - } - - if (count($envs) > 0) { - $expr = $expr->andMethod('getInstallInfo', Expr::method('getEnvironment', Expr::in($envs))); - } - - return $this->packageManager->findPackages($expr); - } - - /** - * Prints packages with intermediate headers for the package states. - * - * @param IO $io The I/O. - * @param PackageCollection $packages The packages to print. - * @param int[] $states The states to print. - */ - private function printPackagesByState(IO $io, PackageCollection $packages, array $states) - { - $printStates = count($states) > 1; - - foreach ($states as $state) { - $filteredPackages = array_filter($packages->toArray(), function (Package $package) use ($state) { - return $state === $package->getState(); - }); - - if (0 === count($filteredPackages)) { - continue; - } - - if ($printStates) { - $this->printPackageState($io, $state); - } - - if (PackageState::NOT_LOADABLE === $state) { - $this->printNotLoadablePackages($io, $filteredPackages, $printStates); - } else { - $styleTag = PackageState::ENABLED === $state ? null : 'bad'; - $this->printPackageTable($io, $filteredPackages, $styleTag, $printStates); - } - - if ($printStates) { - $io->writeLine(''); - } - } - } - - /** - * Prints packages using the given format. - * - * @param IO $io The I/O. - * @param PackageCollection $packages The packages to print. - * @param string $format The format string. - */ - private function printPackagesWithFormat(IO $io, PackageCollection $packages, $format) - { - foreach ($packages as $package) { - $installInfo = $package->getInstallInfo(); - - $io->writeLine(strtr($format, array( - '%name%' => $package->getName(), - '%installer%' => $installInfo ? $installInfo->getInstallerName() : '', - '%install_path%' => $package->getInstallPath(), - '%state%' => self::$stateStrings[$package->getState()], - '%env%' => $installInfo ? $installInfo->getEnvironment() : Environment::PROD, - ))); - } - } - - /** - * Prints the heading for a given package state. - * - * @param IO $io The I/O. - * @param int $packageState The {@link PackageState} constant. - */ - private function printPackageState(IO $io, $packageState) - { - switch ($packageState) { - case PackageState::ENABLED: - $io->writeLine('The following packages are currently enabled:'); - $io->writeLine(''); - - return; - case PackageState::NOT_FOUND: - $io->writeLine('The following packages could not be found:'); - $io->writeLine(' (use "puli package --clean" to remove)'); - $io->writeLine(''); - - return; - case PackageState::NOT_LOADABLE: - $io->writeLine('The following packages could not be loaded:'); - $io->writeLine(''); - - return; - } - } - - /** - * Prints a list of packages in a table. - * - * @param IO $io The I/O. - * @param Package[] $packages The packages. - * @param string|null $styleTag The tag used to style the output. If `null`, - * the default colors are used. - * @param bool $indent Whether to indent the output. - */ - private function printPackageTable(IO $io, array $packages, $styleTag = null, $indent = false) - { - $table = new Table(PuliTableStyle::borderless()); - $table->setHeaderRow(array('Package Name', 'Installer', 'Env', 'Install Path')); - - $installerTag = $styleTag ?: 'c1'; - $envTag = $styleTag ?: 'c1'; - $pathTag = $styleTag ?: 'c2'; - - ksort($packages); - - foreach ($packages as $package) { - $packageName = $package->getName(); - $installInfo = $package->getInstallInfo(); - $installPath = $installInfo ? $installInfo->getInstallPath() : '.'; - $installer = $installInfo ? $installInfo->getInstallerName() : ''; - $env = $installInfo ? $installInfo->getEnvironment() : Environment::PROD; - - $table->addRow(array( - $styleTag ? sprintf('<%s>%s', $styleTag, $packageName, $styleTag) : $packageName, - $installer ? sprintf('<%s>%s', $installerTag, $installer, $installerTag) : '', - sprintf('<%s>%s', $envTag, $env, $envTag), - sprintf('<%s>%s', $pathTag, $installPath, $pathTag), - )); - } - - $table->render($io, $indent ? 4 : 0); - } - - /** - * Prints not-loadable packages in a table. - * - * @param IO $io The I/O. - * @param Package[] $packages The not-loadable packages. - * @param bool $indent Whether to indent the output. - */ - private function printNotLoadablePackages(IO $io, array $packages, $indent = false) - { - $rootDir = $this->packageManager->getContext()->getRootDirectory(); - $table = new Table(PuliTableStyle::borderless()); - $table->setHeaderRow(array('Package Name', 'Error')); - - ksort($packages); - - foreach ($packages as $package) { - $packageName = $package->getName(); - $loadErrors = $package->getLoadErrors(); - $errorMessage = ''; - - foreach ($loadErrors as $loadError) { - $errorMessage .= StringUtil::getShortClassName(get_class($loadError)).': '.$loadError->getMessage()."\n"; - } - - $errorMessage = rtrim($errorMessage); - - if (!$errorMessage) { - $errorMessage = 'Unknown error.'; - } - - // Remove root directory - $errorMessage = str_replace($rootDir.'/', '', $errorMessage); - - $table->addRow(array( - sprintf('%s', $packageName), - sprintf('%s', $errorMessage), - )); - } - - $table->render($io, $indent ? 4 : 0); - } -} diff --git a/src/Handler/PluginCommandHandler.php b/src/Handler/PluginCommandHandler.php index 227979e..9d6b873 100644 --- a/src/Handler/PluginCommandHandler.php +++ b/src/Handler/PluginCommandHandler.php @@ -11,7 +11,7 @@ namespace Puli\Cli\Handler; -use Puli\Manager\Api\Package\RootPackageFileManager; +use Puli\Manager\Api\Module\RootModuleFileManager; use RuntimeException; use Webmozart\Console\Api\Args\Args; use Webmozart\Console\Api\IO\IO; @@ -26,16 +26,16 @@ class PluginCommandHandler { /** - * @var RootPackageFileManager + * @var RootModuleFileManager */ private $manager; /** * Creates the handler. * - * @param RootPackageFileManager $manager The root package file manager. + * @param RootModuleFileManager $manager The root module file manager */ - public function __construct(RootPackageFileManager $manager) + public function __construct(RootModuleFileManager $manager) { $this->manager = $manager; } @@ -43,10 +43,10 @@ public function __construct(RootPackageFileManager $manager) /** * Handles the "puli plugin --list" command. * - * @param Args $args The console arguments. - * @param IO $io The I/O. + * @param Args $args The console arguments + * @param IO $io The I/O * - * @return int The status code. + * @return int The status code */ public function handleList(Args $args, IO $io) { @@ -68,9 +68,9 @@ public function handleList(Args $args, IO $io) /** * Handles the "puli plugin --install" command. * - * @param Args $args The console arguments. + * @param Args $args The console arguments * - * @return int The status code. + * @return int The status code */ public function handleInstall(Args $args) { @@ -91,9 +91,9 @@ public function handleInstall(Args $args) /** * Handles the "puli plugin --remove" command. * - * @param Args $args The console arguments. + * @param Args $args The console arguments * - * @return int The status code. + * @return int The status code */ public function handleDelete(Args $args) { diff --git a/src/Handler/TypeCommandHandler.php b/src/Handler/TypeCommandHandler.php index 32fcaf1..1ea8ac0 100644 --- a/src/Handler/TypeCommandHandler.php +++ b/src/Handler/TypeCommandHandler.php @@ -19,7 +19,7 @@ use Puli\Manager\Api\Discovery\BindingTypeDescriptor; use Puli\Manager\Api\Discovery\BindingTypeState; use Puli\Manager\Api\Discovery\DiscoveryManager; -use Puli\Manager\Api\Package\PackageCollection; +use Puli\Manager\Api\Module\ModuleList; use RuntimeException; use Webmozart\Console\Api\Args\Args; use Webmozart\Console\Api\IO\IO; @@ -41,48 +41,48 @@ class TypeCommandHandler private $discoveryManager; /** - * @var PackageCollection + * @var ModuleList */ - private $packages; + private $modules; /** * Creates the handler. * - * @param DiscoveryManager $discoveryManager The discovery manager. - * @param PackageCollection $packages The loaded packages. + * @param DiscoveryManager $discoveryManager The discovery manager + * @param ModuleList $modules The loaded modules */ - public function __construct(DiscoveryManager $discoveryManager, PackageCollection $packages) + public function __construct(DiscoveryManager $discoveryManager, ModuleList $modules) { $this->discoveryManager = $discoveryManager; - $this->packages = $packages; + $this->modules = $modules; } /** * Handles the "puli type --list" command. * - * @param Args $args The console arguments. - * @param IO $io The I/O. + * @param Args $args The console arguments + * @param IO $io The I/O * - * @return int The status code. + * @return int The status code */ public function handleList(Args $args, IO $io) { - $packageNames = ArgsUtil::getPackageNames($args, $this->packages); + $moduleNames = ArgsUtil::getModuleNames($args, $this->modules); $states = $this->getBindingTypeStates($args); $printStates = count($states) > 1; - $printPackageName = count($packageNames) > 1; - $printHeaders = $printStates || $printPackageName; + $printModuleName = count($moduleNames) > 1; + $printHeaders = $printStates || $printModuleName; $printTypeAdvice = true; $printBindAdvice = false; - $indentation = $printStates && $printPackageName ? 8 - : ($printStates || $printPackageName ? 4 : 0); + $indentation = $printStates && $printModuleName ? 8 + : ($printStates || $printModuleName ? 4 : 0); foreach ($states as $state) { $statePrinted = !$printStates; - foreach ($packageNames as $packageName) { - $expr = Expr::method('getContainingPackage', Expr::method('getName', Expr::same($packageName))) + foreach ($moduleNames as $moduleName) { + $expr = Expr::method('getContainingModule', Expr::method('getName', Expr::same($moduleName))) ->andMethod('getState', Expr::same($state)); $bindingTypes = $this->discoveryManager->findTypeDescriptors($expr); @@ -101,9 +101,9 @@ public function handleList(Args $args, IO $io) $printBindAdvice = true; } - if ($printPackageName) { + if ($printModuleName) { $prefix = $printStates ? ' ' : ''; - $io->writeLine("{$prefix}Package: $packageName"); + $io->writeLine("{$prefix}Module: $moduleName"); $io->writeLine(''); } @@ -130,9 +130,9 @@ public function handleList(Args $args, IO $io) /** * Handles the "puli type --define" command. * - * @param Args $args The console arguments. + * @param Args $args The console arguments * - * @return int The status code. + * @return int The status code */ public function handleDefine(Args $args) { @@ -155,9 +155,9 @@ public function handleDefine(Args $args) /** * Handles the "puli type --update" command. * - * @param Args $args The console arguments. + * @param Args $args The console arguments * - * @return int The status code. + * @return int The status code */ public function handleUpdate(Args $args) { @@ -193,9 +193,9 @@ public function handleUpdate(Args $args) /** * Handles the "puli type --delete" command. * - * @param Args $args The console arguments. + * @param Args $args The console arguments * - * @return int The status code. + * @return int The status code */ public function handleDelete(Args $args) { @@ -203,9 +203,9 @@ public function handleDelete(Args $args) if (!$this->discoveryManager->hasRootTypeDescriptor($typeName)) { throw new RuntimeException(sprintf( - 'The type "%s" does not exist in the package "%s".', + 'The type "%s" does not exist in the module "%s".', $typeName, - $this->packages->getRootPackageName() + $this->modules->getRootModuleName() )); } @@ -217,9 +217,9 @@ public function handleDelete(Args $args) /** * Returns the binding type states selected in the console arguments. * - * @param Args $args The console arguments. + * @param Args $args The console arguments * - * @return int[] A list of {@link BindingTypeState} constants. + * @return int[] A list of {@link BindingTypeState} constants */ private function getBindingTypeStates(Args $args) { @@ -239,10 +239,10 @@ private function getBindingTypeStates(Args $args) /** * Prints the binding types in a table. * - * @param IO $io The I/O. - * @param BindingTypeDescriptor[] $descriptors The type descriptors to print. + * @param IO $io The I/O + * @param BindingTypeDescriptor[] $descriptors The type descriptors to print * @param string $styleTag The tag used to style the output - * @param int $indentation The number of spaces to indent. + * @param int $indentation The number of spaces to indent */ private function printTypeTable(IO $io, array $descriptors, $styleTag = null, $indentation = 0) { @@ -286,8 +286,8 @@ private function printTypeTable(IO $io, array $descriptors, $styleTag = null, $i /** * Prints the heading for a binding type state. * - * @param IO $io The I/O. - * @param int $typeState The {@link BindingTypeState} constant. + * @param IO $io The I/O + * @param int $typeState The {@link BindingTypeState} constant */ private function printBindingTypeState(IO $io, $typeState) { diff --git a/src/Handler/UpgradeCommandHandler.php b/src/Handler/UpgradeCommandHandler.php index 8433555..e95f486 100644 --- a/src/Handler/UpgradeCommandHandler.php +++ b/src/Handler/UpgradeCommandHandler.php @@ -11,7 +11,7 @@ namespace Puli\Cli\Handler; -use Puli\Manager\Api\Package\RootPackageFileManager; +use Puli\Manager\Api\Module\RootModuleFileManager; use Webmozart\Console\Api\Args\Args; use Webmozart\Console\Api\IO\IO; @@ -25,33 +25,33 @@ class UpgradeCommandHandler { /** - * @var RootPackageFileManager + * @var RootModuleFileManager */ - private $packageFileManager; + private $moduleFileManager; /** * Creates the command handler. * - * @param RootPackageFileManager $packageFileManager The manager of the - * puli.json file. + * @param RootModuleFileManager $moduleFileManager The manager of the + * puli.json file */ - public function __construct(RootPackageFileManager $packageFileManager) + public function __construct(RootModuleFileManager $moduleFileManager) { - $this->packageFileManager = $packageFileManager; + $this->moduleFileManager = $moduleFileManager; } /** * Handles the "upgrade" command. * - * @param Args $args The console arguments. - * @param IO $io The I/O. + * @param Args $args The console arguments + * @param IO $io The I/O * - * @return int The status code. + * @return int The status code */ public function handle(Args $args, IO $io) { - $packageFile = $this->packageFileManager->getPackageFile(); - $originVersion = $packageFile->getVersion(); + $moduleFile = $this->moduleFileManager->getModuleFile(); + $originVersion = $moduleFile->getVersion(); $targetVersion = $args->getArgument('version'); if (version_compare($originVersion, $targetVersion, '=')) { @@ -60,7 +60,7 @@ public function handle(Args $args, IO $io) return 0; } - $this->packageFileManager->migrate($targetVersion); + $this->moduleFileManager->migrate($targetVersion); $io->writeLine(sprintf( 'Migrated your puli.json from version %s to version %s.', diff --git a/src/Proxy/DiscoveryManagerProxy.php b/src/Proxy/DiscoveryManagerProxy.php index 5f0b330..4634959 100644 --- a/src/Proxy/DiscoveryManagerProxy.php +++ b/src/Proxy/DiscoveryManagerProxy.php @@ -11,10 +11,10 @@ namespace Puli\Cli\Proxy; +use Puli\Manager\Api\Container; use Puli\Manager\Api\Discovery\BindingDescriptor; use Puli\Manager\Api\Discovery\BindingTypeDescriptor; use Puli\Manager\Api\Discovery\DiscoveryManager; -use Puli\Manager\Api\Puli; use Rhumsaa\Uuid\Uuid; use Webmozart\Expression\Expression; @@ -28,17 +28,17 @@ class DiscoveryManagerProxy implements DiscoveryManager { /** - * @var Puli + * @var Container */ private $puli; /** * Creates the proxy. * - * @param Puli $puli The service locator to fetch the actual discovery - * manager from. + * @param Container $puli The service locator to fetch the actual discovery + * manager from */ - public function __construct(Puli $puli) + public function __construct(Container $puli) { $this->puli = $puli; } @@ -126,9 +126,9 @@ public function hasRootTypeDescriptors(Expression $expr = null) /** * {@inheritdoc} */ - public function getTypeDescriptor($typeName, $packageName) + public function getTypeDescriptor($typeName, $moduleName) { - return $this->puli->getDiscoveryManager()->getTypeDescriptor($typeName, $packageName); + return $this->puli->getDiscoveryManager()->getTypeDescriptor($typeName, $moduleName); } /** @@ -150,9 +150,9 @@ public function findTypeDescriptors(Expression $expr) /** * {@inheritdoc} */ - public function hasTypeDescriptor($typeName, $packageName = null) + public function hasTypeDescriptor($typeName, $moduleName = null) { - return $this->puli->getDiscoveryManager()->hasTypeDescriptor($typeName, $packageName); + return $this->puli->getDiscoveryManager()->hasTypeDescriptor($typeName, $moduleName); } /** diff --git a/src/Proxy/RepositoryManagerProxy.php b/src/Proxy/RepositoryManagerProxy.php index 1d83971..0918c00 100644 --- a/src/Proxy/RepositoryManagerProxy.php +++ b/src/Proxy/RepositoryManagerProxy.php @@ -11,7 +11,7 @@ namespace Puli\Cli\Proxy; -use Puli\Manager\Api\Puli; +use Puli\Manager\Api\Container; use Puli\Manager\Api\Repository\PathMapping; use Puli\Manager\Api\Repository\RepositoryManager; use Webmozart\Expression\Expression; @@ -26,17 +26,17 @@ class RepositoryManagerProxy implements RepositoryManager { /** - * @var Puli + * @var Container */ private $puli; /** * Creates the proxy. * - * @param Puli $puli The service locator to fetch the actual repository - * manager from. + * @param Container $puli The service locator to fetch the actual repository + * manager from */ - public function __construct(Puli $puli) + public function __construct(Container $puli) { $this->puli = $puli; } @@ -132,9 +132,9 @@ public function hasRootPathMappings(Expression $expr = null) /** * {@inheritdoc} */ - public function getPathMapping($repositoryPath, $packageName) + public function getPathMapping($repositoryPath, $moduleName) { - return $this->puli->getRepositoryManager()->getPathMapping($repositoryPath, $packageName); + return $this->puli->getRepositoryManager()->getPathMapping($repositoryPath, $moduleName); } /** @@ -156,9 +156,9 @@ public function findPathMappings(Expression $expr) /** * {@inheritdoc} */ - public function hasPathMapping($repositoryPath, $packageName) + public function hasPathMapping($repositoryPath, $moduleName) { - return $this->puli->getRepositoryManager()->hasPathMapping($repositoryPath, $packageName); + return $this->puli->getRepositoryManager()->hasPathMapping($repositoryPath, $moduleName); } /** diff --git a/src/PuliApplicationConfig.php b/src/PuliApplicationConfig.php index 6471cbf..488c1d1 100644 --- a/src/PuliApplicationConfig.php +++ b/src/PuliApplicationConfig.php @@ -19,7 +19,7 @@ use Puli\Cli\Handler\InstallerCommandHandler; use Puli\Cli\Handler\LsCommandHandler; use Puli\Cli\Handler\MapCommandHandler; -use Puli\Cli\Handler\PackageCommandHandler; +use Puli\Cli\Handler\ModuleCommandHandler; use Puli\Cli\Handler\PluginCommandHandler; use Puli\Cli\Handler\PublishCommandHandler; use Puli\Cli\Handler\SelfUpdateCommandHandler; @@ -30,11 +30,11 @@ use Puli\Cli\Handler\UrlCommandHandler; use Puli\Cli\Proxy\DiscoveryManagerProxy; use Puli\Cli\Proxy\RepositoryManagerProxy; +use Puli\Manager\Api\Container; use Puli\Manager\Api\Context\ProjectContext; -use Puli\Manager\Api\Package\InstallInfo; -use Puli\Manager\Api\Package\PackageFile; -use Puli\Manager\Api\Puli; +use Puli\Manager\Api\Module\InstallInfo; use Puli\Manager\Api\Server\Server; +use Puli\Manager\Module\ModuleFileConverter; use Webmozart\Console\Api\Args\Format\Argument; use Webmozart\Console\Api\Args\Format\Option; use Webmozart\Console\Api\Event\ConsoleEvents; @@ -58,19 +58,19 @@ class PuliApplicationConfig extends DefaultApplicationConfig const VERSION = '@package_version@'; /** - * @var Puli + * @var Container */ private $puli; /** * Creates the configuration. * - * @param Puli $puli The Puli service container. + * @param Container $puli The Puli service container */ - public function __construct(Puli $puli = null) + public function __construct(Container $puli = null) { // Start Puli already so that plugins can change the CLI configuration - $this->puli = $puli ?: new Puli(getcwd()); + $this->puli = $puli ?: new Container(getcwd()); if (!$this->puli->isStarted()) { $this->puli->start(); @@ -114,21 +114,21 @@ protected function configure() ConsoleEvents::PRE_HANDLE, function (PreHandleEvent $event) use ($context) { $io = $event->getIO(); - $packageFile = $context->getRootPackageFile(); + $moduleFile = $context->getRootModuleFile(); // Don't show warning for "upgrade" command if ('upgrade' === $event->getCommand()->getName()) { return; } - if (version_compare($packageFile->getVersion(), PackageFile::DEFAULT_VERSION, '<')) { + if (version_compare($moduleFile->getVersion(), ModuleFileConverter::VERSION, '<')) { $io->errorLine(sprintf( 'Warning: Your puli.json file has version %s, '. 'but the latest version is %s. Run "puli upgrade" to '. 'upgrade to %s.', - $packageFile->getVersion(), - PackageFile::DEFAULT_VERSION, - PackageFile::DEFAULT_VERSION + $moduleFile->getVersion(), + ModuleFileConverter::VERSION, + ModuleFileConverter::VERSION )); } } @@ -141,7 +141,7 @@ function (PreHandleEvent $event) use ($context) { ->setHandler(function () use ($puli) { return new BindCommandHandler( $puli->getDiscoveryManager(), - $puli->getPackageManager()->getPackages() + $puli->getModuleManager()->getModules() ); }) @@ -158,9 +158,9 @@ function (PreHandleEvent $event) use ($context) { ->beginOptionCommand('list') ->markDefault() - ->addOption('root', null, Option::NO_VALUE, 'Show bindings of the root package') - ->addOption('package', 'p', Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'Show bindings of a package', null, 'package') - ->addOption('all', 'a', Option::NO_VALUE, 'Show bindings of all packages') + ->addOption('root', null, Option::NO_VALUE, 'Show bindings of the root module') + ->addOption('module', 'm', Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'Show bindings of a module', null, 'module') + ->addOption('all', 'a', Option::NO_VALUE, 'Show bindings of all modules') ->addOption('enabled', null, Option::NO_VALUE, 'Show enabled bindings') ->addOption('disabled', null, Option::NO_VALUE, 'Show disabled bindings') ->addOption('type-not-found', null, Option::NO_VALUE, 'Show bindings whose type is not found') @@ -234,7 +234,7 @@ function (PreHandleEvent $event) use ($context) { ->beginCommand('config') ->setDescription('Display and modify configuration values') ->setHandler(function () use ($puli) { - return new ConfigCommandHandler($puli->getRootPackageFileManager()); + return new ConfigCommandHandler($puli->getRootModuleFileManager()); }) ->beginSubCommand('list') @@ -328,7 +328,7 @@ function (PreHandleEvent $event) use ($context) { ->setHandler(function () use ($puli) { return new MapCommandHandler( $puli->getRepositoryManager(), - $puli->getPackageManager()->getPackages() + $puli->getModuleManager()->getModules() ); }) @@ -342,9 +342,9 @@ function (PreHandleEvent $event) use ($context) { ->beginOptionCommand('list') ->markDefault() - ->addOption('root', null, Option::NO_VALUE, 'Show mappings of the root package') - ->addOption('package', 'p', Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'Show mappings of a package', null, 'package') - ->addOption('all', 'a', Option::NO_VALUE, 'Show mappings of all packages') + ->addOption('root', null, Option::NO_VALUE, 'Show mappings of the root module') + ->addOption('module', 'm', Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'Show mappings of a module', null, 'module') + ->addOption('all', 'a', Option::NO_VALUE, 'Show mappings of all modules') ->addOption('enabled', null, Option::NO_VALUE, 'Show enabled mappings') ->addOption('not-found', null, Option::NO_VALUE, 'Show mappings whose referenced paths do not exist') ->addOption('conflict', null, Option::NO_VALUE, 'Show conflicting mappings') @@ -368,40 +368,40 @@ function (PreHandleEvent $event) use ($context) { ; $this - ->beginCommand('package') - ->setDescription('Display the installed packages') + ->beginCommand('module') + ->setDescription('Display the installed modules') ->setHandler(function () use ($puli) { - return new PackageCommandHandler($puli->getPackageManager()); + return new ModuleCommandHandler($puli->getModuleManager()); }) ->beginOptionCommand('install', 'i') - ->addArgument('path', Argument::REQUIRED, 'The path to the package') - ->addArgument('name', Argument::OPTIONAL, 'The name of the package. Taken from puli.json if not passed.') + ->addArgument('path', Argument::REQUIRED, 'The path to the module') + ->addArgument('name', Argument::OPTIONAL, 'The name of the module. Taken from puli.json if not passed.') ->addOption('installer', null, Option::REQUIRED_VALUE, 'The name of the installer', InstallInfo::DEFAULT_INSTALLER_NAME) - ->addOption('dev', null, Option::NO_VALUE, 'Install the package in the development environment') + ->addOption('dev', null, Option::NO_VALUE, 'Install the module in the development environment') ->setHandlerMethod('handleInstall') ->end() ->beginOptionCommand('list') ->markDefault() - ->addOption('installer', null, Option::REQUIRED_VALUE, 'Show packages installed by a specific installer') - ->addOption('enabled', null, Option::NO_VALUE, 'Show enabled packages') - ->addOption('not-found', null, Option::NO_VALUE, 'Show packages that could not be found') - ->addOption('not-loadable', null, Option::NO_VALUE, 'Show packages that could not be loaded') - ->addOption('dev', null, Option::NO_VALUE, 'Show packages of the development environment') - ->addOption('prod', null, Option::NO_VALUE, 'Show packages of the production environment') + ->addOption('installer', null, Option::REQUIRED_VALUE, 'Show modules installed by a specific installer') + ->addOption('enabled', null, Option::NO_VALUE, 'Show enabled modules') + ->addOption('not-found', null, Option::NO_VALUE, 'Show modules that could not be found') + ->addOption('not-loadable', null, Option::NO_VALUE, 'Show modules that could not be loaded') + ->addOption('dev', null, Option::NO_VALUE, 'Show modules of the development environment') + ->addOption('prod', null, Option::NO_VALUE, 'Show modules of the production environment') ->addOption('format', null, Option::REQUIRED_VALUE, 'The format of the output. You can use the variables %name%, %install_path%, %installer% and %state% in the format string', null, 'format') ->setHandlerMethod('handleList') ->end() ->beginOptionCommand('rename') - ->addArgument('name', Argument::REQUIRED, 'The name of the package') - ->addArgument('new-name', Argument::REQUIRED, 'The new name of the package') + ->addArgument('name', Argument::REQUIRED, 'The name of the module') + ->addArgument('new-name', Argument::REQUIRED, 'The new name of the module') ->setHandlerMethod('handleRename') ->end() ->beginOptionCommand('delete', 'd') - ->addArgument('name', Argument::REQUIRED, 'The name of the package') + ->addArgument('name', Argument::REQUIRED, 'The name of the module') ->setHandlerMethod('handleDelete') ->end() @@ -415,7 +415,7 @@ function (PreHandleEvent $event) use ($context) { ->beginCommand('plugin') ->setDescription('Manage the installed Puli plugins') ->setHandler(function () use ($puli) { - return new PluginCommandHandler($puli->getRootPackageFileManager()); + return new PluginCommandHandler($puli->getRootModuleFileManager()); }) ->beginOptionCommand('install', 'i') @@ -547,7 +547,7 @@ function (PreHandleEvent $event) use ($context) { ->setHandler(function () use ($puli) { return new TypeCommandHandler( $puli->getDiscoveryManager(), - $puli->getPackageManager()->getPackages() + $puli->getModuleManager()->getModules() ); }) @@ -562,9 +562,9 @@ function (PreHandleEvent $event) use ($context) { ->beginSubCommand('list') ->markDefault() - ->addOption('root', null, Option::NO_VALUE, 'Show types of the root package') - ->addOption('package', 'p', Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'Show types of a package', null, 'package') - ->addOption('all', 'a', Option::NO_VALUE, 'Show types of all packages') + ->addOption('root', null, Option::NO_VALUE, 'Show types of the root module') + ->addOption('module', 'm', Option::REQUIRED_VALUE | Option::MULTI_VALUED, 'Show types of a module', null, 'module') + ->addOption('all', 'a', Option::NO_VALUE, 'Show types of all modules') ->addOption('enabled', null, Option::NO_VALUE, 'Show enabled types') ->addOption('duplicate', null, Option::NO_VALUE, 'Show duplicate types') ->setHandlerMethod('handleList') @@ -589,9 +589,9 @@ function (PreHandleEvent $event) use ($context) { $this ->beginCommand('upgrade') ->setDescription('Upgrades puli.json to the newest version') - ->addArgument('version', Argument::OPTIONAL, 'The version to upgrade/downgrade to', PackageFile::DEFAULT_VERSION) + ->addArgument('version', Argument::OPTIONAL, 'The version to upgrade/downgrade to', ModuleFileConverter::VERSION) ->setHandler(function () use ($puli) { - return new UpgradeCommandHandler($puli->getRootPackageFileManager()); + return new UpgradeCommandHandler($puli->getRootModuleFileManager()); }) ->end() ; diff --git a/src/Util/ArgsUtil.php b/src/Util/ArgsUtil.php index 4437dea..8ab3d6e 100644 --- a/src/Util/ArgsUtil.php +++ b/src/Util/ArgsUtil.php @@ -11,7 +11,7 @@ namespace Puli\Cli\Util; -use Puli\Manager\Api\Package\PackageCollection; +use Puli\Manager\Api\Module\ModuleList; use Webmozart\Console\Api\Args\Args; /** @@ -24,55 +24,55 @@ class ArgsUtil { /** - * Returns the packages selected in the console arguments. + * Returns the modules selected in the console arguments. * - * @param Args $args The console arguments. - * @param PackageCollection $packages The available packages. + * @param Args $args The console arguments + * @param ModuleList $modules The available modules * - * @return string[] The package names. + * @return string[] The module names */ - public static function getPackageNames(Args $args, PackageCollection $packages) + public static function getModuleNames(Args $args, ModuleList $modules) { - // Display all packages if "all" is set + // Display all modules if "all" is set if ($args->isOptionSet('all')) { - return $packages->getPackageNames(); + return $modules->getModuleNames(); } - $packageNames = array(); + $moduleNames = array(); if ($args->isOptionSet('root')) { - $packageNames[] = $packages->getRootPackage()->getName(); + $moduleNames[] = $modules->getRootModuleName(); } - foreach ($args->getOption('package') as $packageName) { - $packageNames[] = $packageName; + foreach ($args->getOption('module') as $moduleName) { + $moduleNames[] = $moduleName; } - return $packageNames ?: $packages->getPackageNames(); + return $moduleNames ?: $modules->getModuleNames(); } /** - * Returns the non-root packages selected in the console arguments. + * Returns the non-root modules selected in the console arguments. * - * @param Args $args The console arguments. - * @param PackageCollection $packages The available packages. + * @param Args $args The console arguments + * @param ModuleList $modules The available modules * - * @return string[] The package names. + * @return string[] The module names */ - public static function getPackageNamesWithoutRoot(Args $args, PackageCollection $packages) + public static function getModuleNamesWithoutRoot(Args $args, ModuleList $modules) { - // Display all packages if "all" is set + // Display all modules if "all" is set if ($args->isOptionSet('all')) { - return $packages->getInstalledPackageNames(); + return $modules->getInstalledModuleNames(); } - $packageNames = array(); + $moduleNames = array(); - foreach ($args->getOption('package') as $packageName) { - $packageNames[] = $packageName; + foreach ($args->getOption('module') as $moduleName) { + $moduleNames[] = $moduleName; } - return $packageNames ?: $packages->getInstalledPackageNames(); + return $moduleNames ?: $modules->getInstalledModuleNames(); } private function __construct() diff --git a/tests/Fixtures/root/puli.json b/tests/Fixtures/root/puli.json index c309212..878418b 100644 --- a/tests/Fixtures/root/puli.json +++ b/tests/Fixtures/root/puli.json @@ -1,5 +1,5 @@ { - "version": "1.0", + "$schema": "http://puli.io/schema/2.0/manager/module#", "packages": { "puli/url-generator": { "install-path": "vendor/puli/url-generator" diff --git a/tests/Handler/AbstractCommandHandlerTest.php b/tests/Handler/AbstractCommandHandlerTest.php index b680cb5..8ebd8f1 100644 --- a/tests/Handler/AbstractCommandHandlerTest.php +++ b/tests/Handler/AbstractCommandHandlerTest.php @@ -14,7 +14,7 @@ use PHPUnit_Framework_TestCase; use Puli\Cli\PuliApplicationConfig; use Puli\Cli\Tests\Handler\Util\NormalizedLineEndingsIO; -use Puli\Manager\Api\Puli; +use Puli\Manager\Api\Container; use Webmozart\Console\Api\Application\Application; use Webmozart\Console\Api\Formatter\Formatter; use Webmozart\Console\ConsoleApplication; @@ -51,7 +51,7 @@ abstract class AbstractCommandHandlerTest extends PHPUnit_Framework_TestCase public static function setUpBeforeClass() { self::$tempDir = TestUtil::makeTempDir('puli-cli', __CLASS__); - self::$application = new ConsoleApplication(new PuliApplicationConfig(new Puli(self::$tempDir))); + self::$application = new ConsoleApplication(new PuliApplicationConfig(new Container(self::$tempDir))); self::$formatter = new PlainFormatter(self::$application->getConfig()->getStyleSet()); } diff --git a/tests/Handler/BindCommandHandlerTest.php b/tests/Handler/BindCommandHandlerTest.php index b9f3a7d..67af2f8 100644 --- a/tests/Handler/BindCommandHandlerTest.php +++ b/tests/Handler/BindCommandHandlerTest.php @@ -21,11 +21,11 @@ use Puli\Manager\Api\Discovery\BindingDescriptor; use Puli\Manager\Api\Discovery\BindingState; use Puli\Manager\Api\Discovery\DiscoveryManager; -use Puli\Manager\Api\Package\Package; -use Puli\Manager\Api\Package\PackageCollection; -use Puli\Manager\Api\Package\PackageFile; -use Puli\Manager\Api\Package\RootPackage; -use Puli\Manager\Api\Package\RootPackageFile; +use Puli\Manager\Api\Module\Module; +use Puli\Manager\Api\Module\ModuleFile; +use Puli\Manager\Api\Module\ModuleList; +use Puli\Manager\Api\Module\RootModule; +use Puli\Manager\Api\Module\RootModuleFile; use Rhumsaa\Uuid\Uuid; use Webmozart\Console\Api\Command\Command; use Webmozart\Console\Args\StringArgs; @@ -95,9 +95,9 @@ class BindCommandHandlerTest extends AbstractCommandHandlerTest private $discoveryManager; /** - * @var PackageCollection + * @var ModuleList */ - private $packages; + private $modules; /** * @var BindCommandHandler @@ -121,12 +121,12 @@ protected function setUp() parent::setUp(); $this->discoveryManager = $this->getMock('Puli\Manager\Api\Discovery\DiscoveryManager'); - $this->packages = new PackageCollection(array( - new RootPackage(new RootPackageFile('vendor/root'), '/root'), - new Package(new PackageFile('vendor/package1'), '/package1'), - new Package(new PackageFile('vendor/package2'), '/package2'), + $this->modules = new ModuleList(array( + new RootModule(new RootModuleFile('vendor/root'), '/root'), + new Module(new ModuleFile('vendor/module1'), '/module1'), + new Module(new ModuleFile('vendor/module2'), '/module2'), )); - $this->handler = new BindCommandHandler($this->discoveryManager, $this->packages); + $this->handler = new BindCommandHandler($this->discoveryManager, $this->modules); } public function testListAllBindings() @@ -138,94 +138,94 @@ public function testListAllBindings() $expected = <<<'EOF' The following bindings are currently enabled: - Package: vendor/root + Module: vendor/root UUID Glob Type bb5a07 /root/enabled Foo cc9f22 /overridden Foo 47491d BindCommandHandlerTest Bar - Package: vendor/package1 + Module: vendor/module1 - UUID Glob Type - 970aba /package1/enabled Foo + UUID Glob Type + 970aba /module1/enabled Foo - Package: vendor/package2 + Module: vendor/module2 - UUID Glob Type - ddb655 /package2/enabled Foo + UUID Glob Type + ddb655 /module2/enabled Foo The following bindings are disabled: (use "puli bind --enable " to enable) - Package: vendor/root + Module: vendor/root UUID Glob Type 9ac78a /root/disabled Foo - Package: vendor/package1 + Module: vendor/module1 - UUID Glob Type - a0b6c7 /package1/disabled Foo + UUID Glob Type + a0b6c7 /module1/disabled Foo - Package: vendor/package2 + Module: vendor/module2 - UUID Glob Type - 424d68 /package2/disabled Foo + UUID Glob Type + 424d68 /module2/disabled Foo The types of the following bindings could not be found: (install or create their type definitions to enable) - Package: vendor/root + Module: vendor/root UUID Glob Type d0e980 /root/type-not-found Foo - Package: vendor/package1 + Module: vendor/module1 - UUID Glob Type - 19b069 /package1/type-not-found Foo + UUID Glob Type + 19b069 /module1/type-not-found Foo - Package: vendor/package2 + Module: vendor/module2 - UUID Glob Type - b7b2c3 /package2/type-not-found Foo + UUID Glob Type + b7b2c3 /module2/type-not-found Foo The types of the following bindings are not enabled: (remove the duplicate type definitions to enable) - Package: vendor/root + Module: vendor/root UUID Glob Type 47491d /root/type-not-enabled Foo - Package: vendor/package1 + Module: vendor/module1 - UUID Glob Type - 7d26ae /package1/type-not-enable Foo + UUID Glob Type + 7d26ae /module1/type-not-enable Foo - Package: vendor/package2 + Module: vendor/module2 - UUID Glob Type - 53e67c /package2/type-not-enabled Foo + UUID Glob Type + 53e67c /module2/type-not-enabled Foo The following bindings have invalid parameters: (remove the binding and add again with correct parameters) - Package: vendor/root + Module: vendor/root UUID Glob Type d06707 /root/invalid Foo - Package: vendor/package1 + Module: vendor/module1 - UUID Glob Type - dd7458 /package1/invalid Foo + UUID Glob Type + dd7458 /module1/invalid Foo - Package: vendor/package2 + Module: vendor/module2 - UUID Glob Type - 24213c /package2/invalid Foo + UUID Glob Type + 24213c /module2/invalid Foo EOF; @@ -281,41 +281,41 @@ public function testListRootBindings() $this->assertEmpty($this->io->fetchErrors()); } - public function testListPackageBindings() + public function testListModuleBindings() { $this->initDefaultBindings(); - $args = self::$listCommand->parseArgs(new StringArgs('--package=vendor/package1')); + $args = self::$listCommand->parseArgs(new StringArgs('--module=vendor/module1')); $expected = <<<'EOF' The following bindings are currently enabled: - UUID Glob Type - 970aba /package1/enabled Foo + UUID Glob Type + 970aba /module1/enabled Foo The following bindings are disabled: (use "puli bind --enable " to enable) - UUID Glob Type - a0b6c7 /package1/disabled Foo + UUID Glob Type + a0b6c7 /module1/disabled Foo The types of the following bindings could not be found: (install or create their type definitions to enable) - UUID Glob Type - 19b069 /package1/type-not-found Foo + UUID Glob Type + 19b069 /module1/type-not-found Foo The types of the following bindings are not enabled: (remove the duplicate type definitions to enable) - UUID Glob Type - 7d26ae /package1/type-not-enable Foo + UUID Glob Type + 7d26ae /module1/type-not-enable Foo The following bindings have invalid parameters: (remove the binding and add again with correct parameters) - UUID Glob Type - dd7458 /package1/invalid Foo + UUID Glob Type + dd7458 /module1/invalid Foo EOF; @@ -325,78 +325,78 @@ public function testListPackageBindings() $this->assertEmpty($this->io->fetchErrors()); } - public function testListRootAndPackageBindings() + public function testListRootAndModuleBindings() { $this->initDefaultBindings(); - $args = self::$listCommand->parseArgs(new StringArgs('--root --package=vendor/package1')); + $args = self::$listCommand->parseArgs(new StringArgs('--root --module=vendor/module1')); $expected = <<<'EOF' The following bindings are currently enabled: - Package: vendor/root + Module: vendor/root UUID Glob Type bb5a07 /root/enabled Foo cc9f22 /overridden Foo 47491d BindCommandHandlerTest Bar - Package: vendor/package1 + Module: vendor/module1 - UUID Glob Type - 970aba /package1/enabled Foo + UUID Glob Type + 970aba /module1/enabled Foo The following bindings are disabled: (use "puli bind --enable " to enable) - Package: vendor/root + Module: vendor/root UUID Glob Type 9ac78a /root/disabled Foo - Package: vendor/package1 + Module: vendor/module1 - UUID Glob Type - a0b6c7 /package1/disabled Foo + UUID Glob Type + a0b6c7 /module1/disabled Foo The types of the following bindings could not be found: (install or create their type definitions to enable) - Package: vendor/root + Module: vendor/root UUID Glob Type d0e980 /root/type-not-found Foo - Package: vendor/package1 + Module: vendor/module1 - UUID Glob Type - 19b069 /package1/type-not-found Foo + UUID Glob Type + 19b069 /module1/type-not-found Foo The types of the following bindings are not enabled: (remove the duplicate type definitions to enable) - Package: vendor/root + Module: vendor/root UUID Glob Type 47491d /root/type-not-enabled Foo - Package: vendor/package1 + Module: vendor/module1 - UUID Glob Type - 7d26ae /package1/type-not-enable Foo + UUID Glob Type + 7d26ae /module1/type-not-enable Foo The following bindings have invalid parameters: (remove the binding and add again with correct parameters) - Package: vendor/root + Module: vendor/root UUID Glob Type d06707 /root/invalid Foo - Package: vendor/package1 + Module: vendor/module1 - UUID Glob Type - dd7458 /package1/invalid Foo + UUID Glob Type + dd7458 /module1/invalid Foo EOF; @@ -406,76 +406,76 @@ public function testListRootAndPackageBindings() $this->assertEmpty($this->io->fetchErrors()); } - public function testListMultiplePackageBindings() + public function testListMultipleModuleBindings() { $this->initDefaultBindings(); - $args = self::$listCommand->parseArgs(new StringArgs('--package=vendor/package1 --package=vendor/package2')); + $args = self::$listCommand->parseArgs(new StringArgs('--module=vendor/module1 --module=vendor/module2')); $expected = <<<'EOF' The following bindings are currently enabled: - Package: vendor/package1 + Module: vendor/module1 - UUID Glob Type - 970aba /package1/enabled Foo + UUID Glob Type + 970aba /module1/enabled Foo - Package: vendor/package2 + Module: vendor/module2 - UUID Glob Type - ddb655 /package2/enabled Foo + UUID Glob Type + ddb655 /module2/enabled Foo The following bindings are disabled: (use "puli bind --enable " to enable) - Package: vendor/package1 + Module: vendor/module1 - UUID Glob Type - a0b6c7 /package1/disabled Foo + UUID Glob Type + a0b6c7 /module1/disabled Foo - Package: vendor/package2 + Module: vendor/module2 - UUID Glob Type - 424d68 /package2/disabled Foo + UUID Glob Type + 424d68 /module2/disabled Foo The types of the following bindings could not be found: (install or create their type definitions to enable) - Package: vendor/package1 + Module: vendor/module1 - UUID Glob Type - 19b069 /package1/type-not-found Foo + UUID Glob Type + 19b069 /module1/type-not-found Foo - Package: vendor/package2 + Module: vendor/module2 - UUID Glob Type - b7b2c3 /package2/type-not-found Foo + UUID Glob Type + b7b2c3 /module2/type-not-found Foo The types of the following bindings are not enabled: (remove the duplicate type definitions to enable) - Package: vendor/package1 + Module: vendor/module1 - UUID Glob Type - 7d26ae /package1/type-not-enable Foo + UUID Glob Type + 7d26ae /module1/type-not-enable Foo - Package: vendor/package2 + Module: vendor/module2 - UUID Glob Type - 53e67c /package2/type-not-enabled Foo + UUID Glob Type + 53e67c /module2/type-not-enabled Foo The following bindings have invalid parameters: (remove the binding and add again with correct parameters) - Package: vendor/package1 + Module: vendor/module1 - UUID Glob Type - dd7458 /package1/invalid Foo + UUID Glob Type + dd7458 /module1/invalid Foo - Package: vendor/package2 + Module: vendor/module2 - UUID Glob Type - 24213c /package2/invalid Foo + UUID Glob Type + 24213c /module2/invalid Foo EOF; @@ -492,22 +492,22 @@ public function testListEnabledBindings() $args = self::$listCommand->parseArgs(new StringArgs('--enabled')); $expected = <<<'EOF' -Package: vendor/root +Module: vendor/root UUID Glob Type bb5a07 /root/enabled Foo cc9f22 /overridden Foo 47491d BindCommandHandlerTest Bar -Package: vendor/package1 +Module: vendor/module1 - UUID Glob Type - 970aba /package1/enabled Foo + UUID Glob Type + 970aba /module1/enabled Foo -Package: vendor/package2 +Module: vendor/module2 - UUID Glob Type - ddb655 /package2/enabled Foo + UUID Glob Type + ddb655 /module2/enabled Foo EOF; @@ -524,20 +524,20 @@ public function testListDisabledBindings() $args = self::$listCommand->parseArgs(new StringArgs('--disabled')); $expected = <<<'EOF' -Package: vendor/root +Module: vendor/root UUID Glob Type 9ac78a /root/disabled Foo -Package: vendor/package1 +Module: vendor/module1 - UUID Glob Type - a0b6c7 /package1/disabled Foo + UUID Glob Type + a0b6c7 /module1/disabled Foo -Package: vendor/package2 +Module: vendor/module2 - UUID Glob Type - 424d68 /package2/disabled Foo + UUID Glob Type + 424d68 /module2/disabled Foo EOF; @@ -554,20 +554,20 @@ public function testListBindingsWithTypeNotFound() $args = self::$listCommand->parseArgs(new StringArgs('--type-not-found')); $expected = <<<'EOF' -Package: vendor/root +Module: vendor/root UUID Glob Type d0e980 /root/type-not-found Foo -Package: vendor/package1 +Module: vendor/module1 - UUID Glob Type - 19b069 /package1/type-not-found Foo + UUID Glob Type + 19b069 /module1/type-not-found Foo -Package: vendor/package2 +Module: vendor/module2 - UUID Glob Type - b7b2c3 /package2/type-not-found Foo + UUID Glob Type + b7b2c3 /module2/type-not-found Foo EOF; @@ -584,20 +584,20 @@ public function testListBindingsWithTypeNotEnabled() $args = self::$listCommand->parseArgs(new StringArgs('--type-not-enabled')); $expected = <<<'EOF' -Package: vendor/root +Module: vendor/root UUID Glob Type 47491d /root/type-not-enabled Foo -Package: vendor/package1 +Module: vendor/module1 - UUID Glob Type - 7d26ae /package1/type-not-enable Foo + UUID Glob Type + 7d26ae /module1/type-not-enable Foo -Package: vendor/package2 +Module: vendor/module2 - UUID Glob Type - 53e67c /package2/type-not-enabled Foo + UUID Glob Type + 53e67c /module2/type-not-enabled Foo EOF; @@ -614,20 +614,20 @@ public function testListInvalidBindings() $args = self::$listCommand->parseArgs(new StringArgs('--invalid')); $expected = <<<'EOF' -Package: vendor/root +Module: vendor/root UUID Glob Type d06707 /root/invalid Foo -Package: vendor/package1 +Module: vendor/module1 - UUID Glob Type - dd7458 /package1/invalid Foo + UUID Glob Type + dd7458 /module1/invalid Foo -Package: vendor/package2 +Module: vendor/module2 - UUID Glob Type - 24213c /package2/invalid Foo + UUID Glob Type + 24213c /module2/invalid Foo EOF; @@ -646,40 +646,40 @@ public function testListEnabledAndDisabledBindings() $expected = <<<'EOF' The following bindings are currently enabled: - Package: vendor/root + Module: vendor/root UUID Glob Type bb5a07 /root/enabled Foo cc9f22 /overridden Foo 47491d BindCommandHandlerTest Bar - Package: vendor/package1 + Module: vendor/module1 - UUID Glob Type - 970aba /package1/enabled Foo + UUID Glob Type + 970aba /module1/enabled Foo - Package: vendor/package2 + Module: vendor/module2 - UUID Glob Type - ddb655 /package2/enabled Foo + UUID Glob Type + ddb655 /module2/enabled Foo The following bindings are disabled: (use "puli bind --enable " to enable) - Package: vendor/root + Module: vendor/root UUID Glob Type 9ac78a /root/disabled Foo - Package: vendor/package1 + Module: vendor/module1 - UUID Glob Type - a0b6c7 /package1/disabled Foo + UUID Glob Type + a0b6c7 /module1/disabled Foo - Package: vendor/package2 + Module: vendor/module2 - UUID Glob Type - 424d68 /package2/disabled Foo + UUID Glob Type + 424d68 /module2/disabled Foo EOF; @@ -708,15 +708,15 @@ public function testListEnabledBindingsFromRoot() $this->assertEmpty($this->io->fetchErrors()); } - public function testListEnabledBindingsFromPackage() + public function testListEnabledBindingsFromModule() { $this->initDefaultBindings(); - $args = self::$listCommand->parseArgs(new StringArgs('--enabled --package=vendor/package2')); + $args = self::$listCommand->parseArgs(new StringArgs('--enabled --module=vendor/module2')); $expected = <<<'EOF' -UUID Glob Type -ddb655 /package2/enabled Foo +UUID Glob Type +ddb655 /module2/enabled Foo EOF; @@ -730,7 +730,7 @@ public function testListBindingsWithParameters() $this->discoveryManager->expects($this->any()) ->method('findBindingDescriptors') ->willReturnCallback($this->returnFromMap(array( - array($this->packageAndState('vendor/root', BindingState::ENABLED), array( + array($this->moduleAndState('vendor/root', BindingState::ENABLED), array( new BindingDescriptor(new ResourceBinding('/path', Foo::clazz, array( 'param1' => 'value1', 'param2' => 'value2', @@ -744,7 +744,7 @@ public function testListBindingsWithParameters() $expected = << 'value2', ), 'glob'); $descriptor = new BindingDescriptor($binding); - $descriptor->load($this->packages->getRootPackage()); + $descriptor->load($this->modules->getRootModule()); $uuid = $descriptor->getUuid(); $this->discoveryManager->expects($this->at(0)) @@ -948,7 +948,7 @@ public function testUpdateResourceBindingWithRelativePath() { $args = self::$updateCommand->parseArgs(new StringArgs('ab12 --query new')); $descriptor = new BindingDescriptor(new ResourceBinding('/old', Foo::clazz)); - $descriptor->load($this->packages->getRootPackage()); + $descriptor->load($this->modules->getRootModule()); $this->discoveryManager->expects($this->at(0)) ->method('findBindingDescriptors') @@ -979,7 +979,7 @@ public function testUpdateClassBinding() 'param2' => 'value2', )); $descriptor = new BindingDescriptor($binding); - $descriptor->load($this->packages->getRootPackage()); + $descriptor->load($this->modules->getRootModule()); $uuid = $descriptor->getUuid(); $this->discoveryManager->expects($this->at(0)) @@ -1014,7 +1014,7 @@ public function testUpdateBindingWithUnsetParameter() 'param2' => 'value2', ), 'glob'); $descriptor = new BindingDescriptor($binding); - $descriptor->load($this->packages->getRootPackage()); + $descriptor->load($this->modules->getRootModule()); $this->discoveryManager->expects($this->at(0)) ->method('findBindingDescriptors') @@ -1041,7 +1041,7 @@ public function testUpdateBindingForce() { $args = self::$updateCommand->parseArgs(new StringArgs('ab12 --query /new --force')); $descriptor = new BindingDescriptor(new ResourceBinding('/old', Foo::clazz)); - $descriptor->load($this->packages->getRootPackage()); + $descriptor->load($this->modules->getRootModule()); $this->discoveryManager->expects($this->at(0)) ->method('findBindingDescriptors') @@ -1072,7 +1072,7 @@ public function testUpdateBindingFailsIfNoUpdateProvided() { $args = self::$updateCommand->parseArgs(new StringArgs('ab12')); $descriptor = new BindingDescriptor(new ResourceBinding('/old', Foo::clazz)); - $descriptor->load($this->packages->getRootPackage()); + $descriptor->load($this->modules->getRootModule()); $this->discoveryManager->expects($this->once()) ->method('findBindingDescriptors') @@ -1089,13 +1089,13 @@ public function testUpdateBindingFailsIfNoUpdateProvided() /** * @expectedException \RuntimeException - * @expectedExceptionMessage Can only update bindings in the package "vendor/root". + * @expectedExceptionMessage Can only update bindings in the module "vendor/root". */ public function testUpdateBindingFailsIfNoRootBinding() { $args = self::$updateCommand->parseArgs(new StringArgs('ab12 --query /new')); $descriptor = new BindingDescriptor(new ResourceBinding('/old', Foo::clazz)); - $descriptor->load($this->packages->get('vendor/package1')); + $descriptor->load($this->modules->get('vendor/module1')); $this->discoveryManager->expects($this->once()) ->method('findBindingDescriptors') @@ -1114,7 +1114,7 @@ public function testDeleteBinding() { $args = self::$deleteCommand->parseArgs(new StringArgs('ab12')); $descriptor = new BindingDescriptor(new ResourceBinding('/path', Foo::clazz)); - $descriptor->load($this->packages->getRootPackage()); + $descriptor->load($this->modules->getRootModule()); $this->discoveryManager->expects($this->once()) ->method('findBindingDescriptors') @@ -1177,13 +1177,13 @@ public function testDeleteBindingFailsIfNotFound() /** * @expectedException \RuntimeException - * @expectedExceptionMessage Can only delete bindings from the package "vendor/root". + * @expectedExceptionMessage Can only delete bindings from the module "vendor/root". */ public function testDeleteBindingFailsIfNoRootBinding() { $args = self::$deleteCommand->parseArgs(new StringArgs('ab12')); $descriptor = new BindingDescriptor(new ResourceBinding('/path', Foo::clazz)); - $descriptor->load($this->packages->get('vendor/package1')); + $descriptor->load($this->modules->get('vendor/module1')); $this->discoveryManager->expects($this->once()) ->method('findBindingDescriptors') @@ -1202,7 +1202,7 @@ public function testEnableBinding() { $args = self::$enableCommand->parseArgs(new StringArgs('ab12')); $descriptor = new BindingDescriptor(new ResourceBinding('/path', Foo::clazz)); - $descriptor->load($this->packages->get('vendor/package1')); + $descriptor->load($this->modules->get('vendor/module1')); $this->discoveryManager->expects($this->once()) ->method('findBindingDescriptors') @@ -1237,13 +1237,13 @@ public function testEnableBindingFailsIfNotFound() /** * @expectedException \RuntimeException - * @expectedExceptionMessage Cannot enable bindings in the package "vendor/root". + * @expectedExceptionMessage Cannot enable bindings in the module "vendor/root". */ public function testEnableBindingFailsIfRoot() { $args = self::$enableCommand->parseArgs(new StringArgs('ab12')); $descriptor = new BindingDescriptor(new ResourceBinding('/path', Foo::clazz)); - $descriptor->load($this->packages->getRootPackage()); + $descriptor->load($this->modules->getRootModule()); $this->discoveryManager->expects($this->once()) ->method('findBindingDescriptors') @@ -1260,7 +1260,7 @@ public function testDisableBinding() { $args = self::$disableCommand->parseArgs(new StringArgs('ab12')); $descriptor = new BindingDescriptor(new ResourceBinding('/path', Foo::clazz)); - $descriptor->load($this->packages->get('vendor/package1')); + $descriptor->load($this->modules->get('vendor/module1')); $this->discoveryManager->expects($this->once()) ->method('findBindingDescriptors') @@ -1295,13 +1295,13 @@ public function testDisableBindingsFailsIfNotFound() /** * @expectedException \RuntimeException - * @expectedExceptionMessage Cannot disable bindings in the package "vendor/root". + * @expectedExceptionMessage Cannot disable bindings in the module "vendor/root". */ public function testDisableBindingFailsIfRoot() { $args = self::$disableCommand->parseArgs(new StringArgs('ab12')); $descriptor = new BindingDescriptor(new ResourceBinding('/path', Foo::clazz)); - $descriptor->load($this->packages->getRootPackage()); + $descriptor->load($this->modules->getRootModule()); $this->discoveryManager->expects($this->once()) ->method('findBindingDescriptors') @@ -1319,59 +1319,59 @@ private function initDefaultBindings() $this->discoveryManager->expects($this->any()) ->method('findBindingDescriptors') ->willReturnCallback($this->returnFromMap(array( - array($this->packageAndState('vendor/root', BindingState::ENABLED), array( + array($this->moduleAndState('vendor/root', BindingState::ENABLED), array( new BindingDescriptor(new ResourceBinding('/root/enabled', Foo::clazz, array(), 'glob', Uuid::fromString(self::BINDING_UUID1))), new BindingDescriptor(new ResourceBinding('/overridden', Foo::clazz, array(), 'glob', Uuid::fromString(self::BINDING_UUID2))), new BindingDescriptor(new ClassBinding(__CLASS__, Bar::clazz, array(), Uuid::fromString(self::BINDING_UUID17))), )), - array($this->packageAndState('vendor/root', BindingState::DISABLED), array( + array($this->moduleAndState('vendor/root', BindingState::DISABLED), array( new BindingDescriptor(new ResourceBinding('/root/disabled', Foo::clazz, array(), 'glob', Uuid::fromString(self::BINDING_UUID3))), )), - array($this->packageAndState('vendor/root', BindingState::TYPE_NOT_FOUND), array( + array($this->moduleAndState('vendor/root', BindingState::TYPE_NOT_FOUND), array( new BindingDescriptor(new ResourceBinding('/root/type-not-found', Foo::clazz, array(), 'glob', Uuid::fromString(self::BINDING_UUID5))), )), - array($this->packageAndState('vendor/root', BindingState::TYPE_NOT_ENABLED), array( + array($this->moduleAndState('vendor/root', BindingState::TYPE_NOT_ENABLED), array( new BindingDescriptor(new ResourceBinding('/root/type-not-enabled', Foo::clazz, array(), 'glob', Uuid::fromString(self::BINDING_UUID17))), )), - array($this->packageAndState('vendor/root', BindingState::INVALID), array( + array($this->moduleAndState('vendor/root', BindingState::INVALID), array( new BindingDescriptor(new ResourceBinding('/root/invalid', Foo::clazz, array(), 'glob', Uuid::fromString(self::BINDING_UUID6))), )), - array($this->packageAndState('vendor/package1', BindingState::ENABLED), array( - new BindingDescriptor(new ResourceBinding('/package1/enabled', Foo::clazz, array(), 'glob', Uuid::fromString(self::BINDING_UUID7))), + array($this->moduleAndState('vendor/module1', BindingState::ENABLED), array( + new BindingDescriptor(new ResourceBinding('/module1/enabled', Foo::clazz, array(), 'glob', Uuid::fromString(self::BINDING_UUID7))), )), - array($this->packageAndState('vendor/package1', BindingState::DISABLED), array( - new BindingDescriptor(new ResourceBinding('/package1/disabled', Foo::clazz, array(), 'glob', Uuid::fromString(self::BINDING_UUID8))), + array($this->moduleAndState('vendor/module1', BindingState::DISABLED), array( + new BindingDescriptor(new ResourceBinding('/module1/disabled', Foo::clazz, array(), 'glob', Uuid::fromString(self::BINDING_UUID8))), )), - array($this->packageAndState('vendor/package1', BindingState::TYPE_NOT_FOUND), array( - new BindingDescriptor(new ResourceBinding('/package1/type-not-found', Foo::clazz, array(), 'glob', Uuid::fromString(self::BINDING_UUID10))), + array($this->moduleAndState('vendor/module1', BindingState::TYPE_NOT_FOUND), array( + new BindingDescriptor(new ResourceBinding('/module1/type-not-found', Foo::clazz, array(), 'glob', Uuid::fromString(self::BINDING_UUID10))), )), - array($this->packageAndState('vendor/package1', BindingState::TYPE_NOT_ENABLED), array( - new BindingDescriptor(new ResourceBinding('/package1/type-not-enable', Foo::clazz, array(), 'glob', Uuid::fromString(self::BINDING_UUID18))), + array($this->moduleAndState('vendor/module1', BindingState::TYPE_NOT_ENABLED), array( + new BindingDescriptor(new ResourceBinding('/module1/type-not-enable', Foo::clazz, array(), 'glob', Uuid::fromString(self::BINDING_UUID18))), )), - array($this->packageAndState('vendor/package1', BindingState::INVALID), array( - new BindingDescriptor(new ResourceBinding('/package1/invalid', Foo::clazz, array(), 'glob', Uuid::fromString(self::BINDING_UUID11))), + array($this->moduleAndState('vendor/module1', BindingState::INVALID), array( + new BindingDescriptor(new ResourceBinding('/module1/invalid', Foo::clazz, array(), 'glob', Uuid::fromString(self::BINDING_UUID11))), )), - array($this->packageAndState('vendor/package2', BindingState::ENABLED), array( - new BindingDescriptor(new ResourceBinding('/package2/enabled', Foo::clazz, array(), 'glob', Uuid::fromString(self::BINDING_UUID12))), + array($this->moduleAndState('vendor/module2', BindingState::ENABLED), array( + new BindingDescriptor(new ResourceBinding('/module2/enabled', Foo::clazz, array(), 'glob', Uuid::fromString(self::BINDING_UUID12))), )), - array($this->packageAndState('vendor/package2', BindingState::DISABLED), array( - new BindingDescriptor(new ResourceBinding('/package2/disabled', Foo::clazz, array(), 'glob', Uuid::fromString(self::BINDING_UUID13))), + array($this->moduleAndState('vendor/module2', BindingState::DISABLED), array( + new BindingDescriptor(new ResourceBinding('/module2/disabled', Foo::clazz, array(), 'glob', Uuid::fromString(self::BINDING_UUID13))), )), - array($this->packageAndState('vendor/package2', BindingState::TYPE_NOT_FOUND), array( - new BindingDescriptor(new ResourceBinding('/package2/type-not-found', Foo::clazz, array(), 'glob', Uuid::fromString(self::BINDING_UUID15))), + array($this->moduleAndState('vendor/module2', BindingState::TYPE_NOT_FOUND), array( + new BindingDescriptor(new ResourceBinding('/module2/type-not-found', Foo::clazz, array(), 'glob', Uuid::fromString(self::BINDING_UUID15))), )), - array($this->packageAndState('vendor/package2', BindingState::TYPE_NOT_ENABLED), array( - new BindingDescriptor(new ResourceBinding('/package2/type-not-enabled', Foo::clazz, array(), 'glob', Uuid::fromString(self::BINDING_UUID19))), + array($this->moduleAndState('vendor/module2', BindingState::TYPE_NOT_ENABLED), array( + new BindingDescriptor(new ResourceBinding('/module2/type-not-enabled', Foo::clazz, array(), 'glob', Uuid::fromString(self::BINDING_UUID19))), )), - array($this->packageAndState('vendor/package2', BindingState::INVALID), array( - new BindingDescriptor(new ResourceBinding('/package2/invalid', Foo::clazz, array(), 'glob', Uuid::fromString(self::BINDING_UUID16))), + array($this->moduleAndState('vendor/module2', BindingState::INVALID), array( + new BindingDescriptor(new ResourceBinding('/module2/invalid', Foo::clazz, array(), 'glob', Uuid::fromString(self::BINDING_UUID16))), )), ))); } - private function packageAndState($packageName, $state) + private function moduleAndState($moduleName, $state) { - return Expr::method('getContainingPackage', Expr::method('getName', Expr::same($packageName))) + return Expr::method('getContainingModule', Expr::method('getName', Expr::same($moduleName))) ->andMethod('getState', Expr::same($state)); } diff --git a/tests/Handler/ConfigCommandHandlerTest.php b/tests/Handler/ConfigCommandHandlerTest.php index fad7e90..31521dc 100644 --- a/tests/Handler/ConfigCommandHandlerTest.php +++ b/tests/Handler/ConfigCommandHandlerTest.php @@ -13,7 +13,7 @@ use PHPUnit_Framework_MockObject_MockObject; use Puli\Cli\Handler\ConfigCommandHandler; -use Puli\Manager\Api\Package\RootPackageFileManager; +use Puli\Manager\Api\Module\RootModuleFileManager; use Webmozart\Console\Api\Command\Command; use Webmozart\Console\Args\StringArgs; @@ -45,7 +45,7 @@ class ConfigCommandHandlerTest extends AbstractCommandHandlerTest private static $resetCommand; /** - * @var PHPUnit_Framework_MockObject_MockObject|RootPackageFileManager + * @var PHPUnit_Framework_MockObject_MockObject|RootModuleFileManager */ private $manager; @@ -68,7 +68,7 @@ protected function setUp() { parent::setUp(); - $this->manager = $this->getMock('Puli\Manager\Api\Package\RootPackageFileManager'); + $this->manager = $this->getMock('Puli\Manager\Api\Module\RootModuleFileManager'); $this->handler = new ConfigCommandHandler($this->manager); } diff --git a/tests/Handler/Fixtures/root/packages/package1/.gitkeep b/tests/Handler/Fixtures/root/modules/module1/.gitkeep similarity index 100% rename from tests/Handler/Fixtures/root/packages/package1/.gitkeep rename to tests/Handler/Fixtures/root/modules/module1/.gitkeep diff --git a/tests/Handler/Fixtures/root/packages/package2/.gitkeep b/tests/Handler/Fixtures/root/modules/module2/.gitkeep similarity index 100% rename from tests/Handler/Fixtures/root/packages/package2/.gitkeep rename to tests/Handler/Fixtures/root/modules/module2/.gitkeep diff --git a/tests/Handler/Fixtures/root/packages/package4/.gitkeep b/tests/Handler/Fixtures/root/modules/module4/.gitkeep similarity index 100% rename from tests/Handler/Fixtures/root/packages/package4/.gitkeep rename to tests/Handler/Fixtures/root/modules/module4/.gitkeep diff --git a/tests/Handler/Fixtures/root/packages/package5/.gitkeep b/tests/Handler/Fixtures/root/modules/module5/.gitkeep similarity index 100% rename from tests/Handler/Fixtures/root/packages/package5/.gitkeep rename to tests/Handler/Fixtures/root/modules/module5/.gitkeep diff --git a/tests/Handler/MapCommandHandlerTest.php b/tests/Handler/MapCommandHandlerTest.php index 0f7e7d1..ae75733 100644 --- a/tests/Handler/MapCommandHandlerTest.php +++ b/tests/Handler/MapCommandHandlerTest.php @@ -13,11 +13,11 @@ use PHPUnit_Framework_MockObject_MockObject; use Puli\Cli\Handler\MapCommandHandler; -use Puli\Manager\Api\Package\Package; -use Puli\Manager\Api\Package\PackageCollection; -use Puli\Manager\Api\Package\PackageFile; -use Puli\Manager\Api\Package\RootPackage; -use Puli\Manager\Api\Package\RootPackageFile; +use Puli\Manager\Api\Module\Module; +use Puli\Manager\Api\Module\ModuleFile; +use Puli\Manager\Api\Module\ModuleList; +use Puli\Manager\Api\Module\RootModule; +use Puli\Manager\Api\Module\RootModuleFile; use Puli\Manager\Api\Repository\PathConflict; use Puli\Manager\Api\Repository\PathMapping; use Puli\Manager\Api\Repository\PathMappingState; @@ -60,9 +60,9 @@ class MapCommandHandlerTest extends AbstractCommandHandlerTest private $repoManager; /** - * @var PackageCollection + * @var ModuleList */ - private $packages; + private $modules; /** * @var MapCommandHandler @@ -84,12 +84,12 @@ protected function setUp() parent::setUp(); $this->repoManager = $this->getMock('Puli\Manager\Api\Repository\RepositoryManager'); - $this->packages = new PackageCollection(array( - new RootPackage(new RootPackageFile('vendor/root'), '/root'), - new Package(new PackageFile('vendor/package1'), '/package1'), - new Package(new PackageFile('vendor/package2'), '/package2'), + $this->modules = new ModuleList(array( + new RootModule(new RootModuleFile('vendor/root'), '/root'), + new Module(new ModuleFile('vendor/module1'), '/module1'), + new Module(new ModuleFile('vendor/module2'), '/module2'), )); - $this->handler = new MapCommandHandler($this->repoManager, $this->packages); + $this->handler = new MapCommandHandler($this->repoManager, $this->modules); } public function testListAllMappings() @@ -103,57 +103,57 @@ public function testListAllMappings() $expected = <<<'EOF' The following path mappings are currently enabled: - Package: vendor/root + Module: vendor/root Puli Path Real Path(s) /root/enabled res, assets - Package: vendor/package1 + Module: vendor/module1 - Puli Path Real Path(s) - /package1/enabled res, @vendor/package2:res + Puli Path Real Path(s) + /module1/enabled res, @vendor/module2:res - Package: vendor/package2 + Module: vendor/module2 - Puli Path Real Path(s) - /package2/enabled res + Puli Path Real Path(s) + /module2/enabled res The target paths of the following path mappings were not found: - Package: vendor/root + Module: vendor/root Puli Path Real Path(s) /root/not-found res - Package: vendor/package1 + Module: vendor/module1 - Puli Path Real Path(s) - /package1/not-found res + Puli Path Real Path(s) + /module1/not-found res - Package: vendor/package2 + Module: vendor/module2 - Puli Path Real Path(s) - /package2/not-found res + Puli Path Real Path(s) + /module2/not-found res Some path mappings have conflicting paths: - (add the package names to the "override-order" key in puli.json to resolve) + (add the module names to the "override-order" key in puli.json to resolve) Conflicting path: /conflict1 Mapped by the following mappings: - Package Puli Path Real Path(s) - vendor/root /conflict1 res, assets - vendor/package1 /conflict1 res, @vendor/package2:res - vendor/package2 /conflict1 res + Module Puli Path Real Path(s) + vendor/root /conflict1 res, assets + vendor/module1 /conflict1 res, @vendor/module2:res + vendor/module2 /conflict1 res Conflicting path: /conflict2/sub/path Mapped by the following mappings: - Package Puli Path Real Path(s) - vendor/package1 /conflict2 res - vendor/package2 /conflict2 res + Module Puli Path Real Path(s) + vendor/module1 /conflict2 res + vendor/module2 /conflict2 res EOF; @@ -163,7 +163,7 @@ public function testListAllMappings() $this->assertEmpty($this->io->fetchErrors()); } - public function testListRootPackageMappings() + public function testListRootModuleMappings() { $this->initDefaultManager(); @@ -183,16 +183,16 @@ public function testListRootPackageMappings() /root/not-found res Some path mappings have conflicting paths: - (add the package names to the "override-order" key in puli.json to resolve) + (add the module names to the "override-order" key in puli.json to resolve) Conflicting path: /conflict1 Mapped by the following mappings: - Package Puli Path Real Path(s) - vendor/root /conflict1 res, assets - vendor/package1 /conflict1 res, @vendor/package2:res - vendor/package2 /conflict1 res + Module Puli Path Real Path(s) + vendor/root /conflict1 res, assets + vendor/module1 /conflict1 res, @vendor/module2:res + vendor/module2 /conflict1 res EOF; @@ -202,44 +202,44 @@ public function testListRootPackageMappings() $this->assertEmpty($this->io->fetchErrors()); } - public function testListPackageMappings() + public function testListModuleMappings() { $this->initDefaultManager(); - $args = self::$listCommand->parseArgs(new StringArgs('--package vendor/package1')); + $args = self::$listCommand->parseArgs(new StringArgs('--module vendor/module1')); $statusCode = $this->handler->handleList($args, $this->io); $expected = <<<'EOF' The following path mappings are currently enabled: - Puli Path Real Path(s) - /package1/enabled res, @vendor/package2:res + Puli Path Real Path(s) + /module1/enabled res, @vendor/module2:res The target paths of the following path mappings were not found: - Puli Path Real Path(s) - /package1/not-found res + Puli Path Real Path(s) + /module1/not-found res Some path mappings have conflicting paths: - (add the package names to the "override-order" key in puli.json to resolve) + (add the module names to the "override-order" key in puli.json to resolve) Conflicting path: /conflict1 Mapped by the following mappings: - Package Puli Path Real Path(s) - vendor/root /conflict1 res, assets - vendor/package1 /conflict1 res, @vendor/package2:res - vendor/package2 /conflict1 res + Module Puli Path Real Path(s) + vendor/root /conflict1 res, assets + vendor/module1 /conflict1 res, @vendor/module2:res + vendor/module2 /conflict1 res Conflicting path: /conflict2/sub/path Mapped by the following mappings: - Package Puli Path Real Path(s) - vendor/package1 /conflict2 res - vendor/package2 /conflict2 res + Module Puli Path Real Path(s) + vendor/module1 /conflict2 res + vendor/module2 /conflict2 res EOF; @@ -249,58 +249,58 @@ public function testListPackageMappings() $this->assertEmpty($this->io->fetchErrors()); } - public function testListRootAndPackageMappings() + public function testListRootAndModuleMappings() { $this->initDefaultManager(); - $args = self::$listCommand->parseArgs(new StringArgs('--root --package vendor/package1')); + $args = self::$listCommand->parseArgs(new StringArgs('--root --module vendor/module1')); $statusCode = $this->handler->handleList($args, $this->io); $expected = <<<'EOF' The following path mappings are currently enabled: - Package: vendor/root + Module: vendor/root Puli Path Real Path(s) /root/enabled res, assets - Package: vendor/package1 + Module: vendor/module1 - Puli Path Real Path(s) - /package1/enabled res, @vendor/package2:res + Puli Path Real Path(s) + /module1/enabled res, @vendor/module2:res The target paths of the following path mappings were not found: - Package: vendor/root + Module: vendor/root Puli Path Real Path(s) /root/not-found res - Package: vendor/package1 + Module: vendor/module1 - Puli Path Real Path(s) - /package1/not-found res + Puli Path Real Path(s) + /module1/not-found res Some path mappings have conflicting paths: - (add the package names to the "override-order" key in puli.json to resolve) + (add the module names to the "override-order" key in puli.json to resolve) Conflicting path: /conflict1 Mapped by the following mappings: - Package Puli Path Real Path(s) - vendor/root /conflict1 res, assets - vendor/package1 /conflict1 res, @vendor/package2:res - vendor/package2 /conflict1 res + Module Puli Path Real Path(s) + vendor/root /conflict1 res, assets + vendor/module1 /conflict1 res, @vendor/module2:res + vendor/module2 /conflict1 res Conflicting path: /conflict2/sub/path Mapped by the following mappings: - Package Puli Path Real Path(s) - vendor/package1 /conflict2 res - vendor/package2 /conflict2 res + Module Puli Path Real Path(s) + vendor/module1 /conflict2 res + vendor/module2 /conflict2 res EOF; @@ -310,58 +310,58 @@ public function testListRootAndPackageMappings() $this->assertEmpty($this->io->fetchErrors()); } - public function testListMultiplePackageMappings() + public function testListMultipleModuleMappings() { $this->initDefaultManager(); - $args = self::$listCommand->parseArgs(new StringArgs('--package vendor/package1 --package vendor/package2')); + $args = self::$listCommand->parseArgs(new StringArgs('--module vendor/module1 --module vendor/module2')); $statusCode = $this->handler->handleList($args, $this->io); $expected = <<<'EOF' The following path mappings are currently enabled: - Package: vendor/package1 + Module: vendor/module1 - Puli Path Real Path(s) - /package1/enabled res, @vendor/package2:res + Puli Path Real Path(s) + /module1/enabled res, @vendor/module2:res - Package: vendor/package2 + Module: vendor/module2 - Puli Path Real Path(s) - /package2/enabled res + Puli Path Real Path(s) + /module2/enabled res The target paths of the following path mappings were not found: - Package: vendor/package1 + Module: vendor/module1 - Puli Path Real Path(s) - /package1/not-found res + Puli Path Real Path(s) + /module1/not-found res - Package: vendor/package2 + Module: vendor/module2 - Puli Path Real Path(s) - /package2/not-found res + Puli Path Real Path(s) + /module2/not-found res Some path mappings have conflicting paths: - (add the package names to the "override-order" key in puli.json to resolve) + (add the module names to the "override-order" key in puli.json to resolve) Conflicting path: /conflict1 Mapped by the following mappings: - Package Puli Path Real Path(s) - vendor/root /conflict1 res, assets - vendor/package1 /conflict1 res, @vendor/package2:res - vendor/package2 /conflict1 res + Module Puli Path Real Path(s) + vendor/root /conflict1 res, assets + vendor/module1 /conflict1 res, @vendor/module2:res + vendor/module2 /conflict1 res Conflicting path: /conflict2/sub/path Mapped by the following mappings: - Package Puli Path Real Path(s) - vendor/package1 /conflict2 res - vendor/package2 /conflict2 res + Module Puli Path Real Path(s) + vendor/module1 /conflict2 res + vendor/module2 /conflict2 res EOF; @@ -380,20 +380,20 @@ public function testListEnabledMappings() $statusCode = $this->handler->handleList($args, $this->io); $expected = <<<'EOF' -Package: vendor/root +Module: vendor/root Puli Path Real Path(s) /root/enabled res, assets -Package: vendor/package1 +Module: vendor/module1 - Puli Path Real Path(s) - /package1/enabled res, @vendor/package2:res + Puli Path Real Path(s) + /module1/enabled res, @vendor/module2:res -Package: vendor/package2 +Module: vendor/module2 - Puli Path Real Path(s) - /package2/enabled res + Puli Path Real Path(s) + /module2/enabled res EOF; @@ -412,20 +412,20 @@ public function testListNotFoundMappings() $statusCode = $this->handler->handleList($args, $this->io); $expected = <<<'EOF' -Package: vendor/root +Module: vendor/root Puli Path Real Path(s) /root/not-found res -Package: vendor/package1 +Module: vendor/module1 - Puli Path Real Path(s) - /package1/not-found res + Puli Path Real Path(s) + /module1/not-found res -Package: vendor/package2 +Module: vendor/module2 - Puli Path Real Path(s) - /package2/not-found res + Puli Path Real Path(s) + /module2/not-found res EOF; @@ -448,18 +448,18 @@ public function testListConflictingMappings() Mapped by the following mappings: - Package Puli Path Real Path(s) - vendor/root /conflict1 res, assets - vendor/package1 /conflict1 res, @vendor/package2:res - vendor/package2 /conflict1 res + Module Puli Path Real Path(s) + vendor/root /conflict1 res, assets + vendor/module1 /conflict1 res, @vendor/module2:res + vendor/module2 /conflict1 res Conflicting path: /conflict2/sub/path Mapped by the following mappings: - Package Puli Path Real Path(s) - vendor/package1 /conflict2 res - vendor/package2 /conflict2 res + Module Puli Path Real Path(s) + vendor/module1 /conflict2 res + vendor/module2 /conflict2 res EOF; @@ -480,37 +480,37 @@ public function testListEnabledAndNotFoundMappings() $expected = <<<'EOF' The following path mappings are currently enabled: - Package: vendor/root + Module: vendor/root Puli Path Real Path(s) /root/enabled res, assets - Package: vendor/package1 + Module: vendor/module1 - Puli Path Real Path(s) - /package1/enabled res, @vendor/package2:res + Puli Path Real Path(s) + /module1/enabled res, @vendor/module2:res - Package: vendor/package2 + Module: vendor/module2 - Puli Path Real Path(s) - /package2/enabled res + Puli Path Real Path(s) + /module2/enabled res The target paths of the following path mappings were not found: - Package: vendor/root + Module: vendor/root Puli Path Real Path(s) /root/not-found res - Package: vendor/package1 + Module: vendor/module1 - Puli Path Real Path(s) - /package1/not-found res + Puli Path Real Path(s) + /module1/not-found res - Package: vendor/package2 + Module: vendor/module2 - Puli Path Real Path(s) - /package2/not-found res + Puli Path Real Path(s) + /module2/not-found res EOF; @@ -539,17 +539,17 @@ public function testListEnabledMappingsFromRoot() $this->assertEmpty($this->io->fetchErrors()); } - public function testListEnabledMappingsFromPackage() + public function testListEnabledMappingsFromModule() { $this->initDefaultManager(); - $args = self::$listCommand->parseArgs(new StringArgs('--enabled --package vendor/package1')); + $args = self::$listCommand->parseArgs(new StringArgs('--enabled --module vendor/module1')); $statusCode = $this->handler->handleList($args, $this->io); $expected = <<<'EOF' -Puli Path Real Path(s) -/package1/enabled res, @vendor/package2:res +Puli Path Real Path(s) +/module1/enabled res, @vendor/module2:res EOF; @@ -616,7 +616,7 @@ public function testUpdateMappingAddPathReferences() $args = self::$updateCommand->parseArgs(new StringArgs('/path --add assets --add res')); $mapping = new PathMapping('/path', array('previous')); - $mapping->load($this->packages->getRootPackage(), $this->packages); + $mapping->load($this->modules->getRootModule(), $this->modules); $this->repoManager->expects($this->once()) ->method('getRootPathMapping') @@ -635,7 +635,7 @@ public function testUpdateMappingRemovePathReference() $args = self::$updateCommand->parseArgs(new StringArgs('/path --remove assets')); $mapping = new PathMapping('/path', array('assets', 'res')); - $mapping->load($this->packages->getRootPackage(), $this->packages); + $mapping->load($this->modules->getRootModule(), $this->modules); $this->repoManager->expects($this->once()) ->method('getRootPathMapping') @@ -654,7 +654,7 @@ public function testUpdateMappingRemoveAllPathReferences() $args = self::$updateCommand->parseArgs(new StringArgs('/path --remove assets --remove res')); $mapping = new PathMapping('/path', array('assets', 'res')); - $mapping->load($this->packages->getRootPackage(), $this->packages); + $mapping->load($this->modules->getRootModule(), $this->modules); $this->repoManager->expects($this->once()) ->method('getRootPathMapping') @@ -673,7 +673,7 @@ public function testUpdateMappingRelativePath() $args = self::$updateCommand->parseArgs(new StringArgs('rel --add assets')); $mapping = new PathMapping('/rel', array('previous')); - $mapping->load($this->packages->getRootPackage(), $this->packages); + $mapping->load($this->modules->getRootModule(), $this->modules); $this->repoManager->expects($this->once()) ->method('getRootPathMapping') @@ -692,7 +692,7 @@ public function testUpdateMappingForce() $args = self::$updateCommand->parseArgs(new StringArgs('/path --add assets --force')); $mapping = new PathMapping('/path', array('previous')); - $mapping->load($this->packages->getRootPackage(), $this->packages); + $mapping->load($this->modules->getRootModule(), $this->modules); $this->repoManager->expects($this->once()) ->method('getRootPathMapping') @@ -714,7 +714,7 @@ public function testUpdateMappingFailsIfNoChange() $args = self::$updateCommand->parseArgs(new StringArgs('/path')); $mapping = new PathMapping('/path', array('previous')); - $mapping->load($this->packages->getRootPackage(), $this->packages); + $mapping->load($this->modules->getRootModule(), $this->modules); $this->repoManager->expects($this->once()) ->method('getRootPathMapping') @@ -761,7 +761,7 @@ public function testDeleteMappingWithAbsolutePath() /** * @expectedException \RuntimeException - * @expectedExceptionMessage The path "/path1" is not mapped in the package "vendor/root". + * @expectedExceptionMessage The path "/path1" is not mapped in the module "vendor/root". */ public function testDeleteMappingFailsIfNotFound() { @@ -782,97 +782,97 @@ public function testDeleteMappingFailsIfNotFound() private function initDefaultManager() { $conflictMappingRoot1 = new PathMapping('/conflict1', array('res', 'assets')); - $conflictMappingPackage11 = new PathMapping('/conflict1', array('res', '@vendor/package2:res')); - $conflictMappingPackage12 = new PathMapping('/conflict2', 'res'); - $conflictMappingPackage21 = new PathMapping('/conflict1', 'res'); - $conflictMappingPackage22 = new PathMapping('/conflict2', 'res'); + $conflictMappingModule11 = new PathMapping('/conflict1', array('res', '@vendor/module2:res')); + $conflictMappingModule12 = new PathMapping('/conflict2', 'res'); + $conflictMappingModule21 = new PathMapping('/conflict1', 'res'); + $conflictMappingModule22 = new PathMapping('/conflict2', 'res'); - $conflictMappingRoot1->load($this->packages->getRootPackage(), $this->packages); - $conflictMappingPackage11->load($this->packages->get('vendor/package1'), $this->packages); - $conflictMappingPackage12->load($this->packages->get('vendor/package1'), $this->packages); - $conflictMappingPackage21->load($this->packages->get('vendor/package2'), $this->packages); - $conflictMappingPackage22->load($this->packages->get('vendor/package2'), $this->packages); + $conflictMappingRoot1->load($this->modules->getRootModule(), $this->modules); + $conflictMappingModule11->load($this->modules->get('vendor/module1'), $this->modules); + $conflictMappingModule12->load($this->modules->get('vendor/module1'), $this->modules); + $conflictMappingModule21->load($this->modules->get('vendor/module2'), $this->modules); + $conflictMappingModule22->load($this->modules->get('vendor/module2'), $this->modules); $conflict1 = new PathConflict('/conflict1'); $conflict1->addMappings(array( $conflictMappingRoot1, - $conflictMappingPackage11, - $conflictMappingPackage21, + $conflictMappingModule11, + $conflictMappingModule21, )); $conflict2 = new PathConflict('/conflict2/sub/path'); $conflict2->addMappings(array( - $conflictMappingPackage12, - $conflictMappingPackage22, + $conflictMappingModule12, + $conflictMappingModule22, )); $this->repoManager->expects($this->any()) ->method('findPathMappings') ->willReturnCallback($this->returnFromMap(array( - array($this->packageAndState('vendor/root', PathMappingState::ENABLED), array( + array($this->moduleAndState('vendor/root', PathMappingState::ENABLED), array( new PathMapping('/root/enabled', array('res', 'assets')), )), - array($this->packageAndState('vendor/package1', PathMappingState::ENABLED), array( - new PathMapping('/package1/enabled', array('res', '@vendor/package2:res')), + array($this->moduleAndState('vendor/module1', PathMappingState::ENABLED), array( + new PathMapping('/module1/enabled', array('res', '@vendor/module2:res')), )), - array($this->packageAndState('vendor/package2', PathMappingState::ENABLED), array( - new PathMapping('/package2/enabled', 'res'), + array($this->moduleAndState('vendor/module2', PathMappingState::ENABLED), array( + new PathMapping('/module2/enabled', 'res'), )), - array($this->packageAndState('vendor/root', PathMappingState::NOT_FOUND), array( + array($this->moduleAndState('vendor/root', PathMappingState::NOT_FOUND), array( new PathMapping('/root/not-found', 'res'), )), - array($this->packageAndState('vendor/package1', PathMappingState::NOT_FOUND), array( - new PathMapping('/package1/not-found', 'res'), + array($this->moduleAndState('vendor/module1', PathMappingState::NOT_FOUND), array( + new PathMapping('/module1/not-found', 'res'), )), - array($this->packageAndState('vendor/package2', PathMappingState::NOT_FOUND), array( - new PathMapping('/package2/not-found', 'res'), + array($this->moduleAndState('vendor/module2', PathMappingState::NOT_FOUND), array( + new PathMapping('/module2/not-found', 'res'), )), - array($this->packagesAndState(array('vendor/root'), PathMappingState::CONFLICT), array( + array($this->modulesAndState(array('vendor/root'), PathMappingState::CONFLICT), array( $conflictMappingRoot1, )), - array($this->packagesAndState(array('vendor/package1'), PathMappingState::CONFLICT), array( - $conflictMappingPackage11, - $conflictMappingPackage12, + array($this->modulesAndState(array('vendor/module1'), PathMappingState::CONFLICT), array( + $conflictMappingModule11, + $conflictMappingModule12, )), - array($this->packagesAndState(array('vendor/package2'), PathMappingState::CONFLICT), array( - $conflictMappingPackage21, - $conflictMappingPackage22, + array($this->modulesAndState(array('vendor/module2'), PathMappingState::CONFLICT), array( + $conflictMappingModule21, + $conflictMappingModule22, )), - array($this->packagesAndState(array('vendor/root', 'vendor/package1'), PathMappingState::CONFLICT), array( + array($this->modulesAndState(array('vendor/root', 'vendor/module1'), PathMappingState::CONFLICT), array( $conflictMappingRoot1, - $conflictMappingPackage11, - $conflictMappingPackage12, + $conflictMappingModule11, + $conflictMappingModule12, )), - array($this->packagesAndState(array('vendor/root', 'vendor/package2'), PathMappingState::CONFLICT), array( + array($this->modulesAndState(array('vendor/root', 'vendor/module2'), PathMappingState::CONFLICT), array( $conflictMappingRoot1, - $conflictMappingPackage21, - $conflictMappingPackage22, + $conflictMappingModule21, + $conflictMappingModule22, )), - array($this->packagesAndState(array('vendor/package1', 'vendor/package2'), PathMappingState::CONFLICT), array( - $conflictMappingPackage11, - $conflictMappingPackage12, - $conflictMappingPackage21, - $conflictMappingPackage22, + array($this->modulesAndState(array('vendor/module1', 'vendor/module2'), PathMappingState::CONFLICT), array( + $conflictMappingModule11, + $conflictMappingModule12, + $conflictMappingModule21, + $conflictMappingModule22, )), - array($this->packagesAndState(array('vendor/root', 'vendor/package1', 'vendor/package2'), PathMappingState::CONFLICT), array( + array($this->modulesAndState(array('vendor/root', 'vendor/module1', 'vendor/module2'), PathMappingState::CONFLICT), array( $conflictMappingRoot1, - $conflictMappingPackage11, - $conflictMappingPackage12, - $conflictMappingPackage21, - $conflictMappingPackage22, + $conflictMappingModule11, + $conflictMappingModule12, + $conflictMappingModule21, + $conflictMappingModule22, )), ))); } - private function packageAndState($packageName, $state) + private function moduleAndState($moduleName, $state) { - return Expr::method('getContainingPackage', Expr::method('getName', Expr::same($packageName))) + return Expr::method('getContainingModule', Expr::method('getName', Expr::same($moduleName))) ->andMethod('getState', Expr::same($state)); } - private function packagesAndState(array $packageNames, $state) + private function modulesAndState(array $moduleNames, $state) { - return Expr::method('getContainingPackage', Expr::method('getName', Expr::in($packageNames))) + return Expr::method('getContainingModule', Expr::method('getName', Expr::in($moduleNames))) ->andMethod('getState', Expr::same($state)); } diff --git a/tests/Handler/ModuleCommandHandlerTest.php b/tests/Handler/ModuleCommandHandlerTest.php new file mode 100644 index 0000000..a3ce35d --- /dev/null +++ b/tests/Handler/ModuleCommandHandlerTest.php @@ -0,0 +1,607 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Puli\Cli\Tests\Handler; + +use PHPUnit_Framework_MockObject_MockObject; +use Puli\Cli\Handler\ModuleCommandHandler; +use Puli\Manager\Api\Context\ProjectContext; +use Puli\Manager\Api\Environment; +use Puli\Manager\Api\Module\InstallInfo; +use Puli\Manager\Api\Module\Module; +use Puli\Manager\Api\Module\ModuleFile; +use Puli\Manager\Api\Module\ModuleList; +use Puli\Manager\Api\Module\ModuleManager; +use Puli\Manager\Api\Module\ModuleState; +use Puli\Manager\Api\Module\RootModule; +use Puli\Manager\Api\Module\RootModuleFile; +use RuntimeException; +use Webmozart\Console\Api\Command\Command; +use Webmozart\Console\Args\StringArgs; +use Webmozart\Expression\Expr; +use Webmozart\Expression\Expression; +use Webmozart\PathUtil\Path; + +/** + * @since 1.0 + * + * @author Bernhard Schussek + */ +class ModuleCommandHandlerTest extends AbstractCommandHandlerTest +{ + /** + * @var Command + */ + private static $listCommand; + + /** + * @var Command + */ + private static $installCommand; + + /** + * @var Command + */ + private static $renameCommand; + + /** + * @var Command + */ + private static $deleteCommand; + + /** + * @var Command + */ + private static $cleanCommand; + + /** + * @var PHPUnit_Framework_MockObject_MockObject|ProjectContext + */ + private $context; + + /** + * @var PHPUnit_Framework_MockObject_MockObject|ModuleManager + */ + private $moduleManager; + + /** + * @var ModuleCommandHandler + */ + private $handler; + + /** + * @var string + */ + private $wd; + + /** + * @var string + */ + private $previousWd; + + public static function setUpBeforeClass() + { + parent::setUpBeforeClass(); + + self::$listCommand = self::$application->getCommand('module')->getSubCommand('list'); + self::$installCommand = self::$application->getCommand('module')->getSubCommand('install'); + self::$renameCommand = self::$application->getCommand('module')->getSubCommand('rename'); + self::$deleteCommand = self::$application->getCommand('module')->getSubCommand('delete'); + self::$cleanCommand = self::$application->getCommand('module')->getSubCommand('clean'); + } + + protected function setUp() + { + parent::setUp(); + + $this->context = $this->getMockBuilder('Puli\Manager\Api\Context\ProjectContext') + ->disableOriginalConstructor() + ->getMock(); + $this->moduleManager = $this->getMock('Puli\Manager\Api\Module\ModuleManager'); + $this->handler = new ModuleCommandHandler($this->moduleManager); + + $this->context->expects($this->any()) + ->method('getRootDirectory') + ->willReturn(__DIR__.'/Fixtures/root'); + + $this->moduleManager->expects($this->any()) + ->method('getContext') + ->willReturn($this->context); + + $installInfo1 = new InstallInfo('vendor/module1', 'modules/module1'); + $installInfo2 = new InstallInfo('vendor/module2', 'modules/module2'); + $installInfo3 = new InstallInfo('vendor/module3', 'modules/module3'); + $installInfo4 = new InstallInfo('vendor/module4', 'modules/module4'); + $installInfo5 = new InstallInfo('vendor/module5', 'modules/module5'); + + $installInfo1->setInstallerName('spock'); + $installInfo2->setInstallerName('spock'); + $installInfo3->setInstallerName('kirk'); + $installInfo4->setInstallerName('spock'); + $installInfo5->setInstallerName('spock'); + $installInfo5->setEnvironment(Environment::DEV); + + $rootModule = new RootModule(new RootModuleFile('vendor/root'), __DIR__.'/Fixtures/root'); + $module1 = new Module(new ModuleFile('vendor/module1'), __DIR__.'/Fixtures/root/modules/module1', $installInfo1); + $module2 = new Module(new ModuleFile('vendor/module2'), __DIR__.'/Fixtures/root/modules/module2', $installInfo2); + $module3 = new Module(new ModuleFile('vendor/module3'), __DIR__.'/Fixtures/root/modules/module3', $installInfo3); + $module4 = new Module(null, __DIR__.'/Fixtures/root/modules/module4', $installInfo4, array(new RuntimeException('Load error'))); + $module5 = new Module(new ModuleFile('vendor/module5'), __DIR__.'/Fixtures/root/modules/module5', $installInfo5); + + $this->moduleManager->expects($this->any()) + ->method('findModules') + ->willReturnCallback($this->returnFromMap(array( + array($this->all(), new ModuleList(array($rootModule, $module1, $module2, $module3, $module4, $module5))), + array($this->env(array(Environment::PROD, Environment::DEV)), new ModuleList(array($rootModule, $module1, $module2, $module3, $module4, $module5))), + array($this->env(array(Environment::PROD)), new ModuleList(array($rootModule, $module1, $module2, $module3, $module4))), + array($this->env(array(Environment::DEV)), new ModuleList(array($module5))), + array($this->installer('spock'), new ModuleList(array($module1, $module2, $module4, $module5))), + array($this->state(ModuleState::ENABLED), new ModuleList(array($rootModule, $module1, $module2, $module5))), + array($this->state(ModuleState::NOT_FOUND), new ModuleList(array($module3))), + array($this->state(ModuleState::NOT_LOADABLE), new ModuleList(array($module4))), + array($this->states(array(ModuleState::ENABLED, ModuleState::NOT_FOUND)), new ModuleList(array($rootModule, $module1, $module2, $module3, $module5))), + array($this->installerAndState('spock', ModuleState::ENABLED), new ModuleList(array($module1, $module2, $module5))), + array($this->installerAndState('spock', ModuleState::NOT_FOUND), new ModuleList(array())), + array($this->installerAndState('spock', ModuleState::NOT_LOADABLE), new ModuleList(array($module4))), + ))); + + $this->previousWd = getcwd(); + $this->wd = Path::normalize(__DIR__); + + chdir($this->wd); + } + + protected function tearDown() + { + chdir($this->previousWd); + } + + public function testListModules() + { + $args = self::$listCommand->parseArgs(new StringArgs('')); + + $statusCode = $this->handler->handleList($args, $this->io); + + $expected = <<<'EOF' +The following modules are currently enabled: + + Module Name Installer Env Install Path + vendor/module1 spock prod modules/module1 + vendor/module2 spock prod modules/module2 + vendor/module5 spock dev modules/module5 + vendor/root prod . + +The following modules could not be found: + (use "puli module --clean" to remove) + + Module Name Installer Env Install Path + vendor/module3 kirk prod modules/module3 + +The following modules could not be loaded: + + Module Name Error + vendor/module4 RuntimeException: Load error + + +EOF; + + $this->assertSame(0, $statusCode); + $this->assertSame($expected, $this->io->fetchOutput()); + $this->assertEmpty($this->io->fetchErrors()); + } + + public function testListModulesByInstaller() + { + $args = self::$listCommand->parseArgs(new StringArgs('--installer spock')); + + $statusCode = $this->handler->handleList($args, $this->io); + + $expected = <<<'EOF' +The following modules are currently enabled: + + Module Name Installer Env Install Path + vendor/module1 spock prod modules/module1 + vendor/module2 spock prod modules/module2 + vendor/module5 spock dev modules/module5 + +The following modules could not be loaded: + + Module Name Error + vendor/module4 RuntimeException: Load error + + +EOF; + + $this->assertSame(0, $statusCode); + $this->assertSame($expected, $this->io->fetchOutput()); + $this->assertEmpty($this->io->fetchErrors()); + } + + public function testListEnabledModules() + { + $args = self::$listCommand->parseArgs(new StringArgs('--enabled')); + + $statusCode = $this->handler->handleList($args, $this->io); + + $expected = <<<'EOF' +Module Name Installer Env Install Path +vendor/module1 spock prod modules/module1 +vendor/module2 spock prod modules/module2 +vendor/module5 spock dev modules/module5 +vendor/root prod . + +EOF; + + $this->assertSame(0, $statusCode); + $this->assertSame($expected, $this->io->fetchOutput()); + $this->assertEmpty($this->io->fetchErrors()); + } + + public function testListNotFoundModules() + { + $args = self::$listCommand->parseArgs(new StringArgs('--not-found')); + + $statusCode = $this->handler->handleList($args, $this->io); + + $expected = <<<'EOF' +Module Name Installer Env Install Path +vendor/module3 kirk prod modules/module3 + +EOF; + + $this->assertSame(0, $statusCode); + $this->assertSame($expected, $this->io->fetchOutput()); + $this->assertEmpty($this->io->fetchErrors()); + } + + public function testListNotLoadableModules() + { + $args = self::$listCommand->parseArgs(new StringArgs('--not-loadable')); + + $statusCode = $this->handler->handleList($args, $this->io); + + $expected = <<<'EOF' +Module Name Error +vendor/module4 RuntimeException: Load error + +EOF; + + $this->assertSame(0, $statusCode); + $this->assertSame($expected, $this->io->fetchOutput()); + $this->assertEmpty($this->io->fetchErrors()); + } + + public function testListEnabledAndNotFoundModules() + { + $args = self::$listCommand->parseArgs(new StringArgs('--enabled --not-found')); + + $statusCode = $this->handler->handleList($args, $this->io); + + $expected = <<<'EOF' +The following modules are currently enabled: + + Module Name Installer Env Install Path + vendor/module1 spock prod modules/module1 + vendor/module2 spock prod modules/module2 + vendor/module5 spock dev modules/module5 + vendor/root prod . + +The following modules could not be found: + (use "puli module --clean" to remove) + + Module Name Installer Env Install Path + vendor/module3 kirk prod modules/module3 + + +EOF; + + $this->assertSame(0, $statusCode); + $this->assertSame($expected, $this->io->fetchOutput()); + $this->assertEmpty($this->io->fetchErrors()); + } + + public function testListEnabledModulesByInstaller() + { + $args = self::$listCommand->parseArgs(new StringArgs('--enabled --installer spock')); + + $statusCode = $this->handler->handleList($args, $this->io); + + $expected = <<<'EOF' +Module Name Installer Env Install Path +vendor/module1 spock prod modules/module1 +vendor/module2 spock prod modules/module2 +vendor/module5 spock dev modules/module5 + +EOF; + + $this->assertSame(0, $statusCode); + $this->assertSame($expected, $this->io->fetchOutput()); + $this->assertEmpty($this->io->fetchErrors()); + } + + public function testListDevModules() + { + $args = self::$listCommand->parseArgs(new StringArgs('--dev')); + + $statusCode = $this->handler->handleList($args, $this->io); + + $expected = <<<'EOF' +The following modules are currently enabled: + + Module Name Installer Env Install Path + vendor/module5 spock dev modules/module5 + + +EOF; + + $this->assertSame(0, $statusCode); + $this->assertSame($expected, $this->io->fetchOutput()); + $this->assertEmpty($this->io->fetchErrors()); + } + + public function testListNoDevModules() + { + $args = self::$listCommand->parseArgs(new StringArgs('--prod')); + + $statusCode = $this->handler->handleList($args, $this->io); + + $expected = <<<'EOF' +The following modules are currently enabled: + + Module Name Installer Env Install Path + vendor/module1 spock prod modules/module1 + vendor/module2 spock prod modules/module2 + vendor/root prod . + +The following modules could not be found: + (use "puli module --clean" to remove) + + Module Name Installer Env Install Path + vendor/module3 kirk prod modules/module3 + +The following modules could not be loaded: + + Module Name Error + vendor/module4 RuntimeException: Load error + + +EOF; + + $this->assertSame(0, $statusCode); + $this->assertSame($expected, $this->io->fetchOutput()); + $this->assertEmpty($this->io->fetchErrors()); + } + + public function testListDevAndNoDevModules() + { + // Same as if passing none of the too + // Does not make much sense but could occur if building the + // "module list" command dynamically + $args = self::$listCommand->parseArgs(new StringArgs('--dev --prod')); + + $statusCode = $this->handler->handleList($args, $this->io); + + $expected = <<<'EOF' +The following modules are currently enabled: + + Module Name Installer Env Install Path + vendor/module1 spock prod modules/module1 + vendor/module2 spock prod modules/module2 + vendor/module5 spock dev modules/module5 + vendor/root prod . + +The following modules could not be found: + (use "puli module --clean" to remove) + + Module Name Installer Env Install Path + vendor/module3 kirk prod modules/module3 + +The following modules could not be loaded: + + Module Name Error + vendor/module4 RuntimeException: Load error + + +EOF; + + $this->assertSame(0, $statusCode); + $this->assertSame($expected, $this->io->fetchOutput()); + $this->assertEmpty($this->io->fetchErrors()); + } + + public function testListModulesWithFormat() + { + $args = self::$listCommand->parseArgs(new StringArgs('--format %name%:%installer%:%install_path%:%state%:%env%')); + + $rootDir = $this->context->getRootDirectory(); + $statusCode = $this->handler->handleList($args, $this->io); + + $expected = <<assertSame(0, $statusCode); + $this->assertSame($expected, $this->io->fetchOutput()); + $this->assertEmpty($this->io->fetchErrors()); + } + + public function testInstallModuleWithRelativePath() + { + $args = self::$installCommand->parseArgs(new StringArgs('modules/module1')); + + $this->moduleManager->expects($this->once()) + ->method('installModule') + ->with($this->wd.'/modules/module1', null, InstallInfo::DEFAULT_INSTALLER_NAME, Environment::PROD); + + $this->assertSame(0, $this->handler->handleInstall($args)); + } + + public function testInstallModuleWithAbsolutePath() + { + $args = self::$installCommand->parseArgs(new StringArgs('/modules/module1')); + + $this->moduleManager->expects($this->once()) + ->method('installModule') + ->with('/modules/module1', null, InstallInfo::DEFAULT_INSTALLER_NAME, Environment::PROD); + + $this->assertSame(0, $this->handler->handleInstall($args)); + } + + public function testInstallModuleWithCustomName() + { + $args = self::$installCommand->parseArgs(new StringArgs('/modules/module1 custom/module1')); + + $this->moduleManager->expects($this->once()) + ->method('installModule') + ->with('/modules/module1', 'custom/module1', InstallInfo::DEFAULT_INSTALLER_NAME, Environment::PROD); + + $this->assertSame(0, $this->handler->handleInstall($args)); + } + + public function testInstallModuleWithCustomInstaller() + { + $args = self::$installCommand->parseArgs(new StringArgs('--installer kirk /modules/module1')); + + $this->moduleManager->expects($this->once()) + ->method('installModule') + ->with('/modules/module1', null, 'kirk', Environment::PROD); + + $this->assertSame(0, $this->handler->handleInstall($args)); + } + + public function testInstallDevModule() + { + $args = self::$installCommand->parseArgs(new StringArgs('--dev modules/module1')); + + $this->moduleManager->expects($this->once()) + ->method('installModule') + ->with($this->wd.'/modules/module1', null, InstallInfo::DEFAULT_INSTALLER_NAME, Environment::DEV); + + $this->assertSame(0, $this->handler->handleInstall($args)); + } + + public function testRenameModule() + { + $args = self::$renameCommand->parseArgs(new StringArgs('vendor/module1 vendor/new')); + + $this->moduleManager->expects($this->once()) + ->method('renameModule') + ->with('vendor/module1', 'vendor/new'); + + $this->assertSame(0, $this->handler->handleRename($args)); + } + + public function testDeleteModule() + { + $args = self::$deleteCommand->parseArgs(new StringArgs('vendor/module1')); + + $this->moduleManager->expects($this->once()) + ->method('hasModule') + ->with('vendor/module1') + ->willReturn(true); + + $this->moduleManager->expects($this->once()) + ->method('removeModule') + ->with('vendor/module1'); + + $this->assertSame(0, $this->handler->handleDelete($args)); + } + + /** + * @expectedException \RuntimeException + * @expectedExceptionMessage The module "vendor/module1" is not installed. + */ + public function testDeleteModuleFailsIfNotFound() + { + $args = self::$deleteCommand->parseArgs(new StringArgs('vendor/module1')); + + $this->moduleManager->expects($this->once()) + ->method('hasModule') + ->with('vendor/module1') + ->willReturn(false); + + $this->moduleManager->expects($this->never()) + ->method('removeModule') + ->with('vendor/module1'); + + $this->handler->handleDelete($args); + } + + public function testCleanModules() + { + $args = self::$cleanCommand->parseArgs(new StringArgs('')); + + // The not-found module + $this->moduleManager->expects($this->once()) + ->method('removeModule') + ->with('vendor/module3'); + + $expected = <<<'EOF' +Removing vendor/module3 + +EOF; + + $this->assertSame(0, $this->handler->handleClean($args, $this->io)); + $this->assertSame($expected, $this->io->fetchOutput()); + $this->assertEmpty($this->io->fetchErrors()); + } + + private function all() + { + return Expr::true(); + } + + private function env(array $envs) + { + return Expr::method('getInstallInfo', Expr::method('getEnvironment', Expr::in($envs))); + } + + private function state($state) + { + return Expr::method('getState', Expr::same($state)); + } + + private function states(array $states) + { + return Expr::method('getState', Expr::in($states)); + } + + private function installer($installer) + { + return Expr::method('getInstallInfo', Expr::method('getInstallerName', Expr::same($installer))); + } + + private function installerAndState($installer, $state) + { + return Expr::method('getInstallInfo', Expr::method('getInstallerName', Expr::same($installer))) + ->andMethod('getState', Expr::same($state)); + } + + private function returnFromMap(array $map) + { + return function (Expression $expr) use ($map) { + foreach ($map as $arguments) { + // Cannot use willReturnMap(), which uses === + if ($expr->equivalentTo($arguments[0])) { + return $arguments[1]; + } + } + + return null; + }; + } +} diff --git a/tests/Handler/PackageCommandHandlerTest.php b/tests/Handler/PackageCommandHandlerTest.php deleted file mode 100644 index ddaee3f..0000000 --- a/tests/Handler/PackageCommandHandlerTest.php +++ /dev/null @@ -1,607 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Puli\Cli\Tests\Handler; - -use PHPUnit_Framework_MockObject_MockObject; -use Puli\Cli\Handler\PackageCommandHandler; -use Puli\Manager\Api\Context\ProjectContext; -use Puli\Manager\Api\Environment; -use Puli\Manager\Api\Package\InstallInfo; -use Puli\Manager\Api\Package\Package; -use Puli\Manager\Api\Package\PackageCollection; -use Puli\Manager\Api\Package\PackageFile; -use Puli\Manager\Api\Package\PackageManager; -use Puli\Manager\Api\Package\PackageState; -use Puli\Manager\Api\Package\RootPackage; -use Puli\Manager\Api\Package\RootPackageFile; -use RuntimeException; -use Webmozart\Console\Api\Command\Command; -use Webmozart\Console\Args\StringArgs; -use Webmozart\Expression\Expr; -use Webmozart\Expression\Expression; -use Webmozart\PathUtil\Path; - -/** - * @since 1.0 - * - * @author Bernhard Schussek - */ -class PackageCommandHandlerTest extends AbstractCommandHandlerTest -{ - /** - * @var Command - */ - private static $listCommand; - - /** - * @var Command - */ - private static $installCommand; - - /** - * @var Command - */ - private static $renameCommand; - - /** - * @var Command - */ - private static $deleteCommand; - - /** - * @var Command - */ - private static $cleanCommand; - - /** - * @var PHPUnit_Framework_MockObject_MockObject|ProjectContext - */ - private $context; - - /** - * @var PHPUnit_Framework_MockObject_MockObject|PackageManager - */ - private $packageManager; - - /** - * @var PackageCommandHandler - */ - private $handler; - - /** - * @var string - */ - private $wd; - - /** - * @var string - */ - private $previousWd; - - public static function setUpBeforeClass() - { - parent::setUpBeforeClass(); - - self::$listCommand = self::$application->getCommand('package')->getSubCommand('list'); - self::$installCommand = self::$application->getCommand('package')->getSubCommand('install'); - self::$renameCommand = self::$application->getCommand('package')->getSubCommand('rename'); - self::$deleteCommand = self::$application->getCommand('package')->getSubCommand('delete'); - self::$cleanCommand = self::$application->getCommand('package')->getSubCommand('clean'); - } - - protected function setUp() - { - parent::setUp(); - - $this->context = $this->getMockBuilder('Puli\Manager\Api\Context\ProjectContext') - ->disableOriginalConstructor() - ->getMock(); - $this->packageManager = $this->getMock('Puli\Manager\Api\Package\PackageManager'); - $this->handler = new PackageCommandHandler($this->packageManager); - - $this->context->expects($this->any()) - ->method('getRootDirectory') - ->willReturn(__DIR__.'/Fixtures/root'); - - $this->packageManager->expects($this->any()) - ->method('getContext') - ->willReturn($this->context); - - $installInfo1 = new InstallInfo('vendor/package1', 'packages/package1'); - $installInfo2 = new InstallInfo('vendor/package2', 'packages/package2'); - $installInfo3 = new InstallInfo('vendor/package3', 'packages/package3'); - $installInfo4 = new InstallInfo('vendor/package4', 'packages/package4'); - $installInfo5 = new InstallInfo('vendor/package5', 'packages/package5'); - - $installInfo1->setInstallerName('spock'); - $installInfo2->setInstallerName('spock'); - $installInfo3->setInstallerName('kirk'); - $installInfo4->setInstallerName('spock'); - $installInfo5->setInstallerName('spock'); - $installInfo5->setEnvironment(Environment::DEV); - - $rootPackage = new RootPackage(new RootPackageFile('vendor/root'), __DIR__.'/Fixtures/root'); - $package1 = new Package(new PackageFile('vendor/package1'), __DIR__.'/Fixtures/root/packages/package1', $installInfo1); - $package2 = new Package(new PackageFile('vendor/package2'), __DIR__.'/Fixtures/root/packages/package2', $installInfo2); - $package3 = new Package(new PackageFile('vendor/package3'), __DIR__.'/Fixtures/root/packages/package3', $installInfo3); - $package4 = new Package(null, __DIR__.'/Fixtures/root/packages/package4', $installInfo4, array(new RuntimeException('Load error'))); - $package5 = new Package(new PackageFile('vendor/package5'), __DIR__.'/Fixtures/root/packages/package5', $installInfo5); - - $this->packageManager->expects($this->any()) - ->method('findPackages') - ->willReturnCallback($this->returnFromMap(array( - array($this->all(), new PackageCollection(array($rootPackage, $package1, $package2, $package3, $package4, $package5))), - array($this->env(array(Environment::PROD, Environment::DEV)), new PackageCollection(array($rootPackage, $package1, $package2, $package3, $package4, $package5))), - array($this->env(array(Environment::PROD)), new PackageCollection(array($rootPackage, $package1, $package2, $package3, $package4))), - array($this->env(array(Environment::DEV)), new PackageCollection(array($package5))), - array($this->installer('spock'), new PackageCollection(array($package1, $package2, $package4, $package5))), - array($this->state(PackageState::ENABLED), new PackageCollection(array($rootPackage, $package1, $package2, $package5))), - array($this->state(PackageState::NOT_FOUND), new PackageCollection(array($package3))), - array($this->state(PackageState::NOT_LOADABLE), new PackageCollection(array($package4))), - array($this->states(array(PackageState::ENABLED, PackageState::NOT_FOUND)), new PackageCollection(array($rootPackage, $package1, $package2, $package3, $package5))), - array($this->installerAndState('spock', PackageState::ENABLED), new PackageCollection(array($package1, $package2, $package5))), - array($this->installerAndState('spock', PackageState::NOT_FOUND), new PackageCollection(array())), - array($this->installerAndState('spock', PackageState::NOT_LOADABLE), new PackageCollection(array($package4))), - ))); - - $this->previousWd = getcwd(); - $this->wd = Path::normalize(__DIR__); - - chdir($this->wd); - } - - protected function tearDown() - { - chdir($this->previousWd); - } - - public function testListPackages() - { - $args = self::$listCommand->parseArgs(new StringArgs('')); - - $statusCode = $this->handler->handleList($args, $this->io); - - $expected = <<<'EOF' -The following packages are currently enabled: - - Package Name Installer Env Install Path - vendor/package1 spock prod packages/package1 - vendor/package2 spock prod packages/package2 - vendor/package5 spock dev packages/package5 - vendor/root prod . - -The following packages could not be found: - (use "puli package --clean" to remove) - - Package Name Installer Env Install Path - vendor/package3 kirk prod packages/package3 - -The following packages could not be loaded: - - Package Name Error - vendor/package4 RuntimeException: Load error - - -EOF; - - $this->assertSame(0, $statusCode); - $this->assertSame($expected, $this->io->fetchOutput()); - $this->assertEmpty($this->io->fetchErrors()); - } - - public function testListPackagesByInstaller() - { - $args = self::$listCommand->parseArgs(new StringArgs('--installer spock')); - - $statusCode = $this->handler->handleList($args, $this->io); - - $expected = <<<'EOF' -The following packages are currently enabled: - - Package Name Installer Env Install Path - vendor/package1 spock prod packages/package1 - vendor/package2 spock prod packages/package2 - vendor/package5 spock dev packages/package5 - -The following packages could not be loaded: - - Package Name Error - vendor/package4 RuntimeException: Load error - - -EOF; - - $this->assertSame(0, $statusCode); - $this->assertSame($expected, $this->io->fetchOutput()); - $this->assertEmpty($this->io->fetchErrors()); - } - - public function testListEnabledPackages() - { - $args = self::$listCommand->parseArgs(new StringArgs('--enabled')); - - $statusCode = $this->handler->handleList($args, $this->io); - - $expected = <<<'EOF' -Package Name Installer Env Install Path -vendor/package1 spock prod packages/package1 -vendor/package2 spock prod packages/package2 -vendor/package5 spock dev packages/package5 -vendor/root prod . - -EOF; - - $this->assertSame(0, $statusCode); - $this->assertSame($expected, $this->io->fetchOutput()); - $this->assertEmpty($this->io->fetchErrors()); - } - - public function testListNotFoundPackages() - { - $args = self::$listCommand->parseArgs(new StringArgs('--not-found')); - - $statusCode = $this->handler->handleList($args, $this->io); - - $expected = <<<'EOF' -Package Name Installer Env Install Path -vendor/package3 kirk prod packages/package3 - -EOF; - - $this->assertSame(0, $statusCode); - $this->assertSame($expected, $this->io->fetchOutput()); - $this->assertEmpty($this->io->fetchErrors()); - } - - public function testListNotLoadablePackages() - { - $args = self::$listCommand->parseArgs(new StringArgs('--not-loadable')); - - $statusCode = $this->handler->handleList($args, $this->io); - - $expected = <<<'EOF' -Package Name Error -vendor/package4 RuntimeException: Load error - -EOF; - - $this->assertSame(0, $statusCode); - $this->assertSame($expected, $this->io->fetchOutput()); - $this->assertEmpty($this->io->fetchErrors()); - } - - public function testListEnabledAndNotFoundPackages() - { - $args = self::$listCommand->parseArgs(new StringArgs('--enabled --not-found')); - - $statusCode = $this->handler->handleList($args, $this->io); - - $expected = <<<'EOF' -The following packages are currently enabled: - - Package Name Installer Env Install Path - vendor/package1 spock prod packages/package1 - vendor/package2 spock prod packages/package2 - vendor/package5 spock dev packages/package5 - vendor/root prod . - -The following packages could not be found: - (use "puli package --clean" to remove) - - Package Name Installer Env Install Path - vendor/package3 kirk prod packages/package3 - - -EOF; - - $this->assertSame(0, $statusCode); - $this->assertSame($expected, $this->io->fetchOutput()); - $this->assertEmpty($this->io->fetchErrors()); - } - - public function testListEnabledPackagesByInstaller() - { - $args = self::$listCommand->parseArgs(new StringArgs('--enabled --installer spock')); - - $statusCode = $this->handler->handleList($args, $this->io); - - $expected = <<<'EOF' -Package Name Installer Env Install Path -vendor/package1 spock prod packages/package1 -vendor/package2 spock prod packages/package2 -vendor/package5 spock dev packages/package5 - -EOF; - - $this->assertSame(0, $statusCode); - $this->assertSame($expected, $this->io->fetchOutput()); - $this->assertEmpty($this->io->fetchErrors()); - } - - public function testListDevPackages() - { - $args = self::$listCommand->parseArgs(new StringArgs('--dev')); - - $statusCode = $this->handler->handleList($args, $this->io); - - $expected = <<<'EOF' -The following packages are currently enabled: - - Package Name Installer Env Install Path - vendor/package5 spock dev packages/package5 - - -EOF; - - $this->assertSame(0, $statusCode); - $this->assertSame($expected, $this->io->fetchOutput()); - $this->assertEmpty($this->io->fetchErrors()); - } - - public function testListNoDevPackages() - { - $args = self::$listCommand->parseArgs(new StringArgs('--prod')); - - $statusCode = $this->handler->handleList($args, $this->io); - - $expected = <<<'EOF' -The following packages are currently enabled: - - Package Name Installer Env Install Path - vendor/package1 spock prod packages/package1 - vendor/package2 spock prod packages/package2 - vendor/root prod . - -The following packages could not be found: - (use "puli package --clean" to remove) - - Package Name Installer Env Install Path - vendor/package3 kirk prod packages/package3 - -The following packages could not be loaded: - - Package Name Error - vendor/package4 RuntimeException: Load error - - -EOF; - - $this->assertSame(0, $statusCode); - $this->assertSame($expected, $this->io->fetchOutput()); - $this->assertEmpty($this->io->fetchErrors()); - } - - public function testListDevAndNoDevPackages() - { - // Same as if passing none of the too - // Does not make much sense but could occur if building the - // "package list" command dynamically - $args = self::$listCommand->parseArgs(new StringArgs('--dev --prod')); - - $statusCode = $this->handler->handleList($args, $this->io); - - $expected = <<<'EOF' -The following packages are currently enabled: - - Package Name Installer Env Install Path - vendor/package1 spock prod packages/package1 - vendor/package2 spock prod packages/package2 - vendor/package5 spock dev packages/package5 - vendor/root prod . - -The following packages could not be found: - (use "puli package --clean" to remove) - - Package Name Installer Env Install Path - vendor/package3 kirk prod packages/package3 - -The following packages could not be loaded: - - Package Name Error - vendor/package4 RuntimeException: Load error - - -EOF; - - $this->assertSame(0, $statusCode); - $this->assertSame($expected, $this->io->fetchOutput()); - $this->assertEmpty($this->io->fetchErrors()); - } - - public function testListPackagesWithFormat() - { - $args = self::$listCommand->parseArgs(new StringArgs('--format %name%:%installer%:%install_path%:%state%:%env%')); - - $rootDir = $this->context->getRootDirectory(); - $statusCode = $this->handler->handleList($args, $this->io); - - $expected = <<assertSame(0, $statusCode); - $this->assertSame($expected, $this->io->fetchOutput()); - $this->assertEmpty($this->io->fetchErrors()); - } - - public function testInstallPackageWithRelativePath() - { - $args = self::$installCommand->parseArgs(new StringArgs('packages/package1')); - - $this->packageManager->expects($this->once()) - ->method('installPackage') - ->with($this->wd.'/packages/package1', null, InstallInfo::DEFAULT_INSTALLER_NAME, Environment::PROD); - - $this->assertSame(0, $this->handler->handleInstall($args)); - } - - public function testInstallPackageWithAbsolutePath() - { - $args = self::$installCommand->parseArgs(new StringArgs('/packages/package1')); - - $this->packageManager->expects($this->once()) - ->method('installPackage') - ->with('/packages/package1', null, InstallInfo::DEFAULT_INSTALLER_NAME, Environment::PROD); - - $this->assertSame(0, $this->handler->handleInstall($args)); - } - - public function testInstallPackageWithCustomName() - { - $args = self::$installCommand->parseArgs(new StringArgs('/packages/package1 custom/package1')); - - $this->packageManager->expects($this->once()) - ->method('installPackage') - ->with('/packages/package1', 'custom/package1', InstallInfo::DEFAULT_INSTALLER_NAME, Environment::PROD); - - $this->assertSame(0, $this->handler->handleInstall($args)); - } - - public function testInstallPackageWithCustomInstaller() - { - $args = self::$installCommand->parseArgs(new StringArgs('--installer kirk /packages/package1')); - - $this->packageManager->expects($this->once()) - ->method('installPackage') - ->with('/packages/package1', null, 'kirk', Environment::PROD); - - $this->assertSame(0, $this->handler->handleInstall($args)); - } - - public function testInstallDevPackage() - { - $args = self::$installCommand->parseArgs(new StringArgs('--dev packages/package1')); - - $this->packageManager->expects($this->once()) - ->method('installPackage') - ->with($this->wd.'/packages/package1', null, InstallInfo::DEFAULT_INSTALLER_NAME, Environment::DEV); - - $this->assertSame(0, $this->handler->handleInstall($args)); - } - - public function testRenamePackage() - { - $args = self::$renameCommand->parseArgs(new StringArgs('vendor/package1 vendor/new')); - - $this->packageManager->expects($this->once()) - ->method('renamePackage') - ->with('vendor/package1', 'vendor/new'); - - $this->assertSame(0, $this->handler->handleRename($args)); - } - - public function testDeletePackage() - { - $args = self::$deleteCommand->parseArgs(new StringArgs('vendor/package1')); - - $this->packageManager->expects($this->once()) - ->method('hasPackage') - ->with('vendor/package1') - ->willReturn(true); - - $this->packageManager->expects($this->once()) - ->method('removePackage') - ->with('vendor/package1'); - - $this->assertSame(0, $this->handler->handleDelete($args)); - } - - /** - * @expectedException \RuntimeException - * @expectedExceptionMessage The package "vendor/package1" is not installed. - */ - public function testDeletePackageFailsIfNotFound() - { - $args = self::$deleteCommand->parseArgs(new StringArgs('vendor/package1')); - - $this->packageManager->expects($this->once()) - ->method('hasPackage') - ->with('vendor/package1') - ->willReturn(false); - - $this->packageManager->expects($this->never()) - ->method('removePackage') - ->with('vendor/package1'); - - $this->handler->handleDelete($args); - } - - public function testCleanPackages() - { - $args = self::$cleanCommand->parseArgs(new StringArgs('')); - - // The not-found package - $this->packageManager->expects($this->once()) - ->method('removePackage') - ->with('vendor/package3'); - - $expected = <<<'EOF' -Removing vendor/package3 - -EOF; - - $this->assertSame(0, $this->handler->handleClean($args, $this->io)); - $this->assertSame($expected, $this->io->fetchOutput()); - $this->assertEmpty($this->io->fetchErrors()); - } - - private function all() - { - return Expr::true(); - } - - private function env(array $envs) - { - return Expr::method('getInstallInfo', Expr::method('getEnvironment', Expr::in($envs))); - } - - private function state($state) - { - return Expr::method('getState', Expr::same($state)); - } - - private function states(array $states) - { - return Expr::method('getState', Expr::in($states)); - } - - private function installer($installer) - { - return Expr::method('getInstallInfo', Expr::method('getInstallerName', Expr::same($installer))); - } - - private function installerAndState($installer, $state) - { - return Expr::method('getInstallInfo', Expr::method('getInstallerName', Expr::same($installer))) - ->andMethod('getState', Expr::same($state)); - } - - private function returnFromMap(array $map) - { - return function (Expression $expr) use ($map) { - foreach ($map as $arguments) { - // Cannot use willReturnMap(), which uses === - if ($expr->equivalentTo($arguments[0])) { - return $arguments[1]; - } - } - - return null; - }; - } -} diff --git a/tests/Handler/PluginCommandHandlerTest.php b/tests/Handler/PluginCommandHandlerTest.php index 1f9aafe..65f71c9 100644 --- a/tests/Handler/PluginCommandHandlerTest.php +++ b/tests/Handler/PluginCommandHandlerTest.php @@ -13,7 +13,7 @@ use PHPUnit_Framework_MockObject_MockObject; use Puli\Cli\Handler\PluginCommandHandler; -use Puli\Manager\Api\Package\RootPackageFileManager; +use Puli\Manager\Api\Module\RootModuleFileManager; use Webmozart\Console\Api\Command\Command; use Webmozart\Console\Args\StringArgs; @@ -40,7 +40,7 @@ class PluginCommandHandlerTest extends AbstractCommandHandlerTest private static $deleteCommand; /** - * @var PHPUnit_Framework_MockObject_MockObject|RootPackageFileManager + * @var PHPUnit_Framework_MockObject_MockObject|RootModuleFileManager */ private $manager; @@ -62,7 +62,7 @@ protected function setUp() { parent::setUp(); - $this->manager = $this->getMock('Puli\Manager\Api\Package\RootPackageFileManager'); + $this->manager = $this->getMock('Puli\Manager\Api\Module\RootModuleFileManager'); $this->handler = new PluginCommandHandler($this->manager); } diff --git a/tests/Handler/TypeCommandHandlerTest.php b/tests/Handler/TypeCommandHandlerTest.php index 886212a..32c2143 100644 --- a/tests/Handler/TypeCommandHandlerTest.php +++ b/tests/Handler/TypeCommandHandlerTest.php @@ -18,11 +18,11 @@ use Puli\Manager\Api\Discovery\BindingTypeDescriptor; use Puli\Manager\Api\Discovery\BindingTypeState; use Puli\Manager\Api\Discovery\DiscoveryManager; -use Puli\Manager\Api\Package\Package; -use Puli\Manager\Api\Package\PackageCollection; -use Puli\Manager\Api\Package\PackageFile; -use Puli\Manager\Api\Package\RootPackage; -use Puli\Manager\Api\Package\RootPackageFile; +use Puli\Manager\Api\Module\Module; +use Puli\Manager\Api\Module\ModuleFile; +use Puli\Manager\Api\Module\ModuleList; +use Puli\Manager\Api\Module\RootModule; +use Puli\Manager\Api\Module\RootModuleFile; use Webmozart\Console\Api\Command\Command; use Webmozart\Console\Args\StringArgs; use Webmozart\Expression\Expr; @@ -61,9 +61,9 @@ class TypeCommandHandlerTest extends AbstractCommandHandlerTest private $discoveryManager; /** - * @var PackageCollection + * @var ModuleList */ - private $packages; + private $modules; /** * @var TypeCommandHandler @@ -85,17 +85,17 @@ protected function setUp() parent::setUp(); $this->discoveryManager = $this->getMock('Puli\Manager\Api\Discovery\DiscoveryManager'); - $this->packages = new PackageCollection(array( - new RootPackage(new RootPackageFile('vendor/root'), '/root'), - new Package(new PackageFile('vendor/package1'), '/package1'), - new Package(new PackageFile('vendor/package2'), '/package2'), + $this->modules = new ModuleList(array( + new RootModule(new RootModuleFile('vendor/root'), '/root'), + new Module(new ModuleFile('vendor/module1'), '/module1'), + new Module(new ModuleFile('vendor/module2'), '/module2'), )); - $this->handler = new TypeCommandHandler($this->discoveryManager, $this->packages); + $this->handler = new TypeCommandHandler($this->discoveryManager, $this->modules); $this->discoveryManager->expects($this->any()) ->method('findTypeDescriptors') ->willReturnCallback($this->returnFromMap(array( - array($this->packageAndState('vendor/root', BindingTypeState::ENABLED), array( + array($this->moduleAndState('vendor/root', BindingTypeState::ENABLED), array( new BindingTypeDescriptor( new BindingType('root/enabled1', array( new BindingParameter('req-param', BindingParameter::REQUIRED), @@ -109,20 +109,20 @@ protected function setUp() ), new BindingTypeDescriptor(new BindingType('root/enabled2'), 'Description of root/enabled2'), )), - array($this->packageAndState('vendor/root', BindingTypeState::DUPLICATE), array( + array($this->moduleAndState('vendor/root', BindingTypeState::DUPLICATE), array( new BindingTypeDescriptor(new BindingType('root/duplicate')), )), - array($this->packageAndState('vendor/package1', BindingTypeState::ENABLED), array( - new BindingTypeDescriptor(new BindingType('package1/enabled')), + array($this->moduleAndState('vendor/module1', BindingTypeState::ENABLED), array( + new BindingTypeDescriptor(new BindingType('module1/enabled')), )), - array($this->packageAndState('vendor/package1', BindingTypeState::DUPLICATE), array( - new BindingTypeDescriptor(new BindingType('package1/duplicate')), + array($this->moduleAndState('vendor/module1', BindingTypeState::DUPLICATE), array( + new BindingTypeDescriptor(new BindingType('module1/duplicate')), )), - array($this->packageAndState('vendor/package2', BindingTypeState::ENABLED), array( - new BindingTypeDescriptor(new BindingType('package2/enabled')), + array($this->moduleAndState('vendor/module2', BindingTypeState::ENABLED), array( + new BindingTypeDescriptor(new BindingType('module2/enabled')), )), - array($this->packageAndState('vendor/package2', BindingTypeState::DUPLICATE), array( - new BindingTypeDescriptor(new BindingType('package2/duplicate')), + array($this->moduleAndState('vendor/module2', BindingTypeState::DUPLICATE), array( + new BindingTypeDescriptor(new BindingType('module2/duplicate')), )), ))); } @@ -134,7 +134,7 @@ public function testListAllTypes() $expected = <<<'EOF' The following binding types are currently enabled: - Package: vendor/root + Module: vendor/root Type Description Parameters root/enabled1 Description of opt-param="default" @@ -142,32 +142,32 @@ public function testListAllTypes() root/enabled2 Description of root/enabled2 - Package: vendor/package1 + Module: vendor/module1 - Type Description Parameters - package1/enabled + Type Description Parameters + module1/enabled - Package: vendor/package2 + Module: vendor/module2 - Type Description Parameters - package2/enabled + Type Description Parameters + module2/enabled The following types have duplicate definitions and are disabled: - Package: vendor/root + Module: vendor/root Type Description Parameters root/duplicate - Package: vendor/package1 + Module: vendor/module1 - Type Description Parameters - package1/duplicate + Type Description Parameters + module1/duplicate - Package: vendor/package2 + Module: vendor/module2 - Type Description Parameters - package2/duplicate + Type Description Parameters + module2/duplicate Use "puli bind " to bind a resource to a type. @@ -178,7 +178,7 @@ public function testListAllTypes() $this->assertEmpty($this->io->fetchErrors()); } - public function testListRootPackageTypes() + public function testListRootModuleTypes() { $args = self::$listCommand->parseArgs(new StringArgs('--root')); @@ -204,20 +204,20 @@ public function testListRootPackageTypes() $this->assertEmpty($this->io->fetchErrors()); } - public function testListPackageTypes() + public function testListModuleTypes() { - $args = self::$listCommand->parseArgs(new StringArgs('--package vendor/package1')); + $args = self::$listCommand->parseArgs(new StringArgs('--module vendor/module1')); $expected = <<<'EOF' The following binding types are currently enabled: - Type Description Parameters - package1/enabled + Type Description Parameters + module1/enabled The following types have duplicate definitions and are disabled: - Type Description Parameters - package1/duplicate + Type Description Parameters + module1/duplicate Use "puli bind " to bind a resource to a type. @@ -228,14 +228,14 @@ public function testListPackageTypes() $this->assertEmpty($this->io->fetchErrors()); } - public function testListRootAndPackageTypes() + public function testListRootAndModuleTypes() { - $args = self::$listCommand->parseArgs(new StringArgs('--root --package vendor/package1')); + $args = self::$listCommand->parseArgs(new StringArgs('--root --module vendor/module1')); $expected = <<<'EOF' The following binding types are currently enabled: - Package: vendor/root + Module: vendor/root Type Description Parameters root/enabled1 Description of opt-param="default" @@ -243,22 +243,22 @@ public function testListRootAndPackageTypes() root/enabled2 Description of root/enabled2 - Package: vendor/package1 + Module: vendor/module1 - Type Description Parameters - package1/enabled + Type Description Parameters + module1/enabled The following types have duplicate definitions and are disabled: - Package: vendor/root + Module: vendor/root Type Description Parameters root/duplicate - Package: vendor/package1 + Module: vendor/module1 - Type Description Parameters - package1/duplicate + Type Description Parameters + module1/duplicate Use "puli bind " to bind a resource to a type. @@ -269,34 +269,34 @@ public function testListRootAndPackageTypes() $this->assertEmpty($this->io->fetchErrors()); } - public function testListMultiplePackageTypes() + public function testListMultipleModuleTypes() { - $args = self::$listCommand->parseArgs(new StringArgs('--package vendor/package1 --package vendor/package2')); + $args = self::$listCommand->parseArgs(new StringArgs('--module vendor/module1 --module vendor/module2')); $expected = <<<'EOF' The following binding types are currently enabled: - Package: vendor/package1 + Module: vendor/module1 - Type Description Parameters - package1/enabled + Type Description Parameters + module1/enabled - Package: vendor/package2 + Module: vendor/module2 - Type Description Parameters - package2/enabled + Type Description Parameters + module2/enabled The following types have duplicate definitions and are disabled: - Package: vendor/package1 + Module: vendor/module1 - Type Description Parameters - package1/duplicate + Type Description Parameters + module1/duplicate - Package: vendor/package2 + Module: vendor/module2 - Type Description Parameters - package2/duplicate + Type Description Parameters + module2/duplicate Use "puli bind " to bind a resource to a type. @@ -312,22 +312,22 @@ public function testListEnabledTypes() $args = self::$listCommand->parseArgs(new StringArgs('--enabled')); $expected = <<<'EOF' -Package: vendor/root +Module: vendor/root Type Description Parameters root/enabled1 Description of root/enabled1 opt-param="default" req-param root/enabled2 Description of root/enabled2 -Package: vendor/package1 +Module: vendor/module1 - Type Description Parameters - package1/enabled + Type Description Parameters + module1/enabled -Package: vendor/package2 +Module: vendor/module2 - Type Description Parameters - package2/enabled + Type Description Parameters + module2/enabled EOF; @@ -342,20 +342,20 @@ public function testListDuplicateTypes() $args = self::$listCommand->parseArgs(new StringArgs('--duplicate')); $expected = <<<'EOF' -Package: vendor/root +Module: vendor/root Type Description Parameters root/duplicate -Package: vendor/package1 +Module: vendor/module1 - Type Description Parameters - package1/duplicate + Type Description Parameters + module1/duplicate -Package: vendor/package2 +Module: vendor/module2 - Type Description Parameters - package2/duplicate + Type Description Parameters + module2/duplicate EOF; @@ -372,7 +372,7 @@ public function testListEnabledAndDuplicateTypes() $expected = <<<'EOF' The following binding types are currently enabled: - Package: vendor/root + Module: vendor/root Type Description Parameters root/enabled1 Description of opt-param="default" @@ -380,32 +380,32 @@ public function testListEnabledAndDuplicateTypes() root/enabled2 Description of root/enabled2 - Package: vendor/package1 + Module: vendor/module1 - Type Description Parameters - package1/enabled + Type Description Parameters + module1/enabled - Package: vendor/package2 + Module: vendor/module2 - Type Description Parameters - package2/enabled + Type Description Parameters + module2/enabled The following types have duplicate definitions and are disabled: - Package: vendor/root + Module: vendor/root Type Description Parameters root/duplicate - Package: vendor/package1 + Module: vendor/module1 - Type Description Parameters - package1/duplicate + Type Description Parameters + module1/duplicate - Package: vendor/package2 + Module: vendor/module2 - Type Description Parameters - package2/duplicate + Type Description Parameters + module2/duplicate Use "puli bind " to bind a resource to a type. @@ -433,13 +433,13 @@ public function testListEnabledTypesInRoot() $this->assertEmpty($this->io->fetchErrors()); } - public function testListEnabledTypesInPackage() + public function testListEnabledTypesInModule() { - $args = self::$listCommand->parseArgs(new StringArgs('--enabled --package vendor/package1')); + $args = self::$listCommand->parseArgs(new StringArgs('--enabled --module vendor/module1')); $expected = <<<'EOF' -Type Description Parameters -package1/enabled +Type Description Parameters +module1/enabled EOF; @@ -454,7 +454,7 @@ public function testListNoTypes() $this->discoveryManager->expects($this->any()) ->method('findTypeDescriptors') ->willReturn(array()); - $this->handler = new TypeCommandHandler($this->discoveryManager, $this->packages); + $this->handler = new TypeCommandHandler($this->discoveryManager, $this->modules); $args = self::$listCommand->parseArgs(new StringArgs('')); @@ -553,7 +553,7 @@ public function testUpdateTypeDescription() $args = self::$updateCommand->parseArgs(new StringArgs('my/type --description "New description"')); $typeDescriptor = new BindingTypeDescriptor(new BindingType('my/type'), 'Old description'); - $typeDescriptor->load($this->packages->getRootPackage()); + $typeDescriptor->load($this->modules->getRootModule()); $this->discoveryManager->expects($this->once()) ->method('getRootTypeDescriptor') @@ -578,7 +578,7 @@ public function testUpdateTypeOptionalParameterToRequired() null, array('param' => 'The description') ); - $typeDescriptor->load($this->packages->getRootPackage()); + $typeDescriptor->load($this->modules->getRootModule()); $this->discoveryManager->expects($this->once()) ->method('getRootTypeDescriptor') @@ -609,7 +609,7 @@ public function testUpdateTypeRequiredParameterToOptional() null, array('param' => 'The description') ); - $typeDescriptor->load($this->packages->getRootPackage()); + $typeDescriptor->load($this->modules->getRootModule()); $this->discoveryManager->expects($this->once()) ->method('getRootTypeDescriptor') @@ -640,7 +640,7 @@ public function testUpdateTypeChangeParameterDescription() null, array('param' => 'Old description') ); - $typeDescriptor->load($this->packages->getRootPackage()); + $typeDescriptor->load($this->modules->getRootModule()); $this->discoveryManager->expects($this->once()) ->method('getRootTypeDescriptor') @@ -670,7 +670,7 @@ public function testUpdateTypeRemoveParameter() new BindingParameter('param2', BindingParameter::OPTIONAL), )) ); - $typeDescriptor->load($this->packages->getRootPackage()); + $typeDescriptor->load($this->modules->getRootModule()); $this->discoveryManager->expects($this->once()) ->method('getRootTypeDescriptor') @@ -696,7 +696,7 @@ public function testUpdateTypeFailsIfNoChanges() $args = self::$updateCommand->parseArgs(new StringArgs('my/type')); $typeDescriptor = new BindingTypeDescriptor(new BindingType('my/type')); - $typeDescriptor->load($this->packages->getRootPackage()); + $typeDescriptor->load($this->modules->getRootModule()); $this->discoveryManager->expects($this->once()) ->method('getRootTypeDescriptor') @@ -727,7 +727,7 @@ public function testDeleteType() /** * @expectedException \RuntimeException - * @expectedExceptionMessage The type "my/type" does not exist in the package "vendor/root". + * @expectedExceptionMessage The type "my/type" does not exist in the module "vendor/root". */ public function testDeleteTypeFailsIfNotFound() { @@ -744,9 +744,9 @@ public function testDeleteTypeFailsIfNotFound() $this->assertSame(0, $this->handler->handleDelete($args)); } - private function packageAndState($packageName, $state) + private function moduleAndState($moduleName, $state) { - return Expr::method('getContainingPackage', Expr::method('getName', Expr::same($packageName))) + return Expr::method('getContainingModule', Expr::method('getName', Expr::same($moduleName))) ->andMethod('getState', Expr::same($state)); } diff --git a/tests/Handler/UpgradeCommandHandlerTest.php b/tests/Handler/UpgradeCommandHandlerTest.php index f30f2a6..07d3272 100644 --- a/tests/Handler/UpgradeCommandHandlerTest.php +++ b/tests/Handler/UpgradeCommandHandlerTest.php @@ -13,9 +13,9 @@ use PHPUnit_Framework_MockObject_MockObject; use Puli\Cli\Handler\UpgradeCommandHandler; -use Puli\Manager\Api\Package\PackageFile; -use Puli\Manager\Api\Package\RootPackageFile; -use Puli\Manager\Api\Package\RootPackageFileManager; +use Puli\Manager\Api\Module\RootModuleFile; +use Puli\Manager\Api\Module\RootModuleFileManager; +use Puli\Manager\Module\ModuleFileConverter; use Webmozart\Console\Api\Command\Command; use Webmozart\Console\Args\StringArgs; @@ -32,14 +32,14 @@ class UpgradeCommandHandlerTest extends AbstractCommandHandlerTest private static $upgradeCommand; /** - * @var PHPUnit_Framework_MockObject_MockObject|RootPackageFileManager + * @var PHPUnit_Framework_MockObject_MockObject|RootModuleFileManager */ - private $packageFileManager; + private $moduleFileManager; /** - * @var RootPackageFile + * @var RootModuleFile */ - private $packageFile; + private $moduleFile; /** * @var UpgradeCommandHandler @@ -57,22 +57,22 @@ protected function setUp() { parent::setUp(); - $this->packageFileManager = $this->getMock('Puli\Manager\Api\Package\RootPackageFileManager'); - $this->packageFile = new RootPackageFile(); - $this->packageFileManager->expects($this->any()) - ->method('getPackageFile') - ->willReturn($this->packageFile); - $this->handler = new UpgradeCommandHandler($this->packageFileManager); + $this->moduleFileManager = $this->getMock('Puli\Manager\Api\Module\RootModuleFileManager'); + $this->moduleFile = new RootModuleFile(); + $this->moduleFileManager->expects($this->any()) + ->method('getModuleFile') + ->willReturn($this->moduleFile); + $this->handler = new UpgradeCommandHandler($this->moduleFileManager); } public function testUpgradeToDefaultVersion() { $args = self::$upgradeCommand->parseArgs(new StringArgs('')); - $defaultVersion = PackageFile::DEFAULT_VERSION; + $defaultVersion = ModuleFileConverter::VERSION; - $this->packageFile->setVersion('0.5'); + $this->moduleFile->setVersion('0.5'); - $this->packageFileManager->expects($this->once()) + $this->moduleFileManager->expects($this->once()) ->method('migrate') ->with($defaultVersion); @@ -90,9 +90,9 @@ public function testUpgradeToExplicitVersion() { $args = self::$upgradeCommand->parseArgs(new StringArgs('0.8')); - $this->packageFile->setVersion('0.5'); + $this->moduleFile->setVersion('0.5'); - $this->packageFileManager->expects($this->once()) + $this->moduleFileManager->expects($this->once()) ->method('migrate') ->with('0.8'); @@ -110,9 +110,9 @@ public function testUpgradeDoesNothingIfAlreadyCorrectVersion() { $args = self::$upgradeCommand->parseArgs(new StringArgs('0.5')); - $this->packageFile->setVersion('0.5'); + $this->moduleFile->setVersion('0.5'); - $this->packageFileManager->expects($this->never()) + $this->moduleFileManager->expects($this->never()) ->method('migrate'); $expected = <<<'EOF'