Skip to content

Commit

Permalink
Merge pull request #19 from bearsunday/refactor
Browse files Browse the repository at this point in the history
Update QA tools and refactor
  • Loading branch information
koriym authored Apr 8, 2020
2 parents ba23dc0 + f97ac98 commit 2f4ddd5
Show file tree
Hide file tree
Showing 12 changed files with 155 additions and 56 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ tests/stdout.log
tmp

.php_cs.cache
.phpunit.result.cache
56 changes: 43 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,54 @@
language: php

php:
- 7.2
- 7.3
- 7.4

cache:
directories:
- vendor
- $HOME/.composer/cache
env:
matrix:
- DEPENDENCIES=""
- DEPENDENCIES="--prefer-lowest --prefer-stable"
before_script:

before_install:
- mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{,.disabled} || echo "xdebug not available"
- composer self-update
- composer update $DEPENDENCIES
- if [[ $TRAVIS_PHP_VERSION = '7.2' ]]; then COVERAGE="--coverage-clover=coverage.clover"; else phpenv config-rm xdebug.ini; fi
- if [[ $TRAVIS_PHP_VERSION = '7.2' ]]; then composer require --dev phpstan/phpstan-shim ^0.9 friendsofphp/php-cs-fixer; fi

install:
- composer update

script:
- ./vendor/bin/phpunit $COVERAGE;
- if [[ $TRAVIS_PHP_VERSION = '7.2' ]]; then vendor/bin/php-cs-fixer fix --verbose --diff --dry-run --config=.php_cs; fi
- if [[ $TRAVIS_PHP_VERSION = '7.2' ]]; then vendor/bin/phpstan analyse -l max -c phpstan.neon src tests --no-progress --no-interaction; fi
after_script:
- if [[ $TRAVIS_PHP_VERSION = '7.2' ]]; then wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi
- ./vendor/bin/phpunit;

jobs:
include:
- stage: Test
name: Lowest dependencies
php: 7.2
install: composer update --prefer-dist --prefer-lowest

- stage: Test
name: Code coverage
php: 7.2
before_script:
- mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini{.disabled,}
- if [[ ! $(php -m | grep -si xdebug) ]]; then echo "xdebug required for coverage"; exit 1; fi
script:
- ./vendor/bin/phpunit -v --coverage-clover ./build/logs/clover.xml
after_script:
- wget https://scrutinizer-ci.com/ocular.phar && php ocular.phar code-coverage:upload --format=php-clover coverage.clover;

- stage: Code Quality
name: Static analysis
php: 7.2
install: composer require --dev phpstan/phpstan ^0.11 vimeo/psalm ^3.8;
script:
- ./vendor/bin/phpstan analyse -c phpstan.neon --no-progress --no-interaction;
- ./vendor/bin/psalm --shepherd --stats;

