/**
  * @param string $option
  * @param string $noParameters
  *
  * @dataProvider helpActionDataProvider
  */
 public function testHelpAction($option, $noParameters)
 {
     $this->request->expects($this->once())->method('getParam')->willReturn($option);
     $usage = $this->controller->getCommandUsage();
     $expectedValue = explode(' ', strlen($usage[$option]) > 0 ? $usage[$option] : $noParameters);
     $returnValue = explode(' ', trim(str_replace([PHP_EOL, 'Available parameters:'], '', $this->controller->helpAction())));
     $expectedValue = asort($expectedValue);
     $returnValue = asort($returnValue);
     $this->assertEquals($expectedValue, $returnValue);
 }
 /**
  * Checks parameters and returns validation messages
  *
  * @param array $data
  * @param array $config
  * @return string
  */
 public function validate(array $data, array $config)
 {
     $validationMessages = '';
     $userAction = null;
     if (!empty($data)) {
         $userAction = $data[0];
         array_shift($data);
     }
     if (isset($userAction) && isset($config[$userAction])) {
         // parse the expected parameters of the action
         $matcher = new RouteMatcher($config[$userAction]['options']['route']);
         $parts = $matcher->getParts();
         array_shift($parts);
         $expectedParams = [];
         foreach ($parts as $part) {
             $expectedParams[$part['name']] = $part;
         }
         // parse user parameters
         $userParams = $this->parseUserParams($data);
         $validationMessages = $this->validateParameters($expectedParams, $userParams);
         // add usage message
         $usages = ConsoleController::getCommandUsage();
         $validationMessages .= 'Usage:' . PHP_EOL . "{$userAction} ";
         $validationMessages .= $usages[$userAction] . PHP_EOL . PHP_EOL;
     } else {
         if (!is_null($userAction)) {
             $validationMessages .= PHP_EOL . "Unknown action name '{$userAction}'." . PHP_EOL . PHP_EOL;
         } else {
             $validationMessages .= PHP_EOL . "No action is given in the command." . PHP_EOL . PHP_EOL;
         }
         $validationMessages .= 'Available options: ' . PHP_EOL;
         foreach (array_keys($config) as $action) {
             $validationMessages .= $action . PHP_EOL;
         }
         $validationMessages .= PHP_EOL;
     }
     return $validationMessages;
 }
Esempio n. 3
0
 /**
  * Checks parameters and returns validation messages
  *
  * @param array $data
  * @param array $config
  * @return string
  */
 public function validate(array $data, array $config)
 {
     $validationMessages = '';
     $userAction = null;
     if (!empty($data)) {
         $userAction = $data[0];
         array_shift($data);
     }
     if (isset($userAction) && isset($config[$userAction])) {
         // parse the expected parameters of the action
         $matcher = new RouteMatcher($config[$userAction]['options']['route']);
         $parts = $matcher->getParts();
         array_shift($parts);
         $expectedParams = [];
         foreach ($parts as $part) {
             $expectedParams[$part['name']] = $part;
         }
         // parse user parameters
         $userParams = $this->parseUserParams($data);
         $missingParams = $this->checkMissingParameter($expectedParams, $userParams);
         $extraParams = $this->checkExtraParameter($expectedParams, $userParams);
         $missingValues = $this->checkMissingValue($expectedParams, $userParams);
         $extraValues = $this->checkExtraValue($expectedParams, $userParams);
         $validationMessages = PHP_EOL;
         if (!empty($missingParams)) {
             $validationMessages .= 'Missing required parameters:' . PHP_EOL;
             foreach ($missingParams as $missingParam) {
                 $validationMessages .= $missingParam . PHP_EOL;
             }
             $validationMessages .= PHP_EOL;
         }
         if (!empty($extraParams)) {
             $validationMessages .= 'Unidentified parameters:' . PHP_EOL;
             foreach ($extraParams as $extraParam) {
                 $validationMessages .= $extraParam . PHP_EOL;
             }
             $validationMessages .= PHP_EOL;
         }
         if (!empty($missingValues)) {
             $validationMessages .= 'Parameters missing value:' . PHP_EOL;
             foreach ($missingValues as $missingValue) {
                 $validationMessages .= $missingValue . PHP_EOL;
             }
             $validationMessages .= PHP_EOL;
         }
         if (!empty($extraValues)) {
             $validationMessages .= 'Parameters that don\'t need value:' . PHP_EOL;
             foreach ($extraValues as $extraValue) {
                 $validationMessages .= $extraValue . PHP_EOL;
             }
             $validationMessages .= PHP_EOL;
         }
         if (empty($missingParams) && empty($extraParams) && empty($missingValues) && empty($extraValue)) {
             $validationMessages .= 'Please make sure parameters are in correct format and are not repeated.';
             $validationMessages .= PHP_EOL . PHP_EOL;
         }
         // add usage message
         $usages = ConsoleController::getCommandUsage();
         $validationMessages .= 'Usage:' . PHP_EOL . "{$userAction} ";
         $validationMessages .= $usages[$userAction] . PHP_EOL . PHP_EOL;
     } else {
         if (!is_null($userAction)) {
             $validationMessages .= PHP_EOL . "Unknown action name '{$userAction}'." . PHP_EOL . PHP_EOL;
         } else {
             $validationMessages .= PHP_EOL . "No action is given in the command." . PHP_EOL . PHP_EOL;
         }
         $validationMessages .= 'Available options: ' . PHP_EOL;
         foreach (array_keys($config) as $action) {
             $validationMessages .= $action . PHP_EOL;
         }
         $validationMessages .= PHP_EOL;
     }
     return $validationMessages;
 }
Esempio n. 4
0
<?php

/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
use Magento\Setup\Controller\ConsoleController;
return ['router' => ['routes' => ['literal' => ['type' => 'Literal', 'options' => ['route' => '/', 'defaults' => ['controller' => 'Magento\\Setup\\Controller\\Index', 'action' => 'index']]], 'setup' => ['type' => 'Segment', 'options' => ['route' => '[/:controller[/:action]]', 'defaults' => ['__NAMESPACE__' => 'Magento\\Setup\\Controller', 'controller' => 'Index', 'action' => 'index'], 'constraints' => ['controller' => '[a-zA-Z][a-zA-Z0-9_-]*', 'action' => '[a-zA-Z][a-zA-Z0-9_-]*']]]]], 'console' => ['router' => ['routes' => ConsoleController::getRouterConfig()]]];