diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 29b90af..9ac7192 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,4 +33,10 @@ jobs: php-version: ${{ matrix.php }} coverage: xdebug - run: composer install - - run: vendor/bin/phpunit --coverage-text ${{ matrix.php < 7.3 && '-c phpunit.xml.legacy' || '' }} + - run: vendor/bin/phpunit --coverage-text --coverage-clover clover.xml ${{ matrix.php < 7.3 && '-c phpunit.xml.legacy' || '' }} + - name: Check 100% code coverage + shell: php {0} + run: | + project->metrics; + exit((int) $metrics['statements'] === (int) $metrics['coveredstatements'] ? 0 : 1); diff --git a/README.md b/README.md index 38f7174..d3be434 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # clue/reactphp-tar [![CI status](https://github.com/clue/reactphp-tar/actions/workflows/ci.yml/badge.svg)](https://github.com/clue/reactphp-tar/actions) +[![code coverage](https://img.shields.io/badge/code%20coverage-100%25-success)](#tests) [![installs on Packagist](https://img.shields.io/packagist/dt/clue/tar-react?color=blue&label=installs%20on%20Packagist)](https://packagist.org/packages/clue/tar-react) Streaming parser to extract tarballs with [ReactPHP](https://reactphp.org/). @@ -82,6 +83,14 @@ To run the test suite, go to the project root and run: vendor/bin/phpunit ``` +The test suite is set up to always ensure 100% code coverage across all +supported environments. If you have the Xdebug extension installed, you can also +generate a code coverage report locally like this: + +```bash +XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-text +``` + ## License This project is released under the permissive [MIT license](LICENSE). diff --git a/src/TarDecoder.php b/src/TarDecoder.php index d944bd1..9254c6d 100644 --- a/src/TarDecoder.php +++ b/src/TarDecoder.php @@ -35,10 +35,12 @@ public function __construct() { $this->format = "Z100name/Z8mode/Z8uid/Z8gid/Z12size/Z12mtime/Z8checksum/Z1type/Z100symlink/Z6magic/Z2version/Z32owner/Z32group/Z8deviceMajor/Z8deviceMinor/Z155prefix/Z12unpacked"; + // @codeCoverageIgnoreStart if (PHP_VERSION < 5.5) { // PHP 5.5 replaced 'a' with 'Z' (read X bytes and removing trailing NULL bytes) - $this->format = str_replace('Z', 'a', $this->format); // @codeCoverageIgnore + $this->format = str_replace('Z', 'a', $this->format); } + // @codeCoverageIgnoreEnd } public function write($data)