- stage: Code Quality
name: Coding standards
php: 7.2
install: composer require --dev friendsofphp/php-cs-fixer ^2.0;
script:
- ./vendor/bin/php-cs-fixer --dry-run -v fix;
34 changes: 25 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
"php": ">=7.2",
"aura/router": "^3.1",
"laminas/laminas-diactoros": "^1.7",
"ray/di": "^2.10",
"doctrine/annotations": "^1.7"
"bear/package": "^1.9.7",
"doctrine/annotations": "^1.7",
"laminas/laminas-dependency-plugin": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^6.5",
"bear/package": "^1.8"
"phpunit/phpunit": "^8.5"
},
"autoload": {
"psr-4": {
Expand All @@ -36,10 +36,26 @@
}
},
"scripts": {
"test": ["phpunit"],
"tests": ["@cs", "phpmd src,tests text ./phpmd.xml", "phpstan analyse -l max src tests -c phpstan.neon --no-progress", "@test"],
"coverage": ["php -dzend_extension=xdebug.so ./vendor/bin/phpunit --coverage-text --coverage-html=build/coverage"],
"cs": ["php-cs-fixer fix -v --dry-run", "phpcs --standard=phpcs.xml src;"],
"cs-fix": ["php-cs-fixer fix -v", "phpcbf src tests"]
"test": [
"phpunit"
],
"tests": [
"@cs",
"phpmd src,tests text ./phpmd.xml",
"phpstan analyse -c phpstan.neon --no-progress",
"psalm",
"@test"
],
"coverage": [
"php -dzend_extension=xdebug.so ./vendor/bin/phpunit --coverage-text --coverage-html=build/coverage"
],
"cs": [
"php-cs-fixer fix -v --dry-run",
"phpcs --standard=phpcs.xml src;"
],
"cs-fix": [
"php-cs-fixer fix -v",
"phpcbf src tests"
]
}
}
11 changes: 6 additions & 5 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
parameters:
ignoreErrors:
- '#Undefined variable#'
- '#Method BEAR\\Package\\Provide\\Router\\AuraRouter::match\(\) should return BEAR\\Sunday\\Extension\\Router\\RouterMatch but returns false.#'
- '#expects bool, BEAR\\Sunday\\Extension\\Router\\RouterMatch#'
- '#Parameter \#1 \$condition of method PHPUnit\\Framework\\Assert::assertFalse\(\)#'
level: max
paths:
- src
- tests
ignoreErrors:
- '#Undefined variable#'
18 changes: 10 additions & 8 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<phpunit bootstrap="tests/bootstrap.php">
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php">
<testsuites>
<testsuite>
<directory suffix="Test.php">tests</directory>
<testsuite name="all">
<directory>tests</directory>
</testsuite>
</testsuites>

<php>
<ini name="error_reporting" value="-1" />
</php>
<filter>
<whitelist>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<php>
<ini name="error_log" value="./tests/tmp/error.log"/>
</php>
</phpunit>
55 changes: 55 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0"?>
<psalm
totallyTyped="false"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>

<issueHandlers>
<LessSpecificReturnType errorLevel="info" />

<!-- level 3 issues - slightly lazy code writing, but provably low false-negatives -->

<DeprecatedMethod errorLevel="info" />
<DeprecatedProperty errorLevel="info" />
<DeprecatedClass errorLevel="info" />
<DeprecatedConstant errorLevel="info" />
<DeprecatedFunction errorLevel="info" />
<DeprecatedInterface errorLevel="info" />
<DeprecatedTrait errorLevel="info" />

<InternalMethod errorLevel="info" />
<InternalProperty errorLevel="info" />
<InternalClass errorLevel="info" />

<MissingClosureReturnType errorLevel="info" />
<MissingReturnType errorLevel="info" />
<MissingPropertyType errorLevel="info" />
<InvalidDocblock errorLevel="info" />
<MisplacedRequiredParam errorLevel="info" />

<PropertyNotSetInConstructor errorLevel="info" />
<MissingConstructor errorLevel="info" />
<MissingClosureParamType errorLevel="info" />
<MissingParamType errorLevel="info" />

<RedundantCondition errorLevel="info" />

<DocblockTypeContradiction errorLevel="info" />
<RedundantConditionGivenDocblockType errorLevel="info" />

<UnresolvableInclude errorLevel="info" />

<RawObjectIteration errorLevel="info" />

<InvalidStringClass errorLevel="info" />
</issueHandlers>
</psalm>
9 changes: 5 additions & 4 deletions src/Provide/Router/AuraRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
use Aura\Router\Route;
use Aura\Router\RouterContainer;
use BEAR\Sunday\Annotation\DefaultSchemeHost;
use BEAR\Sunday\Extension\Router\NullMatch;
use BEAR\Sunday\Extension\Router\RouterInterface;
use BEAR\Sunday\Extension\Router\RouterMatch;
use Laminas\Diactoros\ServerRequest;
use Ray\Di\Di\Inject;
use Zend\Diactoros\ServerRequest;

