mageekguy\atoum\scripts\runner::setArgumentHandlers PHP Method

setArgumentHandlers() protected method

protected setArgumentHandlers ( )
    protected function setArgumentHandlers()
    {
        parent::setArgumentHandlers()->addArgumentHandler(function ($script, $argument, $values) {
            if (sizeof($values) !== 0) {
                throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
            }
            $script->version();
        }, array('-v', '--version'), null, $this->locale->_('Display version'))->addArgumentHandler(function ($script, $argument, $values) {
            if (sizeof($values) !== 0) {
                throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
            }
            $script->resetVerbosityLevel();
            $verbosityLevel = substr_count($argument, '+');
            while ($verbosityLevel--) {
                $script->increaseVerbosityLevel();
            }
        }, array('+verbose', '++verbose'), null, $this->locale->_('Enable verbose mode'))->addArgumentHandler(function ($script, $argument, $values) {
            if (sizeof($values) === 0) {
                $values = array(getcwd());
            }
            $script->init(current($values));
        }, array('--init'), '<path/to/directory>', $this->locale->_('Create configuration and bootstrap files in <path/to/directory> (Optional, default: %s)', $this->getDirectory()))->addArgumentHandler(function ($script, $argument, $path) {
            if (sizeof($path) != 1) {
                throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
            }
            $script->setPhpPath(reset($path));
        }, array('-p', '--php'), '<path/to/php/binary>', $this->locale->_('Path to PHP binary which must be used to run tests'))->addArgumentHandler(function ($script, $argument, $defaultReportTitle) {
            if (sizeof($defaultReportTitle) != 1) {
                throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
            }
            $script->setDefaultReportTitle(reset($defaultReportTitle));
        }, array('-drt', '--default-report-title'), '<string>', $this->locale->_('Define default report title with <string>'))->addArgumentHandler(function ($script, $argument, $file) {
            if (sizeof($file) != 1) {
                throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
            }
            $script->setScoreFile(reset($file));
        }, array('-sf', '--score-file'), '<file>', $this->locale->_('Save score in file <file>'))->addArgumentHandler(function ($script, $argument, $maxChildrenNumber) {
            if (sizeof($maxChildrenNumber) != 1) {
                throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
            }
            $script->setMaxChildrenNumber(reset($maxChildrenNumber));
        }, array('-mcn', '--max-children-number'), '<integer>', $this->locale->_('Maximum number of sub-processus which will be run simultaneously'))->addArgumentHandler(function ($script, $argument, $empty) {
            if ($empty) {
                throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
            }
            $script->disableCodeCoverage();
        }, array('-ncc', '--no-code-coverage'), null, $this->locale->_('Disable code coverage'))->addArgumentHandler(function ($script, $argument, $directories) {
            if (sizeof($directories) <= 0) {
                throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
            }
            $script->excludeDirectoriesFromCoverage($directories);
        }, array('-nccid', '--no-code-coverage-in-directories'), '<directory>...', $this->locale->_('Disable code coverage in directories <directory>'))->addArgumentHandler(function ($script, $argument, $namespaces) {
            if (sizeof($namespaces) <= 0) {
                throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
            }
            $script->excludeNamespacesFromCoverage($namespaces);
        }, array('-nccfns', '--no-code-coverage-for-namespaces'), '<namespace>...', $this->locale->_('Disable code coverage for namespaces <namespace>'))->addArgumentHandler(function ($script, $argument, $classes) {
            if (sizeof($classes) <= 0) {
                throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
            }
            $script->excludeClassesFromCoverage($classes);
        }, array('-nccfc', '--no-code-coverage-for-classes'), '<class>...', $this->locale->_('Disable code coverage for classes <class>'))->addArgumentHandler(function ($script, $argument, $classes) {
            if (sizeof($classes) <= 0) {
                throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
            }
            $script->excludeMethodsFromCoverage($classes);
        }, array('-nccfm', '--no-code-coverage-for-methods'), '<method>...', $this->locale->_('Disable code coverage for methods <method>'))->addArgumentHandler(function ($script, $argument, $empty) {
            if ($empty) {
                throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
            }
            $script->enableBranchesAndPathsCoverage();
        }, array('-ebpc', '--enable-branch-and-path-coverage'), null, $this->locale->_('Enable branch and path coverage'))->addArgumentHandler(function ($script, $argument, $files) {
            if (sizeof($files) <= 0) {
                throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
            }
            $script->addTests($files);
        }, array('-f', '--files'), '<file>...', $this->locale->_('Execute all unit test files <file>'))->addArgumentHandler(function ($script, $argument, $directories) {
            if (sizeof($directories) <= 0) {
                throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
            }
            $script->addTestsFromDirectories($directories);
        }, array('-d', '--directories'), '<directory>...', $this->locale->_('Execute unit test files in all <directory>'))->addArgumentHandler(function ($script, $argument, $extensions) {
            if (sizeof($extensions) <= 0) {
                throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
            }
            $script->acceptTestFileExtensions($extensions);
        }, array('-tfe', '--test-file-extensions'), '<extension>...', $this->locale->_('Execute unit test files with one of extensions <extension>'))->addArgumentHandler(function ($script, $argument, $patterns) {
            if (sizeof($patterns) <= 0) {
                throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
            }
            $script->addTestsFromPatterns($patterns);
        }, array('-g', '--glob'), '<pattern>...', $this->locale->_('Execute unit test files which match <pattern>'))->addArgumentHandler(function ($script, $argument, $tags) {
            if (sizeof($tags) <= 0) {
                throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
            }
            $script->testTags($tags);
        }, array('-t', '--tags'), '<tag>...', $this->locale->_('Execute only unit test with tags <tag>'))->addArgumentHandler(function ($script, $argument, $methods) {
            if (sizeof($methods) <= 0) {
                throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
            }
            foreach ($methods as $method) {
                $method = explode('::', $method);
                if (sizeof($method) != 2) {
                    throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
                }
                $script->testMethod($method[0], $method[1]);
            }
        }, array('-m', '--methods'), '<class::method>...', $this->locale->_('Execute all <class::method>, * may be used as wildcard for class name or method name'))->addArgumentHandler(function ($script, $argument, $namespaces) {
            if (sizeof($namespaces) <= 0) {
                throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
            }
            $script->testNamespaces($namespaces);
        }, array('-ns', '--namespaces'), '<namespace>...', $this->locale->_('Execute all classes in all namespaces <namespace>'))->addArgumentHandler(function ($script, $argument, $values) {
            if ($values) {
                throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
            }
            $script->enableLoopMode();
        }, array('-l', '--loop'), null, $this->locale->_('Execute tests in an infinite loop'))->addArgumentHandler(function ($script, $argument, $values) {
            if (sizeof($values) !== 0) {
                throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
            }
            $script->disableLoopMode();
        }, array('--disable-loop-mode'), null, null, 3)->addArgumentHandler(function ($script, $argument, $values) {
            if (sizeof($values) !== 0) {
                throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
            }
            $script->testIt();
        }, array('--test-it'), null, $this->locale->_('Execute atoum unit tests'))->addArgumentHandler(function ($script, $argument, $values) {
            $script->writeError('--test-all argument is deprecated, please do $runner->addTestsFromDirectory(\'path/to/default/tests/directory\') in a configuration file and use atoum without any argument instead');
        }, array('--test-all'), null, $this->locale->_('DEPRECATED, please do $runner->addTestsFromDirectory(\'path/to/default/tests/directory\') in a configuration file and use atoum without any argument instead'))->addArgumentHandler(function ($script, $argument, $values) {
            if ($values) {
                throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
            }
            \mageekguy\atoum\cli::forceTerminal();
        }, array('-ft', '--force-terminal'), null, $this->locale->_('Force output as in terminal'))->addArgumentHandler(function ($script, $argument, $values) {
            if (sizeof($values) != 1) {
                throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
            }
            $script->setAutoloaderFile($values[0]);
        }, array('-af', '--autoloader-file'), '<file>', $this->locale->_('Include autoloader <file> before executing each test method'), 2)->addArgumentHandler(function ($script, $argument, $values) {
            if (sizeof($values) != 1) {
                throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
            }
            $script->setBootstrapFile($values[0]);
        }, array('-bf', '--bootstrap-file'), '<file>', $this->locale->_('Include bootstrap <file> before executing each test method'), 2)->addArgumentHandler(function ($script, $argument, $values) {
            if (sizeof($values) != 0) {
                throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
            }
            $lightReport = new atoum\reports\realtime\cli\light();
            $lightReport->addWriter($script->getOutputWriter());
            $script->setReport($lightReport);
        }, array('-ulr', '--use-light-report'), null, $this->locale->_('Use "light" CLI report'), PHP_INT_MAX)->addArgumentHandler(function ($script, $argument, $values) {
            if (sizeof($values) != 0) {
                throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
            }
            $tapReport = new atoum\reports\realtime\tap();
            $tapReport->addWriter($script->getOutputWriter());
            $script->setReport($tapReport);
        }, array('-utr', '--use-tap-report'), null, $this->locale->_('Use TAP report'), PHP_INT_MAX)->addArgumentHandler(function ($script, $argument, $values) {
            if (sizeof($values) != 0) {
                throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
            }
            $script->enableDebugMode();
        }, array('--debug'), null, $this->locale->_('Enable debug mode'))->addArgumentHandler(function ($script, $argument, $values) {
            if (sizeof($values) != 1) {
                throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
            }
            $script->setXdebugConfig($values[0]);
        }, array('-xc', '--xdebug-config'), null, $this->locale->_('Set XDEBUG_CONFIG variable'))->addArgumentHandler(function ($script, $argument, $values) {
            $script->failIfVoidMethods();
        }, array('-fivm', '--fail-if-void-methods'), null, $this->locale->_('Make the test suite fail if there is at least one void test method'))->addArgumentHandler(function ($script, $argument, $values) {
            $script->failIfSkippedMethods();
        }, array('-fism', '--fail-if-skipped-methods'), null, $this->locale->_('Make the test suite fail if there is at least one skipped test method'));
        $this->setDefaultArgumentHandler(function ($script, $argument) {
            try {
                $script->getRunner()->addTest($argument);
            } catch (\exception $exception) {
                return false;
            }
            return true;
        });
        return $this;
    }

Usage Example

Esempio n. 1
0
 protected function setArgumentHandlers()
 {
     return parent::setArgumentHandlers()->addArgumentHandler(function ($script, $argument, $values) {
         if (sizeof($values) === 0) {
             throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
         }
         $script->setReportFormat(current($values));
     }, array('-fmt', '--format'), '<xml|clover|html|treemap>', $this->locale->_('Coverage report format'))->addArgumentHandler(function ($script, $argument, $values) {
         if (sizeof($values) === 0) {
             throw new exceptions\logic\invalidArgument(sprintf($script->getLocale()->_('Bad usage of %s, do php %s --help for more informations'), $argument, $script->getName()));
         }
         $script->setReportOutputPath(current($values));
     }, array('-o', '--output'), '<path/to/file/or/directory>', $this->locale->_('Coverage report output path'));
 }
All Usage Examples Of mageekguy\atoum\scripts\runner::setArgumentHandlers