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

Commit 6fb69ad

Browse files
committed
Big 💥
0 parents  commit 6fb69ad

12 files changed

+344
-0
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/.phpcs-cache
2+
/.phpunit.result.cache
3+
/composer.lock
4+
/phpcs.xml
5+
/phpstan.neon
6+
/phpunit.xml
7+
/vendor/

.scrutinizer.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
build:
2+
nodes:
3+
analysis:
4+
environment:
5+
php:
6+
version: 7.2
7+
cache:
8+
disabled: false
9+
directories:
10+
- ~/.composer/cache
11+
project_setup:
12+
override: true
13+
tests:
14+
override:
15+
- php-scrutinizer-run
16+
- phpcs-run
17+
dependencies:
18+
override:
19+
- COMPOSER_ARGS="--prefer-stable" make
20+
21+
checks:
22+
php:
23+
code_rating: true
24+
25+
tools:
26+
external_code_coverage:
27+
timeout: 3600
28+
29+
build_failure_conditions:
30+
- 'elements.rating(<= C).new.exists' # No new classes/methods with a rating of C or worse allowed
31+
- 'issues.severity(>= MAJOR).new.exists' # New issues of major or higher severity
32+
- 'project.metric_change("scrutinizer.test_coverage", < 0)' # Code Coverage decreased from previous inspection

.travis.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
dist: xenial
2+
language: php
3+
sudo: required
4+
5+
php:
6+
- "7.2"
7+
- "7.3"
8+
- 7.4snapshot
9+
10+
env:
11+
- DEPENDENCIES=
12+
- DEPENDENCIES=--prefer-lowest
13+
14+
before_install:
15+
- mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{,.disabled} || echo "xdebug not available"
16+
17+
install: COMPOSER_ARGS="--prefer-stable $DEPENDENCIES" make
18+
19+
script: make test
20+
21+
stages:
22+
- Code Quality
23+
- Test
24+
25+
jobs:
26+
allow_failures:
27+
- php: 7.4snapshot
28+
- php: nightly
29+
30+
include:
31+
- stage: Code Quality
32+
name: Lint
33+
php: "7.2"
34+
script: make lint
35+
- name: Coding Standard
36+
php: "7.2"
37+
script: make cs
38+
- name: Static Analysis
39+
php: "7.2"
40+
script: make static-analysis
41+
42+
- stage: Test
43+
name: "PHP: nightly"
44+
php: nightly
45+
46+
- stage: Test
47+
name: COVERAGE
48+
php: "7.2"
49+
before_script:
50+
- mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{.disabled,}
51+
- if [[ ! $(php -m | grep -si xdebug) ]]; then echo "xdebug required for coverage"; exit 1; fi
52+
script:
53+
- ./vendor/bin/phpunit --coverage-clover ./build/logs/clover.xml
54+
after_script:
55+
- wget https://github.com/scrutinizer-ci/ocular/releases/download/1.6.0/ocular.phar
56+
- php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml
57+
58+
cache:
59+
directories:
60+
- $HOME/.composer/cache

