-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add base repository config * CS (#2) * CS * Fix scrut issues * Update link * Add test * Improve test * Fix readme * Fix readme * Fix readme * Remove useless const * Less strict message comparaison * Add behat tests * Fix * Improve tests * Improve listener and tests * Fix * Add doc about static attributes * Fix doc
- Loading branch information
Showing
25 changed files
with
761 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
vendor | ||
build | ||
composer.lock | ||
.gitkeep |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
checks: | ||
php: | ||
code_rating: true | ||
duplication: true | ||
build_failure_conditions: | ||
- 'project.metric_change("scrutinizer.quality", < -0.10)' | ||
- 'elements.rating(<= D).exists' # No classes/methods with a rating of D or worse | ||
- 'issues.label("coding-style").exists' # No coding style issues allowed | ||
- 'issues.severity(>= MAJOR).exists' # New major or higher severity issues | ||
- 'project.metric("scrutinizer.quality", < 9)' # Code Quality Rating drops below 9 | ||
- 'project.metric("scrutinizer.test_coverage", < 0.90)' # Code Coverage drops below 90% | ||
- 'project.metric_change("scrutinizer.test_coverage", < -0.02)' | ||
- 'patches.label("Doc Comments").exists' # No doc comments patches allowed | ||
- 'patches.label("Spacing").exists' # No spacing patches allowed | ||
build: | ||
cache: | ||
directories: | ||
- ~/.composer | ||
|
||
dependencies: | ||
before: | ||
- composer global require hirak/prestissimo | ||
override: | ||
- composer build-ci | ||
|
||
environment: | ||
mysql: false | ||
postgresql: false | ||
elasticsearch: false | ||
redis: false | ||
|
||
tests: | ||
override: | ||
- composer cs | ||
- | ||
command: composer coverage-clover | ||
idle_timeout: 1200 | ||
coverage: | ||
file: 'build/coverage/clover.xml' | ||
format: 'php-clover' | ||
|
||
tools: | ||
php_analyzer: | ||
enabled: true | ||
config: | ||
checkstyle: | ||
enabled: true | ||
naming: | ||
isser_method_name: ^.*$ | ||
utility_class_name: ^.*$ | ||
doc_comment_fixes: | ||
enabled: false | ||
reflection_fixes: | ||
enabled: false | ||
use_statement_fixes: | ||
enabled: false | ||
simplify_boolean_return: | ||
enabled: true | ||
external_code_coverage: false | ||
php_code_coverage: false | ||
php_changetracking: true | ||
php_cpd: true | ||
php_cs_fixer: false | ||
php_mess_detector: true | ||
php_pdepend: true | ||
sensiolabs_security_checker: true | ||
|
||
filter: | ||
paths: | ||
- src/* | ||
|
||
coding_style: | ||
php: | ||
spaces: | ||
before_parentheses: | ||
closure_definition: true | ||
around_operators: | ||
concatenation: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
language: php | ||
|
||
php: | ||
- '5.5' | ||
- '5.6' | ||
- '7.0' | ||
|
||
sudo: false | ||
|
||
matrix: | ||
fast_finish: true | ||
|
||
before_install: | ||
- composer global require hirak/prestissimo | ||
|
||
install: | ||
- composer build-ci | ||
|
||
script: | ||
- composer test | ||
|
||
cache: | ||
directories: | ||
- $HOME/.composer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Contributing | ||
|
||
## Getting Started | ||
* Fork, then clone the repo: | ||
```bash | ||
git clone git@github.com:your-username/PhpUnitExtended.git | ||
```` | ||
|
||
* Make sure everything goes well: | ||
```bash | ||
composer ci | ||
``` | ||
|
||
* Make your changes (Add/Update tests according to your changes). | ||
* Make sure tests are still green: | ||
```bash | ||
composer ci | ||
``` | ||
|
||
* To check code coverage, launch | ||
```bash | ||
composer coverage | ||
``` | ||
|
||
* Push to your fork and [submit a pull request](https://github.com/yoanm/PhpUnitExtended/compare/). | ||
* Wait for feedback or merge. | ||
|
||
Some stuff that will increase your pull request's acceptance: | ||
* Write tests. | ||
* Follow PSR-2 coding style. | ||
* Write good commit messages. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
default: | ||
suites: | ||
default: | ||
contexts: | ||
- Functional\Yoanm\PhpUnitExtended\BehatContext\FeatureContext: ~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
Feature: TestStrategyListener | ||
|
||
Scenario: Risky output | ||
Given I run "risky-output" phpunit test-suite | ||
Then I should have 1 failure | ||
Then I should have a failure containing following message "1\) RiskyOutputTest::test" | ||
Then I should have a failure containing following message "Strict mode - No output during test" | ||
And I should have a failure containing following message "TEST_OUTPUT_DURING_TEST" | ||
|
||
Scenario: Risky coverage | ||
Given I run "risky-coverage" phpunit test-suite with coverage | ||
Then I should have 1 failure | ||
Then I should have a failure containing following message "1\) RiskyCoverageTest::test" | ||
Then I should have a failure containing following message "Strict mode - Executed code must be defined with @covers and @uses annotations" | ||
And I should have a failure containing following message "src/DefaultClass.php:10" | ||
|
||
Scenario: Risky test that do not test anything | ||
Given I run "risky-nothing" phpunit test-suite | ||
Then I should have 1 failure | ||
Then I should have a failure containing following message "1\) RiskyNothingTest::test" | ||
And I should have a failure containing following message "No test that do not test anything" | ||
|
||
Scenario: Risky globals manipulation | ||
Given I run "risky-globals" phpunit test-suite | ||
Then I should have 1 failure | ||
Then I should have a failure containing following message "1\) RiskyGlobalsTest::test" | ||
Then I should have a failure containing following message "No global variable manipulation during test" | ||
|
||
Scenario: Risky test that do not test anything | ||
Given I run "risky-static" phpunit test-suite | ||
Then I should have 1 failure | ||
Then I should have a failure containing following message "1\) RiskyStaticTest::test" | ||
And I should have a failure containing following message "No static attribute manipulation during test" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
namespace Functional\Yoanm\PhpUnitExtended\BehatContext; | ||
|
||
use Behat\Behat\Context\Context; | ||
use Symfony\Component\Process\Process; | ||
use Symfony\Component\Process\ProcessBuilder; | ||
|
||
/** | ||
* Defines application features from the specific context. | ||
*/ | ||
class FeatureContext implements Context | ||
{ | ||
|
||
/** @var Process|null */ | ||
private $process = null; | ||
|
||
/** | ||
* @Given I run :testSuiteName phpunit test-suite | ||
*/ | ||
public function iRunPhpunitTestSuite($testSuiteName, $withCoverage = false) | ||
{ | ||
$argList = [ | ||
sprintf('%s/%s/vendor/bin/phpunit', __DIR__, '../../..'), | ||
'--testsuite', | ||
$testSuiteName, | ||
'-c', | ||
sprintf('%s/%s/phpunit.xml', __DIR__, '../..'), | ||
]; | ||
if (true === $withCoverage) { | ||
$argList[] = '--coverage-text'; | ||
} | ||
$processBuilder = new ProcessBuilder($argList); | ||
$this->process = $processBuilder->getProcess(); | ||
|
||
$this->process->run(); | ||
} | ||
|
||
/** | ||
* @Given I run :testSuiteName phpunit test-suite with coverage | ||
*/ | ||
public function iRunPhpunitTestSuiteWithCoverage($testSuiteName) | ||
{ | ||
$this->iRunPhpunitTestSuite($testSuiteName, true); | ||
} | ||
|
||
/** | ||
* @Then /^I should have (?P<expectedFailureCount>\d+) failure(s)?$/ | ||
*/ | ||
public function iShouldHaveXFailures($expectedFailureCount) | ||
{ | ||
$output = $this->process->getOutput(); | ||
|
||
$failureCount = preg_match_all(sprintf('#There was %s failure#', $expectedFailureCount), $output); | ||
if ($failureCount != $expectedFailureCount) { | ||
throw new \Exception(sprintf('Found %d failure, but %d expected', $failureCount, $expectedFailureCount)); | ||
} | ||
} | ||
|
||
/** | ||
* @Then I should have a failure containing following message :expectedMessage | ||
*/ | ||
public function iShouldHaveAFailureContainingFollowingMessage($expectedMessage) | ||
{ | ||
$output = $this->process->getOutput(); | ||
|
||
if (!preg_match(sprintf('#%s#', $expectedMessage), $output)) { | ||
throw new \Exception(sprintf('"%s" not found in : %s', $expectedMessage, $output)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html --> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.8/phpunit.xsd" | ||
beStrictAboutOutputDuringTests="true" | ||
backupGlobals="true" | ||
beStrictAboutChangesToGlobalState="true" | ||
beStrictAboutTestsThatDoNotTestAnything="true" | ||
checkForUnintentionallyCoveredCode="true" | ||
forceCoversAnnotation="true" | ||
bootstrap="../vendor/autoload.php" | ||
> | ||
<listeners> | ||
<listener class="Yoanm\PhpUnitExtended\Listener\TestsStrategyListener"/> | ||
</listeners> | ||
<directory>tests/*</directory> | ||
<testsuites> | ||
<testsuite name="risky-output"> | ||
<file>tests/RiskyOutputTest.php</file> | ||
</testsuite> | ||
<testsuite name="risky-coverage"> | ||
<file>tests/RiskyCoverageTest.php</file> | ||
</testsuite> | ||
<testsuite name="risky-nothing"> | ||
<file>tests/RiskyNothingTest.php</file> | ||
</testsuite> | ||
<testsuite name="risky-globals"> | ||
<file>tests/RiskyGlobalsTest.php</file> | ||
</testsuite> | ||
<testsuite name="risky-static"> | ||
<file>tests/RiskyStaticTest.php</file> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<filter> | ||
<whitelist> | ||
<directory>src</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
namespace AppTest; | ||
|
||
class DefaultClass | ||
{ | ||
static $value = null; | ||
|
||
public function justForTest($b = 2) | ||
{ | ||
if ($b % 2) { | ||
$a = $b/2; | ||
} else { | ||
$a = $b*2; | ||
} | ||
|
||
return $a === $b; | ||
} | ||
} |
Oops, something went wrong.