Skip to content

Commit 330ae93

Browse files
Merge pull request #4 from Krinkle/test
Add test suite
2 parents 7bd2e70 + f747db1 commit 330ae93

File tree

5 files changed

+47
-4
lines changed

5 files changed

+47
-4
lines changed

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
sudo: false
2+
language: php
3+
php:
4+
- "7.2"
5+
- "7.1"
6+
- "7.0"
7+
- "5.6"
8+
- "5.5"
9+
script: ./test/run

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
[![Build Status](https://travis-ci.org/richardregeer/phpunit-coverage-check.svg?branch=master)](https://travis-ci.org/richardregeer/phpunit-coverage-check)
2+
13
# phpunit-coverage-check
24
This php script will read the clover xml report from phpunit and calculates the coverage score. Based on the given threshold the script will exit ok of the coverage is higher then the threshold or exit with code 1 if the coverage is lower then the threshold.
35
This script can be used in your continuous deployment environment or for example added to a pre-commit hook.
46

57
# Installation
6-
The script can be installed using composer.Add this repository as a dependency to the composer.json file.
8+
The script can be installed using composer. Add this repository as a dependency to the composer.json file.
79
```bash
810
composer require --dev rregeer/phpunit-coverage-check
911
composer install
@@ -29,5 +31,5 @@ It's also possible to add the coverage report generation to the phpunit.xml.dist
2931
</logging>
3032
```
3133

32-
For more information see the [phpunit documentation](https://phpunit.de/manual/5.3/en/index.html).
33-
Information about the [configuration file](https://phpunit.de/manual/5.3/en/appendixes.configuration.html#appendixes.configuration) and [commandline options](https://phpunit.de/manual/current/en/textui.html#textui.clioptions).
34+
For more information see the [phpunit documentation](https://phpunit.de/manual/5.3/en/index.html).
35+
Information about the [configuration file](https://phpunit.de/manual/5.3/en/appendixes.configuration.html#appendixes.configuration) and [commandline options](https://phpunit.de/manual/current/en/textui.html#textui.clioptions).

bin/coverage-check

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env php
22
<?php
33

4-
include 'vendor/rregeer/phpunit-coverage-check/coverage-check.php';
4+
require dirname( __DIR__ ) . '/coverage-check.php';

test/clover.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<coverage generated="1001">
3+
<project timestamp="1001">
4+
<package name="Example">
5+
<file name="/tmp/Example/String.php">
6+
<class name="Example\String" namespace="Example">
7+
<metrics complexity="15" methods="5" coveredmethods="4" conditionals="0" coveredconditionals="0" statements="33" coveredstatements="32" elements="38" coveredelements="36"/>
8+
</class>
9+
<metrics loc="129" ncloc="62" classes="1" methods="5" coveredmethods="4" conditionals="0" coveredconditionals="0" statements="33" coveredstatements="32" elements="38" coveredelements="36"/>
10+
</file>
11+
<file name="/tmp/Example/StringList.php">
12+
<class name="Example\StringList" namespace="Example">
13+
<metrics complexity="8" methods="5" coveredmethods="4" conditionals="0" coveredconditionals="0" statements="19" coveredstatements="16" elements="24" coveredelements="20"/>
14+
</class>
15+
<metrics loc="103" ncloc="45" classes="1" methods="5" coveredmethods="4" conditionals="0" coveredconditionals="0" statements="19" coveredstatements="16" elements="24" coveredelements="20"/>
16+
</file>
17+
</package>
18+
<metrics files="2" loc="232" ncloc="107" classes="2" methods="10" coveredmethods="8" conditionals="0" coveredconditionals="0" statements="52" coveredstatements="48" elements="62" coveredelements="56"/>
19+
</project>
20+
</coverage>

test/run

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash -eu
2+
3+
# Consistent CWD, regardless of which directory the script is run from.
4+
cd $(dirname $0)/..
5+
6+
# Expect pass
7+
bin/coverage-check test/clover.xml 0
8+
bin/coverage-check test/clover.xml 90
9+
10+
# Expect fail
11+
! bin/coverage-check test/clover.xml 95
12+
! bin/coverage-check test/clover.xml 100

0 commit comments

Comments
 (0)