Makefile

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
COMPOSER_ARGS += --no-progress --no-interaction
2+
3+
### BEGIN main targets
4+
5+
.PHONY: build
6+
build: vendor
7+
8+
.PHONY: list
9+
list:
10+
@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$'
11+
12+
### END
13+
14+
### BEGIN secondary targets
15+
16+
.PHONY: vendor
17+
vendor: vendor/lock
18+
19+
vendor/lock: composer.json
20+
composer update $(COMPOSER_ARGS)
21+
touch vendor/lock
22+
23+
### END
24+
25+
### BEGIN tests
26+
27+
.PHONY: test
28+
test:
29+
vendor/bin/phpunit $(PHPUNIT_ARGS)
30+
31+
.PHONY: lint
32+
lint:
33+
vendor/bin/parallel-lint --exclude vendor .
34+
35+
.PHONY: cs
36+
cs:
37+
vendor/bin/phpcs
38+
39+
.PHONY: fix
40+
fix:
41+
vendor/bin/phpcbf
42+
43+
.PHONY: static-analysis
44+
static-analysis:
45+
vendor/bin/phpstan analyse
46+
47+
.PHONY: check
48+
check: build lint cs static-analysis test
49+
50+
### END
51+
52+
### BEGIN cleaning
53+
54+
.PHONY: clean
55+
clean: clean-vendor
56+
57+
.PHONY: clean-vendor
58+
clean-vendor:
59+
rm -rf vendor
60+
61+
### END

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Cdn77 PHPStan TestUtils Rule
2+
3+
[![Build Status](https://travis-ci.com/cdn77/PHPStanTestUtilsRule.svg)](https://travis-ci.com/cdn77/PHPStanTestUtilsRule)
4+
[![Downloads](https://poser.pugx.org/cdn77/phpstan-test-utils-rule/d/total.svg)](https://packagist.org/packages/cdn77/phpstan-test-utils-rule)
5+
[![Packagist](https://poser.pugx.org/cdn77/phpstan-test-utils-rule/v/stable.svg)](https://packagist.org/packages/cdn77/phpstan-test-utils-rule)
6+
[![Licence](https://poser.pugx.org/cdn77/phpstan-test-utils-rule/license.svg)](https://packagist.org/packages/cdn77/phpstan-test-utils-rule)
7+
[![Quality Score](https://scrutinizer-ci.com/g/cdn77/PHPStanTestUtilsRule/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/cdn77/PHPStanTestUtilsRule)
8+
[![Code Coverage](https://scrutinizer-ci.com/g/cdn77/PHPStanTestUtilsRule/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/simPod/PHPStanTestUtilsRule)
9+
10+
## Installation
11+
12+
* Require this project as composer dev dependency:
13+
14+
```
15+
composer require --dev cdn77/phpstan-test-utils-rule
16+
```
17+
18+
## CreateStub Extension
19+
20+
This extension helps PHPStan to determine return type from `createStub()` method provided by CreateStub Feature.
21+
22+
*The extension must be extended by your extension class and located in your code base because Features are enabled using traits and there's no reliable way for PHPStan to determine from which trait a method comes in a class.*
23+
24+
Create your extension that extends extension from this lib. Only implement `getClass()` method. The class returned is the one you injected the trait in.
25+
26+
```php
27+
<?php
28+
29+
declare(strict_types=1);
30+
31+
namespace Your\Project\Tests\Utils\PHPStan\Extension;
32+
33+
use Cdn77\TestUtils\PHPStan\CreateStubExtension;
34+
use Your\Project\Tests\BaseTestCase;
35+
36+
final class CreateStub extends CreateStubExtension
37+
{
38+
public function getClass() : string
39+
{
40+
return BaseTestCase::class;
41+
}
42+
}
43+
```
44+
45+
Create PHPStan config file for extensions:
46+
47+
```neon
48+
services:
49+
-
50+
class: Your\Project\Tests\Utils\PHPStan\Extension\CreateStub
51+
tags:
52+
- phpstan.broker.dynamicMethodReturnTypeExtension
53+
```
54+
55+
And register it in PHPStan by including it in PHPStan's config:
56+
57+
```neon
58+
includes:
59+
- tests/Utils/PHPStan/Extension/extension.neon
60+
```

composer.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "cdn77/phpstan-test-utils-rule",
3+
"description": "A PHPStan rule to be used with the cdn77/test-utils package",
4+
"license": "MIT",
5+
"minimum-stability": "dev",
6+
"prefer-stable": true,
7+
"type": "phpstan-extension",
8+
"extra": {
9+
"phpstan": {
10+
"includes": [
11+
"extension.neon"
12+
]
13+
}
14+
},
15+
"require": {
16+
"php": "^7.2",
17+
"phpstan/phpstan": "^0.10|^0.11",
18+
"phpstan/phpdoc-parser": "^0.3",
19+
"nikic/php-parser": "^4.0"
20+
},
21+
"require-dev": {
22+
"cdn77/coding-standard": "^2.0",
23+
"jakub-onderka/php-parallel-lint": "^1.0",
24+
"phing/phing": "^2.16.0",
25+
"phpstan/extension-installer": "^1.0",
26+
"phpstan/phpstan-strict-rules": "^0.11.1",
27+
"phpstan/phpstan-phpunit": "^0.11.2",
28+
"phpunit/phpunit": "^8"
29+
},
30+
"autoload": {
31+
"psr-4": {
32+
"Cdn77\\TestUtils\\PHPStan\\": "src/"
33+
}
34+
},
35+
"autoload-dev": {
36+
"psr-4": {
37+
"Cdn77\\TestUtils\\PHPStan\\Tests\\": "tests/"
38+
}
39+
}
40+
}

extension.neon

Whitespace-only changes.

phpcs.xml.dist

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0"?>
2+
<ruleset
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd"
5+
>
6+
<arg name="cache" value=".phpcs-cache"/>
7+
8+
<rule ref="Cdn77CodingStandard"/>
9+
10+
<file>src/</file>
11+
<file>tests/</file>
12+
</ruleset>

phpstan.neon

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
parameters:
2+
bootstrap: %currentWorkingDirectory%/tests/bootstrap.php
3+
memory-limit: -1
4+
level: max
5+
paths:
6+
- %currentWorkingDirectory%/src
7+
- %currentWorkingDirectory%/tests

phpunit.xml.dist

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
4+
beStrictAboutChangesToGlobalState="true"
5+
beStrictAboutOutputDuringTests="true"
6+
beStrictAboutTodoAnnotatedTests="true"
7+
executionOrder="random"
8+
colors="true"
9+
bootstrap="tests/bootstrap.php"
10+
>
11+
<testsuites>
12+
<testsuite name="Test Suite">
13+
<directory>tests</directory>
14+
</testsuite>
15+
</testsuites>
16+
<filter>
17+
<whitelist processUncoveredFilesFromWhitelist="true">
18+
<directory suffix=".php">src</directory>
19+
</whitelist>
20+
</filter>
21+
</phpunit>

0 commit comments

Comments
 (0)