diff --git a/.appveyor.yml b/.appveyor.yml index b67a649..3e221d0 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -77,5 +77,6 @@ install: test_script: - cd c:\projects\behat-code-coverage + - bin\phpcs - phpdbg -qrr vendor\phpunit\phpunit\phpunit -vvv diff --git a/.travis.yml b/.travis.yml index 690aca7..bbd1387 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,5 +16,7 @@ before_script: - composer validate - if [[ $deps = low ]]; then composer update --prefer-lowest --prefer-stable; else composer update; fi -script: ./bin/phpunit -vvv +script: + - ./bin/phpcs + - ./bin/phpunit -vvv diff --git a/CHANGELOG.md b/CHANGELOG.md index f313097..3d74616 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Version constraints in composer.json have been updated from `~` to `^`. +## [3.2.1] - 2018-03-19 + +- Fix Text report generation #5 + ## [3.2.0] - 2017-10-17 - Guzzle 6.0 support release - Updated `guzzlehttp/guzzle` requirement from `~4.0||~5.0` to `~6.0`. We are diff --git a/composer.json b/composer.json index 5b69c84..59e8d9d 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,9 @@ }, "require-dev": { "phpunit/phpunit": "^6.0", - "mikey179/vfsStream": "1.6.*" + "mikey179/vfsStream": "1.6.*", + "squizlabs/php_codesniffer": "^3.2", + "escapestudios/symfony2-coding-standard": "^3.1" }, "suggest": { "ext-xdebug": "Xdebug extension is required to collect coverage via Xdebug driver and run tests", diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 0000000..0498173 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,20 @@ + + + + LeanPHP Coding Standard + + + src + + + test + tests + *Spec.php + + + + > + + + + diff --git a/src/Common/Driver/Factory.php b/src/Common/Driver/Factory.php index 527e969..0388f1b 100644 --- a/src/Common/Driver/Factory.php +++ b/src/Common/Driver/Factory.php @@ -3,6 +3,7 @@ * Code Coverage Driver Factory * * @copyright 2013 Anthon Pang + * * @license BSD-3-Clause */ diff --git a/src/Common/Driver/HHVM.php b/src/Common/Driver/HHVM.php index 6d265b4..d7682f2 100644 --- a/src/Common/Driver/HHVM.php +++ b/src/Common/Driver/HHVM.php @@ -3,6 +3,7 @@ * HHVM Code Coverage Driver * * @copyright 2013 Anthon Pang + * * @license BSD-3-Clause */ @@ -27,7 +28,7 @@ class HHVM implements DriverInterface */ public function __construct() { - if ( ! defined('HPHP_VERSION')) { + if (! defined('HPHP_VERSION')) { throw new \SebastianBergmann\CodeCoverage\RuntimeException('This driver requires HHVM'); } } diff --git a/src/Common/Driver/Stub.php b/src/Common/Driver/Stub.php index b3ff988..2095e92 100644 --- a/src/Common/Driver/Stub.php +++ b/src/Common/Driver/Stub.php @@ -3,6 +3,7 @@ * Code Coverage Stub Driver * * @copyright 2013 Anthon Pang + * * @license BSD-3-Clause */ diff --git a/src/Common/Driver/XCache.php b/src/Common/Driver/XCache.php index 71e0561..a0b0539 100644 --- a/src/Common/Driver/XCache.php +++ b/src/Common/Driver/XCache.php @@ -3,6 +3,7 @@ * XCache Code Coverage Driver * * @copyright 2013 Anthon Pang + * * @license BSD-3-Clause */ @@ -26,7 +27,7 @@ class XCache implements DriverInterface */ public function __construct() { - if ( ! extension_loaded('xcache')) { + if (! extension_loaded('xcache')) { throw new \SebastianBergmann\CodeCoverage\RuntimeException('This driver requires XCache'); } diff --git a/src/Common/Model/Aggregate.php b/src/Common/Model/Aggregate.php index d1999d5..8dc6d67 100644 --- a/src/Common/Model/Aggregate.php +++ b/src/Common/Model/Aggregate.php @@ -3,6 +3,7 @@ * Aggregate * * @copyright 2013 Anthon Pang + * * @license BSD-3-Clause */ @@ -36,14 +37,14 @@ public function __construct() */ public function update($class, array $counts) { - if ( ! isset($this->coverage[$class])) { + if (! isset($this->coverage[$class])) { $this->coverage[$class] = $counts; return; } foreach ($counts as $line => $status) { - if ( ! isset($this->coverage[$class][$line]) || $status > 0) { + if (! isset($this->coverage[$class][$line]) || $status > 0) { // converts "hits" to "status" $status = ! $status ? -1 : ($status > 1 ? 1 : $status); diff --git a/src/Common/Report/Clover.php b/src/Common/Report/Clover.php index 286d740..2476e14 100644 --- a/src/Common/Report/Clover.php +++ b/src/Common/Report/Clover.php @@ -3,6 +3,7 @@ * Code Coverage Clover Report * * @copyright 2013 Anthon Pang + * * @license BSD-3-Clause */ @@ -34,11 +35,11 @@ class Clover implements ReportInterface */ public function __construct(array $options) { - if ( ! isset($options['target'])) { + if (! isset($options['target'])) { $options['target'] = null; } - if ( ! isset($options['name'])) { + if (! isset($options['name'])) { $options['name'] = null; } diff --git a/src/Common/Report/Crap4j.php b/src/Common/Report/Crap4j.php index 71adda3..f1345d0 100644 --- a/src/Common/Report/Crap4j.php +++ b/src/Common/Report/Crap4j.php @@ -3,6 +3,7 @@ * Code Coverage Crap4j Report * * @copyright 2013 Anthon Pang + * * @license BSD-3-Clause */ @@ -11,6 +12,7 @@ use LeanPHP\Behat\CodeCoverage\Common\ReportInterface; use SebastianBergmann\CodeCoverage\CodeCoverage; use SebastianBergmann\CodeCoverage\Report\Crap4j as Crap4jReport; + /** * Crap4j report * @@ -33,15 +35,15 @@ class Crap4j implements ReportInterface */ public function __construct(array $options) { - if ( ! class_exists('SebastianBergmann\CodeCoverage\Report\Crap4j')) { + if (! class_exists('SebastianBergmann\CodeCoverage\Report\Crap4j')) { throw new \Exception('Crap4j requires CodeCoverage 4.0+'); } - if ( ! isset($options['target'])) { + if (! isset($options['target'])) { $options['target'] = null; } - if ( ! isset($options['name'])) { + if (! isset($options['name'])) { $options['name'] = null; } diff --git a/src/Common/Report/Factory.php b/src/Common/Report/Factory.php index c629b88..9c1a616 100644 --- a/src/Common/Report/Factory.php +++ b/src/Common/Report/Factory.php @@ -3,6 +3,7 @@ * Code Coverage Report Factory * * @copyright 2013 Anthon Pang + * * @license BSD-3-Clause */ @@ -26,7 +27,7 @@ class Factory public function create($reportType, array $options) { if (in_array($reportType, array('clover', 'crap4j', 'html', 'php', 'text', 'xml'))) { - $className = '\LeanPHP\Behat\CodeCoverage\Common\Report\\' . ucfirst($reportType); + $className = '\LeanPHP\Behat\CodeCoverage\Common\Report\\'.ucfirst($reportType); return new $className($options); } diff --git a/src/Common/Report/Html.php b/src/Common/Report/Html.php index eb91691..925a3d5 100644 --- a/src/Common/Report/Html.php +++ b/src/Common/Report/Html.php @@ -3,6 +3,7 @@ * Code Coverage HTML Report * * @copyright 2013 Anthon Pang + * * @license BSD-3-Clause */ @@ -34,27 +35,27 @@ class Html implements ReportInterface */ public function __construct(array $options) { - if ( ! isset($options['target'])) { + if (! isset($options['target'])) { $options['target'] = null; } - if ( ! isset($options['charset'])) { + if (! isset($options['charset'])) { $options['charset'] = 'UTF-8'; } - if ( ! isset($options['highlight'])) { + if (! isset($options['highlight'])) { $options['highlight'] = false; } - if ( ! isset($options['lowUpperBound'])) { + if (! isset($options['lowUpperBound'])) { $options['lowUpperBound'] = 35; } - if ( ! isset($options['highUpperBound'])) { + if (! isset($options['highUpperBound'])) { $options['highUpperBound'] = 70; } - if ( ! isset($options['generator'])) { + if (! isset($options['generator'])) { $options['generator'] = ''; } diff --git a/src/Common/Report/Php.php b/src/Common/Report/Php.php index a069026..0248963 100644 --- a/src/Common/Report/Php.php +++ b/src/Common/Report/Php.php @@ -3,6 +3,7 @@ * Code Coverage PHP Report * * @copyright 2013 Anthon Pang + * * @license BSD-3-Clause */ @@ -34,7 +35,7 @@ class Php implements ReportInterface */ public function __construct(array $options) { - if ( ! isset($options['target'])) { + if (! isset($options['target'])) { $options['target'] = null; } diff --git a/src/Common/Report/Text.php b/src/Common/Report/Text.php index 74782ac..935cb7f 100644 --- a/src/Common/Report/Text.php +++ b/src/Common/Report/Text.php @@ -3,6 +3,7 @@ * Code Coverage Text Report * * @copyright 2013 Anthon Pang + * * @license BSD-3-Clause */ @@ -34,23 +35,23 @@ class Text implements ReportInterface */ public function __construct(array $options) { - if ( ! isset($options['showColors'])) { + if (! isset($options['showColors'])) { $options['showColors'] = false; } - if ( ! isset($options['printer'])) { + if (! isset($options['printer'])) { $options['printer'] = null; } - if ( ! isset($options['lowUpperBound'])) { + if (! isset($options['lowUpperBound'])) { $options['lowUpperBound'] = 35; } - if ( ! isset($options['highUpperBound'])) { + if (! isset($options['highUpperBound'])) { $options['highUpperBound'] = 70; } - if ( ! isset($options['showUncoveredFiles'])) { + if (! isset($options['showUncoveredFiles'])) { $options['showUncoveredFiles'] = false; } @@ -64,7 +65,7 @@ public function __construct(array $options) $options['showUncoveredFiles'] ); } else { - if ( ! isset($options['showOnlySummary'])) { + if (! isset($options['showOnlySummary'])) { $options['showOnlySummary'] = false; } @@ -90,6 +91,11 @@ public function process(CodeCoverage $coverage) ); } + /** + * return version of CodeCoverage + * + * @return string + */ private function getVersion() { $reflectionMethod = new \ReflectionMethod('SebastianBergmann\CodeCoverage\Report\Text', '__construct'); diff --git a/src/Common/Report/Xml.php b/src/Common/Report/Xml.php index 91b3be3..c5065a9 100644 --- a/src/Common/Report/Xml.php +++ b/src/Common/Report/Xml.php @@ -3,6 +3,7 @@ * Code Coverage XML Report * * @copyright 2013 Anthon Pang + * * @license BSD-3-Clause */ @@ -10,7 +11,7 @@ use LeanPHP\Behat\CodeCoverage\Common\ReportInterface; use SebastianBergmann\CodeCoverage\CodeCoverage; -use SebastianBergmann\CodeCoverage\Report\Xml\Facade;; +use SebastianBergmann\CodeCoverage\Report\Xml\Facade; /** * XML report @@ -34,11 +35,11 @@ class Xml implements ReportInterface */ public function __construct(array $options) { - if ( ! class_exists('SebastianBergmann\CodeCoverage\Report\Xml\Facade')) { + if (! class_exists('SebastianBergmann\CodeCoverage\Report\Xml\Facade')) { throw new \Exception('XML requires CodeCoverage 4.0+'); } - if ( ! isset($options['target'])) { + if (! isset($options['target'])) { $options['target'] = null; } diff --git a/src/Common/ReportInterface.php b/src/Common/ReportInterface.php index dcb15f8..759b879 100644 --- a/src/Common/ReportInterface.php +++ b/src/Common/ReportInterface.php @@ -3,6 +3,7 @@ * Report * * @copyright 2013 Anthon Pang + * * @license BSD-3-Clause */ diff --git a/src/Compiler/DriverPass.php b/src/Compiler/DriverPass.php index a9c410b..07c620e 100644 --- a/src/Compiler/DriverPass.php +++ b/src/Compiler/DriverPass.php @@ -3,6 +3,7 @@ * Driver Compiler Pass * * @copyright 2013 Anthon Pang + * * @license BSD-2-Clause */ diff --git a/src/Compiler/FactoryPass.php b/src/Compiler/FactoryPass.php index 4ed22a4..d0de3e9 100644 --- a/src/Compiler/FactoryPass.php +++ b/src/Compiler/FactoryPass.php @@ -3,6 +3,7 @@ * Factory Compiler Pass * * @copyright 2013 Anthon Pang + * * @license BSD-2-Clause */ diff --git a/src/Compiler/FilterPass.php b/src/Compiler/FilterPass.php index b2487bb..a6834fb 100644 --- a/src/Compiler/FilterPass.php +++ b/src/Compiler/FilterPass.php @@ -3,6 +3,7 @@ * Filter Compiler Pass * * @copyright 2013 Anthon Pang + * * @license BSD-2-Clause */ @@ -28,6 +29,9 @@ public function process(ContainerBuilder $container) $this->processCodeCoverageFilter($container); } + /** + * @param ContainerBuilder $container + */ private function processCodeCoverage(ContainerBuilder $container) { if (! $container->hasDefinition('behat.code_coverage.php_code_coverage')) { @@ -55,6 +59,9 @@ private function processCodeCoverage(ContainerBuilder $container) ); } + /** + * @param ContainerBuilder $container + */ private function processCodeCoverageFilter(ContainerBuilder $container) { if (! $container->hasDefinition('behat.code_coverage.php_code_coverage_filter')) { diff --git a/src/Driver/Proxy.php b/src/Driver/Proxy.php index 963fd73..fd1a1e5 100644 --- a/src/Driver/Proxy.php +++ b/src/Driver/Proxy.php @@ -3,6 +3,7 @@ * Proxy Code Coverage Driver * * @copyright 2013 Anthon Pang + * * @license BSD-2-Clause */ @@ -51,7 +52,7 @@ public function start($determineUnusedAndDead = true) */ public function stop() { - $aggregate = new Aggregate; + $aggregate = new Aggregate(); foreach ($this->drivers as $driver) { $coverage = $driver->stop(); diff --git a/src/Driver/RemoteXdebug.php b/src/Driver/RemoteXdebug.php index 40af55a..4bf3fe6 100644 --- a/src/Driver/RemoteXdebug.php +++ b/src/Driver/RemoteXdebug.php @@ -3,6 +3,7 @@ * Code Coverage Driver * * @copyright 2013 Anthon Pang + * * @license BSD-2-Clause */ @@ -52,7 +53,7 @@ class RemoteXdebug implements DriverInterface * ], * ] * - * @param array $config Configuration + * @param array $config Configuration * @param GuzzleHttp\Client $client HTTP client */ public function __construct(array $config, Client $client) @@ -71,7 +72,7 @@ public function start($determineUnusedAndDead = true) $response = $this->sendRequest('create'); if ($response->getStatusCode() !== 200) { - throw new \Exception('remote driver start failed: ' . $response->getReasonPhrase()); + throw new \Exception(sprintf('remote driver start failed: %s', $response->getReasonPhrase())); } } @@ -83,7 +84,7 @@ public function stop() $response = $this->sendRequest('read', ['headers' => ['Accept' => 'application/json']]); if ($response->getStatusCode() !== 200) { - throw new \Exception('remote driver fetch failed: ' . $response->getReasonPhrase()); + throw new \Exception(sprintf('remote driver fetch failed: %s', $response->getReasonPhrase())); } $response = $this->sendRequest('delete'); @@ -104,20 +105,24 @@ private function sendRequest($endpoint, $headers = array()) $method = strtolower($this->config[$endpoint]['method']); if (! in_array($method, array('get', 'post', 'put', 'delete'))) { - throw new \Exception($endpoint . ' method must be GET, POST, PUT, or DELETE'); + throw new \Exception(sprintf('%s method must be GET, POST, PUT, or DELETE', $endpoint)); } if (isset($this->config['auth'])) { - $response = $this->client->request($method, - $this->config[$endpoint]['path'], [ + $response = $this->client->request( + $method, + $this->config[$endpoint]['path'], + [ 'auth' => [$this->config['auth']['user'], $this->config['auth']['password']], 'headers' => $headers, ] ); } else { - $response = $this->client->request($method, - $this->config[$endpoint]['path'], [ - 'headers' => $headers + $response = $this->client->request( + $method, + $this->config[$endpoint]['path'], + [ + 'headers' => $headers, ] ); } diff --git a/src/Extension.php b/src/Extension.php index b08826c..6f17215 100644 --- a/src/Extension.php +++ b/src/Extension.php @@ -3,6 +3,7 @@ * Code Coverage Extension for Behat * * @copyright 2013 Anthon Pang + * * @license BSD-2-Clause */ @@ -35,7 +36,7 @@ class Extension implements ExtensionInterface */ public function __construct($configFolder = null) { - $this->configFolder = $configFolder ?: __DIR__ . '/Resources/config'; + $this->configFolder = $configFolder ?: __DIR__.'/Resources/config'; } /** @@ -68,7 +69,7 @@ public function load(ContainerBuilder $container, array $config) if (! count($config['report']['options'])) { $config['report']['options'] = array( - 'target' => '/tmp' + 'target' => '/tmp', ); } @@ -212,6 +213,11 @@ public function process(ContainerBuilder $container) } } + /** + * return an array of compiler passes + * + * @return array + */ private function getCompilerPasses() { return array( diff --git a/src/Listener/EventListener.php b/src/Listener/EventListener.php index 45c688c..1734b4d 100644 --- a/src/Listener/EventListener.php +++ b/src/Listener/EventListener.php @@ -3,6 +3,7 @@ * Event Listener * * @copyright 2013 Anthon Pang + * * @license BSD-2-Clause */ @@ -78,7 +79,7 @@ public function beforeExercise(ExerciseCompleted $event) public function beforeScenario(ScenarioTested $event) { $node = $event->getScenario(); - $id = $event->getFeature()->getFile() . ':' . $node->getLine(); + $id = $event->getFeature()->getFile().':'.$node->getLine(); $this->coverage->start($id); } diff --git a/src/Service/ReportService.php b/src/Service/ReportService.php index e7142c6..f4901b6 100644 --- a/src/Service/ReportService.php +++ b/src/Service/ReportService.php @@ -3,6 +3,7 @@ * Code Coverage Report Service * * @copyright 2013 Anthon Pang + * * @license BSD-2-Clause */ @@ -31,7 +32,7 @@ class ReportService /** * Constructor * - * @param array $config + * @param array $config * @param \LeanPHP\Behat\CodeCoverage\Common\Report\Factory $factory */ public function __construct(array $config, Factory $factory)