Skip to content
This repository was archived by the owner on Dec 11, 2020. It is now read-only.

Commit 88bfb84

Browse files
localheinzpimjansen
authored andcommitted
Enhancement: Collect code coverage (#1824)
* Enhancement: Configure whitelist filter for code coverage collection * Enhancement: Add coverage target to Makefile * Enhancement: Collect coverage on Travis CI
1 parent 8c18173 commit 88bfb84

File tree

6 files changed

+57
-14
lines changed

6 files changed

+57
-14
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
.build/
12
vendor
23
composer.lock

Diff for: .travis.yml

+22-13
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@ language: php
22

33
dist: precise
44

5-
php:
6-
- 5.3
7-
- 5.4
8-
- 5.5
9-
- 5.6
10-
- 7.0
11-
- 7.1
12-
- 7.2
13-
- 7.3
14-
- nightly
5+
jobs:
6+
include:
7+
- php: 5.3
8+
- php: 5.4
9+
- php: 5.5
10+
- php: 5.6
11+
- php: 7.0
12+
- php: 7.1
13+
- php: 7.2
14+
- php: 7.3
15+
env: WITH_COVERAGE=true
16+
- php: nightly
1517

1618
matrix:
1719
allow_failures:
@@ -22,9 +24,16 @@ cache:
2224
- $HOME/.composer/cache
2325

2426
before_install:
25-
- phpenv config-rm xdebug.ini || true
27+
- source .travis/xdebug.sh
28+
- xdebug-disable
2629

2730
before_script:
28-
- travis_retry composer install --no-interaction --prefer-dist
31+
- travis_retry composer install --no-interaction --prefer-dist
2932

30-
script: make sniff test
33+
script:
34+
- make sniff
35+
- if [[ "$WITH_COVERAGE" == "true" ]]; then xdebug-enable; fi
36+
- if [[ "$WITH_COVERAGE" == "true" ]]; then make coverage; else make test; fi
37+
38+
after_success:
39+
- if [[ "$WITH_COVERAGE" == "true" ]]; then bash <(curl -s https://codecov.io/bash); fi

Diff for: .travis/xdebug.sh

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
# The problem is that we do not want to remove the configuration file, just disable it for a few tasks, then enable it
4+
#
5+
# For reference, see
6+
#
7+
# - https://docs.travis-ci.com/user/languages/php#Disabling-preinstalled-PHP-extensions
8+
# - https://docs.travis-ci.com/user/languages/php#Custom-PHP-configuration
9+
10+
config="/home/travis/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini"
11+
12+
function xdebug-disable() {
13+
if [[ -f $config ]]; then
14+
mv $config "$config.bak"
15+
fi
16+
}
17+
18+
function xdebug-enable() {
19+
if [[ -f "$config.bak" ]]; then
20+
mv "$config.bak" $config
21+
fi
22+
}

Diff for: Makefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
.PHONY: build fix help sniff test
1+
.PHONY: build coverage fix help sniff test
22

33
help:
44
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
55

66
build: fix test ## Runs fix and test targets
77

8+
coverage: vendor/autoload.php ## Collects coverage with phpunit
9+
vendor/bin/phpunit --coverage-text --coverage-clover=.build/logs/clover.xml
10+
811
fix: vendor/autoload.php ## Fixes code style issues with phpcbf
912
vendor/bin/phpcbf --standard=PSR2 src
1013

Diff for: phpunit.xml.dist

+6
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,10 @@
1313
<directory>./test/Faker/</directory>
1414
</testsuite>
1515
</testsuites>
16+
17+
<filter>
18+
<whitelist addUncoveredFilesFromWhitelist="true" processUncoveredFilesFromWhitelist="true">
19+
<directory suffix=".php">src/</directory>
20+
</whitelist>
21+
</filter>
1622
</phpunit>

Diff for: readme.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Faker
22

3+
[![Code Coverage](https://codecov.io/gh/fzaninotto/Faker/branch/master/graph/badge.svg)](https://codecov.io/gh/fzaninotto/Faker)
4+
35
Faker is a PHP library that generates fake data for you. Whether you need to bootstrap your database, create good-looking XML documents, fill-in your persistence to stress test it, or anonymize data taken from a production service, Faker is for you.
46

57
Faker is heavily inspired by Perl's [Data::Faker](http://search.cpan.org/~jasonk/Data-Faker-0.07/), and by ruby's [Faker](https://rubygems.org/gems/faker).

0 commit comments

Comments
 (0)