added phpstan for code analyzes (#806)

This commit is contained in:
Kevin Papst
2019-05-24 01:11:03 +02:00
committed by GitHub
parent cdef22b4d1
commit 8873947a1b
16 changed files with 756 additions and 597 deletions

View File

@@ -7,7 +7,6 @@ A clear and concise description of what this pull request adds or changes.
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
## Checklist
- [ ] I ran `bin/console kimai:codestyle --fix` to verify the correct code style
- [ ] I have updated the [documentation](https://github.com/kimai/www.kimai.org/tree/master/_documentation) accordingly
- [ ] I have added tests to cover my changes
- [ ] I verified that my code applies to the guidelines (`composer code-check`)
- [ ] I updated the documentation accordingly (see [here](https://github.com/kimai/www.kimai.org/tree/master/_documentation))
- [ ] I agree that this code is used in Kimai and will be published under the [MIT license](https://github.com/kevinpapst/kimai2/blob/master/LICENSE)

View File

@@ -27,7 +27,7 @@ install:
script:
- php -r "echo date(DATE_RFC850);"
- vendor/bin/phpunit tests/
- composer code-check
- cp tests/.env.dist.sqlite .env
- bin/console doctrine:database:create -n
- bin/console doctrine:migrations:migrate -n

View File

@@ -12,14 +12,12 @@ As announced in the [README](README.md) I only support the latest available rele
## Reporting a Vulnerability
Please report any security related vulnerability to info@keleo.de or kpapst@gmx.net.
Please report any security related vulnerability in the [advisories section at GitHub](https://github.com/kevinpapst/kimai2/security/advisories) or via email to info@keleo.de or kpapst@gmx.net.
I will work as fast as I can to fix the problem and publish a bugfix release.
Depending on the size of the required fixes, this might take between a couple of hours up
to a couple of days.
I will work as fast as I can to fix the problem and publish a bugfix release / security update.
Depending on the size of the required fixes, this might take a couple of hours or a couple of days.
You can expect that your message (via email is the preferred way) will be answered ASAP,
but please take into account that I am living in the timezone Europe/Berlin.
You can expect that your message will be answered ASAP, but please take into account that I am living in the timezone Europe/Berlin.
If your issue is valid and I verified and fixed it, you will be mentioned in the release
notes within the Security section at the top of the release.
If your issue is valid and I verified and fixed it, you will be mentioned in the release notes within the Security section at the top of the release.
I am grateful for any (discrete) disclosure of vulnerabilities!

View File

@@ -16,6 +16,7 @@
"ext-mbstring": "*",
"ext-pdo": "*",
"ext-zip": "*",
"ext-json": "*",
"beberlei/doctrineextensions": "^1.2",
"doctrine/doctrine-fixtures-bundle": "^3.0",
"erusev/parsedown": "^1.6",
@@ -63,6 +64,7 @@
"require-dev": {
"dama/doctrine-test-bundle": "^5.0",
"friendsofphp/php-cs-fixer": "^2.10",
"phpstan/phpstan": "^0.11.7",
"phpunit/phpunit": "^7.0",
"symfony/browser-kit": "^4.0",
"symfony/css-selector": "^4.0",
@@ -106,7 +108,18 @@
],
"post-update-cmd": [
"@auto-scripts"
]
],
"code-check": [
"@codestyle",
"@phpstan",
"@tests"
],
"tests": "vendor/bin/phpunit tests/",
"tests-unit": "vendor/bin/phpunit --exclude-group integration tests/",
"tests-integration": "vendor/bin/phpunit --group integration tests/",
"phpstan": "vendor/bin/phpstan analyse src --level=1",
"codestyle": "vendor/bin/php-cs-fixer fix --dry-run --verbose --show-progress=none",
"codestyle-fix": "vendor/bin/php-cs-fixer fix"
},
"conflict": {
"symfony/symfony": "*"

697
composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "cd043a2f6453e0ad61c8acbbdbabc4b5",
"content-hash": "4ea6464ccdb8d43c48a4c1188ba2c4d5",
"packages": [
{
"name": "beberlei/DoctrineExtensions",
@@ -9036,6 +9036,580 @@
"description": "A tool to automatically fix PHP code style",
"time": "2019-05-06T07:13:51+00:00"
},
{
"name": "jean85/pretty-package-versions",
"version": "1.2",
"source": {
"type": "git",
"url": "https://github.com/Jean85/pretty-package-versions.git",
"reference": "75c7effcf3f77501d0e0caa75111aff4daa0dd48"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Jean85/pretty-package-versions/zipball/75c7effcf3f77501d0e0caa75111aff4daa0dd48",
"reference": "75c7effcf3f77501d0e0caa75111aff4daa0dd48",
"shasum": ""
},
"require": {
"ocramius/package-versions": "^1.2.0",
"php": "^7.0"
},
"require-dev": {
"phpunit/phpunit": "^6.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
}
},
"autoload": {
"psr-4": {
"Jean85\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Alessandro Lai",
"email": "alessandro.lai85@gmail.com"
}
],
"description": "A wrapper for ocramius/package-versions to get pretty versions strings",
"keywords": [
"composer",
"package",
"release",
"versions"
],
"time": "2018-06-13T13:22:40+00:00"
},
{
"name": "nette/bootstrap",
"version": "v3.0.0",
"source": {
"type": "git",
"url": "https://github.com/nette/bootstrap.git",
"reference": "e1075af05c211915e03e0c86542f3ba5433df4a3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nette/bootstrap/zipball/e1075af05c211915e03e0c86542f3ba5433df4a3",
"reference": "e1075af05c211915e03e0c86542f3ba5433df4a3",
"shasum": ""
},
"require": {
"nette/di": "^3.0",
"nette/utils": "^3.0",
"php": ">=7.1"
},
"require-dev": {
"latte/latte": "^2.2",
"nette/application": "^3.0",
"nette/caching": "^3.0",
"nette/database": "^3.0",
"nette/forms": "^3.0",
"nette/http": "^3.0",
"nette/mail": "^3.0",
"nette/robot-loader": "^3.0",
"nette/safe-stream": "^2.2",
"nette/security": "^3.0",
"nette/tester": "^2.0",
"tracy/tracy": "^2.6"
},
"suggest": {
"nette/robot-loader": "to use Configurator::createRobotLoader()",
"tracy/tracy": "to use Configurator::enableTracy()"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.0-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause",
"GPL-2.0",
"GPL-3.0"
],
"authors": [
{
"name": "David Grudl",
"homepage": "https://davidgrudl.com"
},
{
"name": "Nette Community",
"homepage": "https://nette.org/contributors"
}
],
"description": "🅱 Nette Bootstrap: the simple way to configure and bootstrap your Nette application.",
"homepage": "https://nette.org",
"keywords": [
"bootstrapping",
"configurator",
"nette"
],
"time": "2019-03-26T12:59:07+00:00"
},
{
"name": "nette/di",
"version": "v3.0.0",
"source": {
"type": "git",
"url": "https://github.com/nette/di.git",
"reference": "19d83539245aaacb59470828919182411061841f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nette/di/zipball/19d83539245aaacb59470828919182411061841f",
"reference": "19d83539245aaacb59470828919182411061841f",
"shasum": ""
},
"require": {
"ext-tokenizer": "*",
"nette/neon": "^3.0",
"nette/php-generator": "^3.2.2",
"nette/robot-loader": "^3.2",
"nette/schema": "^1.0",
"nette/utils": "^3.0",
"php": ">=7.1"
},
"conflict": {
"nette/bootstrap": "<3.0"
},
"require-dev": {
"nette/tester": "^2.2",
"tracy/tracy": "^2.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.0-dev"
}
},
"autoload": {
"classmap": [
"src/"
],
"files": [
"src/compatibility.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause",
"GPL-2.0",
"GPL-3.0"
],
"authors": [
{
"name": "David Grudl",
"homepage": "https://davidgrudl.com"
},
{
"name": "Nette Community",
"homepage": "https://nette.org/contributors"
}
],
"description": "💎 Nette Dependency Injection Container: Flexible, compiled and full-featured DIC with perfectly usable autowiring and support for all new PHP 7.1 features.",
"homepage": "https://nette.org",
"keywords": [
"compiled",
"di",
"dic",
"factory",
"ioc",
"nette",
"static"
],
"time": "2019-04-03T19:35:46+00:00"
},
{
"name": "nette/finder",
"version": "v2.5.0",
"source": {
"type": "git",
"url": "https://github.com/nette/finder.git",
"reference": "6be1b83ea68ac558aff189d640abe242e0306fe2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nette/finder/zipball/6be1b83ea68ac558aff189d640abe242e0306fe2",
"reference": "6be1b83ea68ac558aff189d640abe242e0306fe2",
"shasum": ""
},
"require": {
"nette/utils": "^2.4 || ~3.0.0",
"php": ">=7.1"
},
"conflict": {
"nette/nette": "<2.2"
},
"require-dev": {
"nette/tester": "^2.0",
"tracy/tracy": "^2.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.5-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause",
"GPL-2.0",
"GPL-3.0"
],
"authors": [
{
"name": "David Grudl",
"homepage": "https://davidgrudl.com"
},
{
"name": "Nette Community",
"homepage": "https://nette.org/contributors"
}
],
"description": "? Nette Finder: find files and directories with an intuitive API.",
"homepage": "https://nette.org",
"keywords": [
"filesystem",
"glob",
"iterator",
"nette"
],
"time": "2019-02-28T18:13:25+00:00"
},
{
"name": "nette/neon",
"version": "v3.0.0",
"source": {
"type": "git",
"url": "https://github.com/nette/neon.git",
"reference": "cbff32059cbdd8720deccf9e9eace6ee516f02eb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nette/neon/zipball/cbff32059cbdd8720deccf9e9eace6ee516f02eb",
"reference": "cbff32059cbdd8720deccf9e9eace6ee516f02eb",
"shasum": ""
},
"require": {
"ext-iconv": "*",
"ext-json": "*",
"php": ">=7.0"
},
"require-dev": {
"nette/tester": "^2.0",
"tracy/tracy": "^2.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.0-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause",
"GPL-2.0",
"GPL-3.0"
],
"authors": [
{
"name": "David Grudl",
"homepage": "https://davidgrudl.com"
},
{
"name": "Nette Community",
"homepage": "https://nette.org/contributors"
}
],
"description": "? Nette NEON: encodes and decodes NEON file format.",
"homepage": "http://ne-on.org",
"keywords": [
"export",
"import",
"neon",
"nette",
"yaml"
],
"time": "2019-02-05T21:30:40+00:00"
},
{
"name": "nette/php-generator",
"version": "v3.2.2",
"source": {
"type": "git",
"url": "https://github.com/nette/php-generator.git",
"reference": "acff8b136fad84b860a626d133e791f95781f9f5"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nette/php-generator/zipball/acff8b136fad84b860a626d133e791f95781f9f5",
"reference": "acff8b136fad84b860a626d133e791f95781f9f5",
"shasum": ""
},
"require": {
"nette/utils": "^2.4.2 || ~3.0.0",
"php": ">=7.1"
},
"require-dev": {
"nette/tester": "^2.0",
"tracy/tracy": "^2.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.2-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause",
"GPL-2.0",
"GPL-3.0"
],
"authors": [
{
"name": "David Grudl",
"homepage": "https://davidgrudl.com"
},
{
"name": "Nette Community",
"homepage": "https://nette.org/contributors"
}
],
"description": "🐘 Nette PHP Generator: generates neat PHP code for you. Supports new PHP 7.3 features.",
"homepage": "https://nette.org",
"keywords": [
"code",
"nette",
"php",
"scaffolding"
],
"time": "2019-03-15T03:41:13+00:00"
},
{
"name": "nette/robot-loader",
"version": "v3.2.0",
"source": {
"type": "git",
"url": "https://github.com/nette/robot-loader.git",
"reference": "0712a0e39ae7956d6a94c0ab6ad41aa842544b5c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nette/robot-loader/zipball/0712a0e39ae7956d6a94c0ab6ad41aa842544b5c",
"reference": "0712a0e39ae7956d6a94c0ab6ad41aa842544b5c",
"shasum": ""
},
"require": {
"ext-tokenizer": "*",
"nette/finder": "^2.5",
"nette/utils": "^3.0",
"php": ">=7.1"
},
"require-dev": {
"nette/tester": "^2.0",
"tracy/tracy": "^2.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.2-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause",
"GPL-2.0",
"GPL-3.0"
],
"authors": [
{
"name": "David Grudl",
"homepage": "https://davidgrudl.com"
},
{
"name": "Nette Community",
"homepage": "https://nette.org/contributors"
}
],
"description": "? Nette RobotLoader: high performance and comfortable autoloader that will search and autoload classes within your application.",
"homepage": "https://nette.org",
"keywords": [
"autoload",
"class",
"interface",
"nette",
"trait"
],
"time": "2019-03-08T21:57:24+00:00"
},
{
"name": "nette/schema",
"version": "v1.0.0",
"source": {
"type": "git",
"url": "https://github.com/nette/schema.git",
"reference": "6241d8d4da39e825dd6cb5bfbe4242912f4d7e4d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nette/schema/zipball/6241d8d4da39e825dd6cb5bfbe4242912f4d7e4d",
"reference": "6241d8d4da39e825dd6cb5bfbe4242912f4d7e4d",
"shasum": ""
},
"require": {
"nette/utils": "^3.0.1",
"php": ">=7.1"
},
"require-dev": {
"nette/tester": "^2.2",
"tracy/tracy": "^2.3"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause",
"GPL-2.0",
"GPL-3.0"
],
"authors": [
{
"name": "David Grudl",
"homepage": "https://davidgrudl.com"
},
{
"name": "Nette Community",
"homepage": "https://nette.org/contributors"
}
],
"description": "📐 Nette Schema: validating data structures against a given Schema.",
"homepage": "https://nette.org",
"keywords": [
"config",
"nette"
],
"time": "2019-04-03T15:53:25+00:00"
},
{
"name": "nette/utils",
"version": "v3.0.1",
"source": {
"type": "git",
"url": "https://github.com/nette/utils.git",
"reference": "bd961f49b211997202bda1d0fbc410905be370d4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nette/utils/zipball/bd961f49b211997202bda1d0fbc410905be370d4",
"reference": "bd961f49b211997202bda1d0fbc410905be370d4",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
"require-dev": {
"nette/tester": "~2.0",
"tracy/tracy": "^2.3"
},
"suggest": {
"ext-gd": "to use Image",
"ext-iconv": "to use Strings::webalize() and toAscii()",
"ext-intl": "to use Strings::webalize(), toAscii(), normalize() and compare()",
"ext-json": "to use Nette\\Utils\\Json",
"ext-mbstring": "to use Strings::lower() etc...",
"ext-xml": "to use Strings::length() etc. when mbstring is not available"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.0-dev"
}
},
"autoload": {
"classmap": [
"src/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause",
"GPL-2.0",
"GPL-3.0"
],
"authors": [
{
"name": "David Grudl",
"homepage": "https://davidgrudl.com"
},
{
"name": "Nette Community",
"homepage": "https://nette.org/contributors"
}
],
"description": "🛠 Nette Utils: lightweight utilities for string & array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.",
"homepage": "https://nette.org",
"keywords": [
"array",
"core",
"datetime",
"images",
"json",
"nette",
"paginator",
"password",
"slugify",
"string",
"unicode",
"utf-8",
"utility",
"validation"
],
"time": "2019-03-22T01:00:30+00:00"
},
{
"name": "phar-io/manifest",
"version": "1.0.3",
@@ -9252,6 +9826,127 @@
],
"time": "2018-08-05T17:53:17+00:00"
},
{
"name": "phpstan/phpdoc-parser",
"version": "0.3.3",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpdoc-parser.git",
"reference": "472d3161d289f652713a5e353532fa4592663a57"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/472d3161d289f652713a5e353532fa4592663a57",
"reference": "472d3161d289f652713a5e353532fa4592663a57",
"shasum": ""
},
"require": {
"php": "~7.1"
},
"require-dev": {
"consistence/coding-standard": "^3.5",
"jakub-onderka/php-parallel-lint": "^0.9.2",
"phing/phing": "^2.16.0",
"phpstan/phpstan": "^0.10",
"phpunit/phpunit": "^6.3",
"slevomat/coding-standard": "^4.7.2",
"squizlabs/php_codesniffer": "^3.3.2",
"symfony/process": "^3.4 || ^4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "0.3-dev"
}
},
"autoload": {
"psr-4": {
"PHPStan\\PhpDocParser\\": [
"src/"
]
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "PHPDoc parser with support for nullable, intersection and generic types",
"time": "2019-04-23T20:26:19+00:00"
},
{
"name": "phpstan/phpstan",
"version": "0.11.7",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan.git",
"reference": "32d87d746c70785f78d239855782d27cde0eb6ee"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/32d87d746c70785f78d239855782d27cde0eb6ee",
"reference": "32d87d746c70785f78d239855782d27cde0eb6ee",
"shasum": ""
},
"require": {
"composer/xdebug-handler": "^1.3.0",
"jean85/pretty-package-versions": "^1.0.3",
"nette/bootstrap": "^2.4 || ^3.0",
"nette/di": "^2.4.7 || ^3.0",
"nette/robot-loader": "^3.0.1",
"nette/schema": "^1.0",
"nette/utils": "^2.4.5 || ^3.0",
"nikic/php-parser": "^4.0.2",
"php": "~7.1",
"phpstan/phpdoc-parser": "^0.3",
"symfony/console": "~3.2 || ~4.0",
"symfony/finder": "~3.2 || ~4.0"
},
"conflict": {
"symfony/console": "3.4.16 || 4.1.5"
},
"require-dev": {
"brianium/paratest": "^2.0",
"consistence/coding-standard": "^3.5",
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.4",
"ext-intl": "*",
"ext-mysqli": "*",
"ext-soap": "*",
"ext-zip": "*",
"jakub-onderka/php-parallel-lint": "^1.0",
"localheinz/composer-normalize": "^1.1.0",
"phing/phing": "^2.16.0",
"phpstan/phpstan-deprecation-rules": "^0.11",
"phpstan/phpstan-php-parser": "^0.11",
"phpstan/phpstan-phpunit": "^0.11",
"phpstan/phpstan-strict-rules": "^0.11",
"phpunit/phpunit": "^7.0",
"slevomat/coding-standard": "^4.7.2",
"squizlabs/php_codesniffer": "^3.3.2"
},
"bin": [
"bin/phpstan"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "0.11-dev"
}
},
"autoload": {
"psr-4": {
"PHPStan\\": [
"src/",
"build/PHPStan"
]
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "PHPStan - PHP Static Analysis Tool",
"time": "2019-05-19T17:36:42+00:00"
},
{
"name": "phpunit/php-code-coverage",
"version": "6.1.4",

4
phpstan.neon Normal file
View File

@@ -0,0 +1,4 @@
parameters:
autoload_directories:
- %rootDir%/../../../src/Migrations

View File

@@ -1,41 +0,0 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Command;
class BashExecutor
{
/**
* @var string
*/
protected $rootDir;
/**
* @param string $projectDirectory
*/
public function __construct(string $projectDirectory)
{
$this->rootDir = realpath($projectDirectory);
}
/**
* @param string $command
* @return BashResult
*/
public function execute(string $command)
{
$exitCode = 0;
$command = rtrim($this->rootDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . ltrim($command, DIRECTORY_SEPARATOR);
passthru($command, $exitCode);
return new BashResult($exitCode);
}
}

View File

@@ -1,34 +0,0 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Command;
class BashResult
{
/**
* @var string
*/
protected $exitCode;
/**
* @param string $exitCode
*/
public function __construct($exitCode)
{
$this->exitCode = $exitCode;
}
/**
* @return string
*/
public function getExitCode(): string
{
return $this->exitCode;
}
}

View File

@@ -1,79 +0,0 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
/**
* Command used to check and apply the projects coding styles.
*/
class RunCodestyleCommand extends Command
{
/**
* @var BashExecutor
*/
protected $executor;
/**
* @var string
*/
protected $rootDir = '';
/**
* @param BashExecutor $executor
* @param string $projectDirectory
*/
public function __construct(BashExecutor $executor, string $projectDirectory)
{
$this->executor = $executor;
$this->rootDir = realpath($projectDirectory);
parent::__construct();
}
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('kimai:codestyle')
->setDescription('Check and fix the projects coding style')
->addOption('fix', null, InputOption::VALUE_NONE, 'Fix all found problems')
;
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$args = [];
if (!$input->getOption('fix')) {
$args[] = '--dry-run';
$args[] = '--verbose';
$args[] = '--show-progress=none';
}
$result = $this->executor->execute('/vendor/bin/php-cs-fixer fix ' . implode(' ', $args));
if ($result->getExitCode() > 0) {
$io->error('Found violations while checking code styles');
return;
}
$io->success('All source files have proper code styles');
}
}

View File

@@ -1,36 +0,0 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Command;
/**
* Command used to run all integration tests.
*/
class RunIntegrationTestsCommand extends RunUnitTestsCommand
{
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('kimai:test-integration')
->setDescription('Run all integration tests')
->setHelp('This command will execute all integration tests with the annotation "@group integration".')
;
}
/**
* @return string
*/
protected function createPhpunitCmdLine()
{
return '/vendor/bin/phpunit --group integration ' . $this->rootDir . '/tests';
}
}

View File

@@ -1,79 +0,0 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
/**
* Command used to run all unit tests.
*/
class RunUnitTestsCommand extends Command
{
/**
* @var BashExecutor
*/
protected $executor;
/**
* @var string
*/
protected $rootDir;
/**
* @param BashExecutor $executor
* @param string $projectDirectory
*/
public function __construct(BashExecutor $executor, string $projectDirectory)
{
$this->executor = $executor;
$this->rootDir = realpath($projectDirectory);
parent::__construct();
}
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('kimai:test-unit')
->setDescription('Run all unit tests')
->setHelp('This command will execute all unit tests. Skips all tests with "@group integration" annotation.')
;
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$result = $this->executor->execute($this->createPhpunitCmdLine());
if ($result->getExitCode() > 0) {
$io->error('Found problems while running tests');
return;
}
$io->success('All tests were successful');
}
/**
* @return string
*/
protected function createPhpunitCmdLine()
{
return '/vendor/bin/phpunit --exclude-group integration ' . $this->rootDir . '/tests';
}
}

View File

@@ -189,6 +189,9 @@
"jdorn/sql-formatter": {
"version": "v1.2.17"
},
"jean85/pretty-package-versions": {
"version": "1.2"
},
"jms/metadata": {
"version": "1.6.0"
},
@@ -243,6 +246,30 @@
"ref": "f0436fc35fca88eada758311f8de43bfb61f1980"
}
},
"nette/bootstrap": {
"version": "v3.0.0"
},
"nette/di": {
"version": "v3.0.0"
},
"nette/finder": {
"version": "v2.5.0"
},
"nette/neon": {
"version": "v3.0.0"
},
"nette/php-generator": {
"version": "v3.2.2"
},
"nette/robot-loader": {
"version": "v3.2.0"
},
"nette/schema": {
"version": "v1.0.0"
},
"nette/utils": {
"version": "v3.0.1"
},
"nikic/php-parser": {
"version": "v4.0.2"
},
@@ -291,6 +318,12 @@
"phpspec/prophecy": {
"version": "1.7.3"
},
"phpstan/phpdoc-parser": {
"version": "0.3.3"
},
"phpstan/phpstan": {
"version": "0.11.7"
},
"phpunit/php-code-coverage": {
"version": "5.3.0"
},

View File

@@ -1,96 +0,0 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Tests\Command;
use App\Command\BashResult;
use App\Command\RunCodestyleCommand;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Tester\CommandTester;
/**
* @covers \App\Command\RunCodestyleCommand
* @covers \App\Command\BashExecutor
* @covers \App\Command\BashResult
* @group integration
*/
class RunCodestyleCommandTest extends KernelTestCase
{
/**
* @var Application
*/
protected $application;
/**
* @var TestBashExecutor
*/
protected $executor;
/**
* @var string
*/
protected $directory;
protected function setUp()
{
$kernel = self::bootKernel();
$this->application = new Application($kernel);
$this->directory = realpath(__DIR__ . '/../../');
$this->executor = new TestBashExecutor($this->directory);
$this->application->add(new RunCodestyleCommand($this->executor, $this->directory));
}
public function testSuccessCommandNoOptions()
{
$command = $this->assertSuccessCommand([]);
$this->assertStringStartsWith('/vendor/bin/php-cs-fixer fix --dry-run --verbose --show-progress=none', $command);
}
public function testSuccessCommandFix()
{
$command = $this->assertSuccessCommand(['--fix' => true]);
$this->assertStringStartsWith('/vendor/bin/php-cs-fixer fix', $command);
}
public function testSuccessCommand()
{
$command = $this->assertSuccessCommand([]);
$this->assertStringStartsWith('/vendor/bin/php-cs-fixer fix --dry-run --verbose --show-progress=none', $command);
}
protected function assertSuccessCommand(array $options)
{
$result = new BashResult(0);
$this->executor->setResult($result);
$command = $this->application->find('kimai:codestyle');
$commandTester = new CommandTester($command);
$inputs = array_merge(['command' => $command->getName()], $options);
$commandTester->execute($inputs);
$output = $commandTester->getDisplay();
$this->assertContains('[OK] All source files have proper code styles', $output);
return $this->executor->getCommand();
}
public function testFailureCommand()
{
$result = new BashResult(1);
$this->executor->setResult($result);
$command = $this->application->find('kimai:codestyle');
$commandTester = new CommandTester($command);
$inputs = array_merge(['command' => $command->getName()], ['--fix' => true]);
$commandTester->execute($inputs);
$output = $commandTester->getDisplay();
$this->assertContains('[ERROR] Found violations while checking code styles', $output);
}
}

View File

@@ -1,81 +0,0 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Tests\Command;
use App\Command\BashResult;
use App\Command\RunIntegrationTestsCommand;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
/**
* @covers \App\Command\RunIntegrationTestsCommand
* @covers \App\Command\BashExecutor
* @covers \App\Command\BashResult
* @group integration
*/
class RunIntegrationTestsCommandTest extends RunUnitTestsCommandTest
{
/**
* @var Application
*/
protected $application;
/**
* @var TestBashExecutor
*/
protected $executor;
/**
* @var string
*/
protected $directory;
protected function setUp()
{
$kernel = self::bootKernel();
$this->application = new Application($kernel);
$this->directory = realpath(__DIR__ . '/../../');
$this->executor = new TestBashExecutor($this->directory);
$this->application->add(new RunIntegrationTestsCommand($this->executor, $this->directory));
}
public function testSuccessCommand()
{
$result = new BashResult(0);
$this->executor->setResult($result);
$command = $this->application->find('kimai:test-integration');
$commandTester = new CommandTester($command);
$inputs = array_merge(['command' => $command->getName()], []);
$commandTester->execute($inputs);
$output = $commandTester->getDisplay();
$this->assertContains('[OK] All tests were successful', $output);
$this->assertStringStartsWith('/vendor/bin/phpunit --group integration', $this->executor->getCommand());
$this->assertContains($this->directory, $this->executor->getCommand());
}
public function testFailureCommand()
{
$result = new BashResult(1);
$this->executor->setResult($result);
$command = $this->application->find('kimai:test-integration');
$commandTester = new CommandTester($command);
$inputs = array_merge(['command' => $command->getName()], []);
$commandTester->execute($inputs);
$output = $commandTester->getDisplay();
$this->assertContains('[ERROR] Found problems while running tests', $output);
$this->assertStringStartsWith('/vendor/bin/phpunit --group integration', $this->executor->getCommand());
$this->assertContains($this->directory, $this->executor->getCommand());
}
}

View File

@@ -1,82 +0,0 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Tests\Command;
use App\Command\BashResult;
use App\Command\RunUnitTestsCommand;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Tester\CommandTester;
/**
* @covers \App\Command\RunUnitTestsCommand
* @covers \App\Command\BashExecutor
* @covers \App\Command\BashResult
* @group integration
*/
class RunUnitTestsCommandTest extends KernelTestCase
{
/**
* @var Application
*/
protected $application;
/**
* @var TestBashExecutor
*/
protected $executor;
/**
* @var string
*/
protected $directory;
protected function setUp()
{
$kernel = self::bootKernel();
$this->application = new Application($kernel);
$this->directory = realpath(__DIR__ . '/../../');
$this->executor = new TestBashExecutor($this->directory);
$this->application->add(new RunUnitTestsCommand($this->executor, $this->directory));
}
public function testSuccessCommand()
{
$result = new BashResult(0);
$this->executor->setResult($result);
$command = $this->application->find('kimai:test-unit');
$commandTester = new CommandTester($command);
$inputs = array_merge(['command' => $command->getName()], []);
$commandTester->execute($inputs);
$output = $commandTester->getDisplay();
$this->assertContains('[OK] All tests were successful', $output);
$this->assertStringStartsWith('/vendor/bin/phpunit --exclude-group integration', $this->executor->getCommand());
$this->assertContains($this->directory, $this->executor->getCommand());
}
public function testFailureCommand()
{
$result = new BashResult(1);
$this->executor->setResult($result);
$command = $this->application->find('kimai:test-unit');
$commandTester = new CommandTester($command);
$inputs = array_merge(['command' => $command->getName()], []);
$commandTester->execute($inputs);
$output = $commandTester->getDisplay();
$this->assertContains('[ERROR] Found problems while running tests', $output);
$this->assertStringStartsWith('/vendor/bin/phpunit --exclude-group integration', $this->executor->getCommand());
$this->assertContains($this->directory, $this->executor->getCommand());
}
}

View File

@@ -1,55 +0,0 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Tests\Command;
use App\Command\BashExecutor;
use App\Command\BashResult;
class TestBashExecutor extends BashExecutor
{
/**
* @var BashResult
*/
protected $result;
/**
* @var string
*/
protected $command;
/**
* @param BashResult $result
* @return $this
*/
public function setResult(BashResult $result)
{
$this->result = $result;
return $this;
}
/**
* @return string
*/
public function getCommand(): string
{
return $this->command;
}
/**
* @param string $command
* @return BashResult
*/
public function execute(string $command)
{
$this->command = $command;
return $this->result;
}
}