Skip to content

Commit

Permalink
Add PHPUnit testing and coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
arellanog committed Feb 1, 2019
1 parent 774243f commit 460056f
Show file tree
Hide file tree
Showing 10 changed files with 4,696 additions and 1,391 deletions.
126 changes: 89 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ The scripts also work on continous integration (CI) servers like Jenkins.

## Used packages

### [phpspec/phpspec](https://github.com/phpspec/phpspec)

Used for testing (SpecBDD) the code.
Must be configured with a `phpspec.yml` file in your root folder.

We are using the `leanphp/phpspec-code-coverage` extension for generating coverage reports.
This extension requires a `phpspec-coverage.yml` file in your root folder and Xdebug enabled.

### [FriendsOfPHP/PHP-CS-Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer)

Currently used for fixing the code.
Expand All @@ -44,6 +36,23 @@ Runs the defined ruleset (`config/phpmd.xml`) on all files in `src` directory.
Used for static analysis.
Perform static analysis on all files in `src` directory.

### [phpunit/phpunit](https://phpunit.de)

Used for testing the code.
Must be configured with a `phpunit.xml` file in your root folder.

### [lchrusciel/api-test-case](https://github.com/lchrusciel/ApiTestCase)

Based on PHPUnit and used for testing API methods.


### [phpspec/phpspec](https://github.com/phpspec/phpspec)

Used for testing (SpecBDD) the code.
Must be configured with a `phpspec.yml` file in your root folder.

We are using the `leanphp/phpspec-code-coverage` extension for generating coverage reports.
This extension requires a `phpspec-coverage.yml` file in your root folder and Xdebug enabled.

## Installation

Expand All @@ -54,12 +63,15 @@ After installing, insert the desired scripts to your `composer.json`.
```json
{
"scripts": {
"spec-test": "Karriere\\CodeQuality\\SpecificationTest::run",
"lint": "Karriere\\CodeQuality\\CodeStyleChecker::run",
"fix": "Karriere\\CodeQuality\\CodeStyleFixer::run",
"spec-coverage": "Karriere\\CodeQuality\\CodeCoverage::run",
"md": "Karriere\\CodeQuality\\MessDetector::run",
"static": "Karriere\\CodeQuality\\StaticAnalyzer::run"
"static": "Karriere\\CodeQuality\\StaticAnalyzer::run",
"unit-test": "Karriere\\CodeQuality\\UnitTest::run",
"unit-coverage": "Karriere\\CodeQuality\\UnitCoverage::run",
"check-coverage": "Karriere\\CodeQuality\\CloverCoverageCheck::run",
"spec-test": "Karriere\\CodeQuality\\SpecificationTest::run",
"spec-coverage": "Karriere\\CodeQuality\\CodeCoverage::run"
}
}
```
Expand All @@ -81,32 +93,6 @@ composer {script} -- --env=jenkins --notty

### Scripts

#### `spec-coverage`

```
Usage:
spec-test [--] [options]
Options:
--fail Exit with 1 if tests fail.
--notty Disable TTY.
-v --verbose Increase the verbosity of messages.
```

#### `spec-coverage`

```
Usage:
spec-coverage [--] [options]
Options:
--env Specifiy the environment. Possible values:
'local': prints output on command-line.
'jenkins': generates a JUnit report file.
--notty Disable TTY.
```

#### `lint`

```
Expand Down Expand Up @@ -159,6 +145,72 @@ Options:
--notty Disable TTY.
```

#### `unit-test`

```
Usage:
unit-test [--] [options]
Options:
--fail Exit with 1 if tests fail.
--notty Disable TTY.
-v --verbose Increase the verbosity of messages.
```

#### `unit-coverage`

```
Usage:
unit-coverage [--] [options]
Options:
--env Specifiy the environment. Possible values:
'local': generate html report in coverage directory.
'jenkins': generates clover.xml coverage report in root directory.
--notty Disable TTY.
```

#### `check-coverage`

```
Usage:
check-coverage [--] [options]
Options:
--min-coverage Specify minimal coverage level. Possible
values: 0, 25, 50, 100 (default)
--fail Exit with 1 on insufficient coverage.
--notty Disable TTY.
```

#### `spec-test`

```
Usage:
spec-test [--] [options]
Options:
--fail Exit with 1 if tests fail.
--notty Disable TTY.
-v --verbose Increase the verbosity of messages.
```

#### `spec-coverage`

```
Usage:
spec-coverage [--] [options]
Options:
--env Specifiy the environment. Possible values:
'local': prints output on command-line.
'jenkins': generates a JUnit report file.
--notty Disable TTY.
```


## Using custom matchers

This package integrates [karriere/phpspec-matchers](https://github.com/karriereat/phpspec-matchers).
Expand Down
18 changes: 12 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,34 @@
},
"require": {
"php": ">=7.1",
"squizlabs/php_codesniffer": "^3.4",
"friendsofphp/php-cs-fixer": "^2.14",
"karriere/phpspec-matchers": "^2.0",
"leanphp/phpspec-code-coverage": "^4.2",
"phpmd/phpmd": "^2.6",
"phpstan/phpstan": "^0.11.1",
"phpstan/phpstan-doctrine": "^0.11.0",
"phpstan/phpstan-symfony": "^0.11.0",
"karriere/phpspec-matchers": "^2.0",
"leanphp/phpspec-code-coverage": "^4.2",
"phpspec/phpspec": "^4.3",
"squizlabs/php_codesniffer": "^3.4",
"phpunit/phpunit": "^6.0|^7.0",
"lchrusciel/api-test-case": "^3.1",
"symfony/console": "^3.2 || ^4.0",
"symfony/process": "^3.2 || ^4.0"
},
"require-dev": {
"composer/composer": "^1.6"
},
"bin": ["scripts/coverage-checker"],
"scripts": {
"spec-test": "Karriere\\CodeQuality\\SpecificationTest::run",
"spec-coverage": "Karriere\\CodeQuality\\CodeCoverage::run",
"lint": "Karriere\\CodeQuality\\CodeStyleChecker::run",
"fix": "Karriere\\CodeQuality\\CodeStyleFixer::run",
"md": "Karriere\\CodeQuality\\MessDetector::run",
"static": "Karriere\\CodeQuality\\StaticAnalyzer::run"
"static": "Karriere\\CodeQuality\\StaticAnalyzer::run",
"unit-test": "Karriere\\CodeQuality\\UnitTest::run",
"unit-coverage": "Karriere\\CodeQuality\\UnitCoverage::run",
"check-coverage": "Karriere\\CodeQuality\\CloverCoverageCheck::run",
"spec-test": "Karriere\\CodeQuality\\SpecificationTest::run",
"spec-coverage": "Karriere\\CodeQuality\\CodeCoverage::run"
},
"config": {
"sort-packages": true
Expand Down
Loading

0 comments on commit 460056f

Please sign in to comment.