Skip to content

Add test suite #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sudo: false
language: php
php:
- "7.2"
- "7.1"
- "7.0"
- "5.6"
- "5.5"
script: ./test/run
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
[![Build Status](https://travis-ci.org/richardregeer/phpunit-coverage-check.svg?branch=master)](https://travis-ci.org/richardregeer/phpunit-coverage-check)

# phpunit-coverage-check
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.
This script can be used in your continuous deployment environment or for example added to a pre-commit hook.

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

For more information see the [phpunit documentation](https://phpunit.de/manual/5.3/en/index.html).
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).
For more information see the [phpunit documentation](https://phpunit.de/manual/5.3/en/index.html).
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).
2 changes: 1 addition & 1 deletion bin/coverage-check
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env php
<?php

include 'vendor/rregeer/phpunit-coverage-check/coverage-check.php';
require dirname( __DIR__ ) . '/coverage-check.php';
20 changes: 20 additions & 0 deletions test/clover.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<coverage generated="1001">
<project timestamp="1001">
<package name="Example">
<file name="/tmp/Example/String.php">
<class name="Example\String" namespace="Example">
<metrics complexity="15" methods="5" coveredmethods="4" conditionals="0" coveredconditionals="0" statements="33" coveredstatements="32" elements="38" coveredelements="36"/>
</class>
<metrics loc="129" ncloc="62" classes="1" methods="5" coveredmethods="4" conditionals="0" coveredconditionals="0" statements="33" coveredstatements="32" elements="38" coveredelements="36"/>
</file>
<file name="/tmp/Example/StringList.php">
<class name="Example\StringList" namespace="Example">
<metrics complexity="8" methods="5" coveredmethods="4" conditionals="0" coveredconditionals="0" statements="19" coveredstatements="16" elements="24" coveredelements="20"/>
</class>
<metrics loc="103" ncloc="45" classes="1" methods="5" coveredmethods="4" conditionals="0" coveredconditionals="0" statements="19" coveredstatements="16" elements="24" coveredelements="20"/>
</file>
</package>
<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"/>
</project>
</coverage>
12 changes: 12 additions & 0 deletions test/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash -eu

# Consistent CWD, regardless of which directory the script is run from.
cd $(dirname $0)/..

# Expect pass
bin/coverage-check test/clover.xml 0
bin/coverage-check test/clover.xml 90

# Expect fail
! bin/coverage-check test/clover.xml 95
! bin/coverage-check test/clover.xml 100