Skip to content

Commit 0a2e4a1

Browse files
xaloppmmoll
authored andcommitted
improve unit and coverage testing
1 parent 5297707 commit 0a2e4a1

11 files changed

+93
-13
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ before_script:
1313
- composer install
1414

1515
script:
16-
- vendor/bin/phpunit --filter MO4
16+
- vendor/bin/phpunit
1717
- vendor/bin/phpcs

CONTRIBUTING.md

+35-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Contributing
22

3+
If you contribute code, please make sure it conforms to the
4+
[PHPCS coding standard](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/phpcs.xml.dist)
5+
and that the unit tests still pass.
6+
37
## Setup
48

59
We do recommend the following setup:
@@ -12,17 +16,42 @@ We do recommend the following setup:
1216
* install all required dependencies
1317

1418
composer install
19+
20+
* be sure that [Xdebug](https://xdebug.org/) is installed, if you like to check code coverage.
21+
22+
23+
## Coding Standard
24+
25+
To check the coding standard, execute in the repository root:
26+
27+
./vendor/bin/phpcs
28+
29+
`phpcs` might report that some coding standard issues can be fixed automatically.
30+
So give `phpcbf` a try and let it fix the issues for you:
31+
32+
./vendor/bin/phpcbf
33+
34+
## Tests
35+
36+
To run the unit tests, execute in the repository root:
37+
38+
./vendor/bin/phpunit
39+
40+
## Code Coverage
41+
42+
Make sure, that you write tests for your code.
1543

44+
Testing code coverage with [PHPUnit](https://phpunit.de/) requires [Xdebug](https://xdebug.org/) to be enabled.
1645

17-
## Coding Standard and Tests
46+
You can generate a simple code coverage report by running in the repository root:
1847

19-
If you contribute code, please make sure it conforms to the PHPCS coding standard and that the unit tests still pass.
48+
./vendor/bin/phpunit --coverage-text
2049

21-
1. To check the coding standard, execute in the repository root:
50+
In the case that Xdebug is disabled by default
2251

23-
./vendor/bin/phpcs
52+
php -d zend_extension=xdebug.so vendor/bin/phpunit --coverage-text
2453

25-
2. To run the unit tests, execute in the repository root:
54+
will do the trick.
2655

27-
./vendor/bin/phpunit --filter MO4
56+
Please refer to the [PHPUnit Manual](https://phpunit.de/documentation.html) for further information about code coverage.
2857

MO4/Tests/Formatting/AlphabeticalUseStatementsUnitTest.fail.1.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use A;
66

77
use A\B\C as CC;
88
use A\B\B as BB;
9-
use A\B\A as AA;
9+
use A\B\A as AA;
1010

1111
use Z;
1212
use X;

MO4/Tests/Formatting/ArrayAlignmentUnitTest.fail.inc

+3
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,6 @@ $values = [
150150
'object_name' => 'TestObject',
151151
'id' => 'Test:2', ], ];
152152

153+
154+
$fail = array(
155+
1);

MO4/Tests/Formatting/ArrayAlignmentUnitTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ protected function getErrorList($testFile='')
8282
136 => 2,
8383
145 => 1,
8484
151 => 2,
85+
155 => 1,
8586
);
8687
}//end switch
8788

MO4/Tests/Formatting/UnnecessaryNamespaceUsageUnitTest.fail.3.inc

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class MyFixtures
1111
{
1212
/**
1313
* Inserts data into database.
14-
*
14+
* @throws
1515
* @param Doctrine\ORM\EntityManager|\Something\ObjectManager $manager Entity Manager
1616
* @throws MyApp\OmgException
1717
* @throws \MyApp\FatalException

MO4/Tests/Formatting/UnnecessaryNamespaceUsageUnitTest.fail.3.inc.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class MyFixtures
1111
{
1212
/**
1313
* Inserts data into database.
14-
*
14+
* @throws
1515
* @param EntityManager|\Something\ObjectManager $manager Entity Manager
1616
* @throws OmgException
1717
* @throws FatalException

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Using [Composer](https://getcomposer.org/) is the preferred way.
7878

7979
1. Add the MO4 coding standard to `composer.json`
8080

81-
composer require --dev mayflower/mo4-coding-standard:dev-master
81+
composer require --dev mayflower/mo4-coding-standard
8282

8383
2. Profit
8484

phpcs.mo4.xml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
<!-- Sensible default configuration settings for coding standard checking of MO4. -->
66
<file>MO4</file>
7+
<file>tests</file>
78

89
<exclude-pattern>*/Tests/*\.(inc|css|js)</exclude-pattern>
910
<exclude-pattern>vendor/*</exclude-pattern>

phpunit.xml.dist

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit backupGlobals="true" beStrictAboutTestsThatDoNotTestAnything="false" bootstrap="vendor/squizlabs/php_codesniffer/tests/bootstrap.php">
2+
<phpunit
3+
backupGlobals="true"
4+
beStrictAboutTestsThatDoNotTestAnything="false"
5+
bootstrap="tests/bootstrap.php"
6+
>
37
<testsuites>
4-
<testsuite name="PHP_CodeSniffer Test Suite">
8+
<testsuite name="MO4 Ruleset Test Suite">
59
<file>vendor/squizlabs/php_codesniffer/tests/Standards/AllSniffs.php</file>
610
</testsuite>
711
</testsuites>
12+
<filter>
13+
<whitelist processUncoveredFilesFromWhitelist="false">
14+
<directory suffix=".php">./MO4/Sniffs</directory>
15+
</whitelist>
16+
</filter>
817
</phpunit>

tests/bootstrap.php

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* Bootstrap file for PHP_CodeSniffer MO4 Coding Standard unit tests.
4+
*
5+
* @category PHP
6+
* @package PHP_CodeSniffer-MO4
7+
* @author Xaver Loppenstedt <[email protected]>
8+
* @license http://spdx.org/licenses/MIT MIT License
9+
* @link https://github.com/mayflower/mo4-coding-standard
10+
*/
11+
12+
$myStandardName = 'MO4';
13+
14+
require_once __DIR__.'/../vendor/squizlabs/php_codesniffer/tests/bootstrap.php';
15+
16+
// Add this Standard.
17+
PHP_CodeSniffer\Config::setConfigData(
18+
'installed_paths',
19+
__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.$myStandardName,
20+
true
21+
);
22+
23+
// Ignore all other Standards in tests.
24+
$standards = PHP_CodeSniffer\Util\Standards::getInstalledStandards();
25+
$standards[] = 'Generic';
26+
27+
$ignoredStandardsStr = implode(
28+
',',
29+
array_filter(
30+
$standards,
31+
function ($v) use ($myStandardName) {
32+
return $v !== $myStandardName;
33+
}
34+
)
35+
);
36+
37+
putenv("PHPCS_IGNORE_TESTS={$ignoredStandardsStr}");

0 commit comments

Comments
 (0)