mirrored from https://git.sr.ht/~ancarda/high-test-coverage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 532d1c0
Showing
26 changed files
with
4,961 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
image: debian/buster | ||
|
||
sources: | ||
- https://git.sr.ht/~ancarda/psr7-string-stream | ||
|
||
packages: | ||
- php7.3-cli | ||
- composer | ||
|
||
# some dev tools use XML config files | ||
- php7.3-xml | ||
|
||
# for code coverage (phpunit and infection) | ||
- php-xdebug | ||
|
||
# for composer | ||
- unzip | ||
|
||
environment: | ||
DIR: psr7-string-stream | ||
XDEBUG_MODE: coverage | ||
|
||
tasks: | ||
- composer: cd $DIR && composer install | ||
- analyze: cd $DIR && composer run-script analyze | ||
- check-style: cd $DIR && composer run-script check-style | ||
- test: cd $DIR && composer run-script test | ||
- check-cov: cd $DIR && composer run-script check-coverage | ||
- check-tests: cd $DIR && composer run-script check-tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
image: debian/bullseye | ||
|
||
sources: | ||
- https://git.sr.ht/~ancarda/psr7-string-stream | ||
|
||
packages: | ||
- php7.4-cli | ||
- composer | ||
|
||
# some dev tools use XML config files | ||
- php7.4-xml | ||
|
||
# for code coverage (phpunit and infection) | ||
- php-xdebug | ||
|
||
# for composer | ||
- unzip | ||
|
||
environment: | ||
DIR: psr7-string-stream | ||
XDEBUG_MODE: coverage | ||
|
||
tasks: | ||
- composer: cd $DIR && composer install | ||
- analyze: cd $DIR && composer run-script analyze | ||
- check-style: cd $DIR && composer run-script check-style | ||
- test: cd $DIR && composer run-script test | ||
- check-cov: cd $DIR && composer run-script check-coverage | ||
- check-tests: cd $DIR && composer run-script check-tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
image: debian/sid | ||
|
||
sources: | ||
- https://git.sr.ht/~ancarda/psr7-string-stream | ||
|
||
packages: | ||
- php8.0-cli | ||
- composer | ||
|
||
# PHP 8.0 on debian/sid does not come with mbstring by default? | ||
# See: https://builds.sr.ht/~ancarda/job/453331 | ||
- php8.0-mbstring | ||
|
||
# some dev tools use XML config files | ||
- php8.0-xml | ||
|
||
# for code coverage (phpunit and infection) | ||
- php-xdebug | ||
|
||
# for composer | ||
- unzip | ||
|
||
environment: | ||
DIR: psr7-string-stream | ||
XDEBUG_MODE: coverage | ||
|
||
tasks: | ||
- composer: cd $DIR && composer install | ||
- analyze: cd $DIR && composer run-script analyze | ||
- check-style: cd $DIR && composer run-script check-style | ||
- test: cd $DIR && composer run-script test | ||
|
||
# coverage is not yet working on PHP 8.0 | ||
# See: https://builds.sr.ht/~ancarda/job/453338#task-check-tests | ||
# - check-tests: cd $DIR && composer run-script check-tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Expat License | ||
|
||
Copyright (c) 2021 Mark Dain <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# High Test Coverage | ||
|
||
[![builds.sr.ht status](https://builds.sr.ht/~ancarda/high-test-coverage.svg)](https://builds.sr.ht/~ancarda/high-test-coverage) | ||
|
||
High Test Coverage is a collection of classes and interfaces designed to help | ||
you get higher test coverage when using impure parts of the PHP Standard | ||
Library. It provides a `RandomInt` interface which you can use in place of the | ||
`random_int` function, like so: | ||
|
||
Pull down with composer: | ||
|
||
composer require --dev ancarda/high-test-coverage | ||
|
||
## Example Usage | ||
|
||
```php | ||
<?php | ||
|
||
use Ancarda\HighTestCoverage\RandomInt\RandomInt; | ||
|
||
final class Genie | ||
{ | ||
public function __construct(private RandomInt $randomInt) {} | ||
|
||
public function fortune(): string | ||
{ | ||
return 'Your lucky number is ' . $this->randomInt(1, 10); | ||
} | ||
} | ||
``` | ||
|
||
In production, this class would be given an instance of `RandomInt\Real`, | ||
likely via your Dependency Injection container. Under test, you would use one | ||
of the many built-in classes, such as `Fixed` or `OneShot`, like so: | ||
|
||
```php | ||
<?php | ||
|
||
use Ancarda\HighTestCoverage\RandomInt\Fixed; | ||
|
||
final class GenieTest extends TestCase | ||
{ | ||
public function testFortune(): void | ||
{ | ||
$genie = new Genie(new Fixed(42)); | ||
self::assertSame('Your lucky number is 42', $genie->fortune()); | ||
} | ||
} | ||
``` | ||
|
||
## Useful Links | ||
|
||
* Source Code: <https://git.sr.ht/~ancarda/high-test-coverage> | ||
* Issue Tracker: <https://todo.sr.ht/~ancarda/high-test-coverage> | ||
* Mailing List: <https://lists.sr.ht/~ancarda/high-test-coverage> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"name": "ancarda/high-test-coverage", | ||
"description": "Classes and Interfaces to help you get higher test coverage", | ||
"type": "library", | ||
"license": "MIT", | ||
"config": { | ||
"sort-packages": true | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Ancarda\\HighTestCoverage\\": "src" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Tests\\": "tests" | ||
} | ||
}, | ||
"require": { | ||
"php": "^7.3|^8.0" | ||
}, | ||
"require-dev": { | ||
"ancarda/coverage-enforcer": "^1.0", | ||
"infection/infection": "^0.21.4", | ||
"phpstan/phpstan": "^0.12.82", | ||
"phpstan/phpstan-phpunit": "^0.12.18", | ||
"phpstan/phpstan-strict-rules": "^0.12.9", | ||
"phpunit/phpunit": "^9.5", | ||
"squizlabs/php_codesniffer": "^3.5" | ||
}, | ||
"scripts": { | ||
"analyze": "phpstan", | ||
"check-coverage": "enforce-coverage --minStmtCov 100 var/coverage/coverage.clover.xml", | ||
"check-style": "phpcs", | ||
"check-tests": "infection", | ||
"fix-style": "phpcbf", | ||
"test": "phpunit" | ||
} | ||
} |
Oops, something went wrong.