5 * Copyright (c) 2009-2011, Sebastian Bergmann <sb@sebastian-bergmann.de>.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
20 * * Neither the name of Sebastian Bergmann nor the names of his
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
38 * @package CodeCoverage
39 * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
40 * @copyright 2009-2011 Sebastian Bergmann <sb@sebastian-bergmann.de>
41 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
42 * @link http://github.com/sebastianbergmann/php-code-coverage
43 * @since File available since Release 1.0.0
46 require_once 'PHP/CodeCoverage.php';
48 require_once 'ezc/Base/base.php';
49 spl_autoload_register(array('ezcBase', 'autoload'));
52 * TextUI frontend for PHP_CodeCoverage.
55 * @package CodeCoverage
56 * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
57 * @copyright 2009-2011 Sebastian Bergmann <sb@sebastian-bergmann.de>
58 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
59 * @version Release: 1.0.4
60 * @link http://github.com/sebastianbergmann/php-code-coverage
61 * @since Class available since Release 1.0.0
63 class PHP_CodeCoverage_TextUI_Command
68 public static function main()
70 $input = new ezcConsoleInput;
72 $input->registerOption(
76 ezcConsoleInput::TYPE_STRING
80 $input->registerOption(
84 ezcConsoleInput::TYPE_STRING
88 $input->registerOption(
92 ezcConsoleInput::TYPE_STRING,
98 $input->registerOption(
102 ezcConsoleInput::TYPE_STRING,
108 $input->registerOption(
109 new ezcConsoleOption(
112 ezcConsoleInput::TYPE_NONE,
125 $input->registerOption(
126 new ezcConsoleOption(
129 ezcConsoleInput::TYPE_NONE,
146 catch (ezcConsoleOptionException $e) {
147 print $e->getMessage() . "\n";
151 if ($input->getOption('help')->value) {
156 else if ($input->getOption('version')->value) {
157 self::printVersionString();
161 $arguments = $input->getArguments();
162 $clover = $input->getOption('clover')->value;
163 $html = $input->getOption('html')->value;
164 $blacklist = $input->getOption('blacklist')->value;
165 $whitelist = $input->getOption('whitelist')->value;
167 if (count($arguments) == 1) {
168 self::printVersionString();
170 $coverage = new PHP_CodeCoverage;
171 $filter = $coverage->filter();
173 if (empty($whitelist)) {
174 $c = new ReflectionClass('ezcBase');
175 $filter->addDirectoryToBlacklist(dirname($c->getFileName()));
176 $c = new ReflectionClass('ezcConsoleInput');
177 $filter->addDirectoryToBlacklist(dirname($c->getFileName()));
179 foreach ($blacklist as $item) {
181 $filter->addDirectoryToBlacklist($item);
184 else if (is_file($item)) {
185 $filter->addFileToBlacklist($item);
189 foreach ($whitelist as $item) {
191 $filter->addDirectoryToWhitelist($item);
194 else if (is_file($item)) {
195 $filter->addFileToWhitelist($item);
200 $coverage->start('phpcov');
202 require $arguments[0];
207 require 'PHP/CodeCoverage/Report/Clover.php';
209 $writer = new PHP_CodeCoverage_Report_Clover;
210 $writer->process($coverage, $clover);
214 require 'PHP/CodeCoverage/Report/HTML.php';
216 $writer = new PHP_CodeCoverage_Report_HTML;
217 $writer->process($coverage, $html);
228 * @param string $message
230 protected static function showError($message)
232 self::printVersionString();
242 protected static function showHelp()
244 self::printVersionString();
247 Usage: phpcov [switches] <file>
249 --clover <file> Write code coverage data in Clover XML format.
250 --html <dir> Generate code coverage report in HTML format.
252 --blacklist <dir|file> Adds <dir|file> to the blacklist.
253 --whitelist <dir|file> Adds <dir|file> to the whitelist.
255 --help Prints this usage information.
256 --version Prints the version and exits.
262 * Prints the version string.
264 protected static function printVersionString()
266 print "phpcov 1.0.4 by Sebastian Bergmann.\n\n";