class AuraRouter implements RouterInterface
{
Expand Down Expand Up @@ -58,15 +59,15 @@ public function __construct(RouterContainer $routerContainer, HttpMethodParamsIn
* @DefaultSchemeHost("schemeHost")
* @Inject
*/
public function setSchemaHost(string $schemeHost)
public function setSchemaHost(string $schemeHost) : void
{
$this->schemeHost = $schemeHost;
}

/**
* {@inheritdoc}
*/
public function match(array $globals, array $server)
public function match(array $globals, array $server) : RouterMatch
{
$psr15request = new ServerRequest(
$server,
Expand All @@ -81,7 +82,7 @@ public function match(array $globals, array $server)
);
$route = $this->matcher->match($psr15request);
if ($route === false) {
return false;
return new NullMatch;
}

return $this->getRouterMatch($globals, $server, $route);
Expand Down
2 changes: 1 addition & 1 deletion src/Provide/Router/AuraRouterModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(string $routerFile = '', AbstractModule $module = nu
parent::__construct($module);
}

protected function configure()
protected function configure() : void
{
$this->bind()->annotatedWith('aura_router_file')->toInstance($this->routerFile);
$this->bind(RouterInterface::class)->toProvider(RouterCollectionProvider::class)->in(Scope::SINGLETON);
Expand Down
2 changes: 1 addition & 1 deletion src/Provide/Router/RouterContainerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct(string $schemeHost)
* @Inject
* @Named("routerFile=aura_router_file")
*/
public function setRouterContainer(AbstractAppMeta $appMeta, string $routerFile = '')
public function setRouterContainer(AbstractAppMeta $appMeta, string $routerFile = '') : void
{
$this->routerContainer = new RouterContainer;
$routerFile = ($routerFile === '') ? $appMeta->appDir . '/var/conf/aura.route.php' : $routerFile;
Expand Down
3 changes: 2 additions & 1 deletion tests/Provide/Router/AuraRouterModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use BEAR\AppMeta\AppMeta;
use BEAR\Package\AppMetaModule;
use BEAR\Package\Provide\Router\Exception\InvalidRouterFilePathException;
use BEAR\Sunday\Extension\Router\NullMatch;
use BEAR\Sunday\Extension\Router\RouterInterface;
use FakeVendor\HelloWorld\Module\AppModule;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -79,7 +80,7 @@ public function testRouteWithTokenFailure(AuraRouter $auraRouter)
'REQUEST_URI' => 'http://localhost/user/0bear'
];
$request = $auraRouter->match($globals, $server);
$this->assertFalse($request);
$this->assertInstanceOf(NullMatch::class, $request);
}

public function testRouterFileNotExsits()
Expand Down
11 changes: 6 additions & 5 deletions tests/Provide/Router/AuraRouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

use Aura\Router\Map;
use Aura\Router\RouterContainer;
use BEAR\Sunday\Extension\Router\NullMatch;
use PHPUnit\Framework\TestCase;

class AuraRouterTest extends TestCase
Expand All @@ -22,7 +23,7 @@ class AuraRouterTest extends TestCase
*/
private $auraRouter;

public function setUp()
public function setUp() : void
{
parent::setUp();
$routerContainer = new RouterContainer;
Expand Down Expand Up @@ -62,7 +63,7 @@ public function testMatchInvalidToken()
'REQUEST_URI' => 'http://localhost/blog/PC6001'
];
$request = $this->auraRouter->match($globals, $server);
$this->assertFalse($request);
$this->assertInstanceOf(NullMatch::class, $request);
}

public function testMatchValidToken()
Expand Down Expand Up @@ -126,7 +127,7 @@ public function testNotMatch()
'REQUEST_URI' => 'http://localhost/not_much_uri',
];
$match = $this->auraRouter->match($globals, $server);
$this->assertFalse($match);
$this->assertInstanceOf(NullMatch::class, $match);
}

public function testInvalidPath()
Expand All @@ -140,7 +141,7 @@ public function testInvalidPath()
'REQUEST_URI' => null
];
$match = $this->auraRouter->match($globals, $server);
$this->assertFalse($match);
$this->assertInstanceOf(NullMatch::class, $match);
}

public function testGenerate()
Expand All @@ -153,7 +154,7 @@ public function testGenerate()
public function testGenerateFailed()
{
$uri = $this->auraRouter->generate('/_invalid_', ['year' => '8', 'month' => '1']);
$this->assertFalse($uri);
$this->assertFalse((bool) $uri);
}

public function testSerialize()
Expand Down
9 changes: 0 additions & 9 deletions tests/bootstrap.php

This file was deleted.

0 comments on commit 2f4ddd5

Please sign in to comment.