Skip to content

Commit

Permalink
Added CI with Github actions (#119)
Browse files Browse the repository at this point in the history
* Added CI with Github actions

* Conservative CS fixes

* Fix

* Use Symfony PHPUnit bridge
  • Loading branch information
Nyholm authored Sep 19, 2020
1 parent 48f3760 commit cb78c99
Show file tree
Hide file tree
Showing 26 changed files with 393 additions and 106 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[*.yml]
indent_size = 2
49 changes: 49 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Tests
on: [push, pull_request]

jobs:
build:
name: Build
runs-on: ubuntu-latest
strategy:
max-parallel: 10
matrix:
php: [ '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4']

steps:
- name: Set up PHP
uses: shivammathur/[email protected]
with:
php-version: ${{ matrix.php }}
coverage: none
tools: flex

- name: Checkout code
uses: actions/checkout@v2

- name: Download dependencies
run: composer update --no-interaction --prefer-dist --optimize-autoloader --prefer-stable

- name: Run tests
run: ./vendor/bin/phpunit

lowest:
name: Lowest deps
runs-on: ubuntu-latest
steps:
- name: Set up PHP
uses: shivammathur/[email protected]
with:
php-version: 7.3
coverage: pcov

- name: Checkout code
uses: actions/checkout@v2

- name: Download dependencies
run: composer update --no-interaction --prefer-dist --optimize-autoloader --prefer-stable --prefer-lowest

- name: Run tests
env:
SYMFONY_DEPRECATIONS_HELPER: "max[self]=0"
run: ./vendor/bin/phpunit --coverage-text
44 changes: 44 additions & 0 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
on: [push, pull_request]
name: Static analysis

jobs:
phpstan:
name: PHPStan
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Download dependencies
run: |
composer update --no-interaction --prefer-dist --optimize-autoloader
- name: PHPStan
uses: docker://oskarstark/phpstan-ga:0.12.23
with:
entrypoint: /composer/vendor/bin/phpstan
args: analyze --no-progress

php-cs-fixer:
name: PHP-CS-Fixer
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: PHP-CS-Fixer
uses: OskarStark/[email protected]
with:
args: --dry-run --diff-format udiff

psalm:
name: Psalm
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Psalm
uses: docker://vimeo/psalm-github-actions
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ artifacts/
vendor/
composer.lock
phpunit.xml
.php_cs
.php_cs.cache
.phpunit.result.cache
88 changes: 88 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

$config = PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'binary_operator_spaces' => ['operators' => ['=>' => null]],
'blank_line_after_opening_tag' => true,
'class_attributes_separation' => ['elements' => ['method']],
'compact_nullable_typehint' => true,
'concat_space' => ['spacing' => 'one'],
'declare_equal_normalize' => ['space' => 'none'],
'declare_strict_types' => false,
'dir_constant' => true,
'final_static_access' => true,
'fully_qualified_strict_types' => true,
'function_to_constant' => true,
'function_typehint_space' => true,
'header_comment' => false,
'is_null' => ['use_yoda_style' => false],
'list_syntax' => ['syntax' => 'short'],
'lowercase_cast' => true,
'magic_method_casing' => true,
'modernize_types_casting' => true,
'multiline_comment_opening_closing' => true,
//'native_constant_invocation' => true,
'no_alias_functions' => true,
'no_alternative_syntax' => true,
'no_blank_lines_after_phpdoc' => true,
'no_empty_comment' => true,
'no_empty_phpdoc' => true,
'no_extra_blank_lines' => true,
'no_leading_import_slash' => true,
'no_leading_namespace_whitespace' => true,
'no_spaces_around_offset' => true,
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true],
'no_trailing_comma_in_singleline_array' => true,
'no_unneeded_control_parentheses' => true,
'no_unset_cast' => true,
'no_unused_imports' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'no_whitespace_in_blank_line' => true,
'normalize_index_brace' => true,
'ordered_imports' => true,
'php_unit_construct' => true,
'php_unit_dedicate_assert' => ['target' => 'newest'],
'php_unit_dedicate_assert_internal_type' => ['target' => 'newest'],
'php_unit_expectation' => ['target' => 'newest'],
'php_unit_mock' => ['target' => 'newest'],
'php_unit_mock_short_will_return' => true,
'php_unit_no_expectation_annotation' => ['target' => 'newest'],
'php_unit_test_annotation' => ['style' => 'prefix'],
//'php_unit_test_case_static_method_calls' => ['call_type' => 'self'],
'phpdoc_align' => ['align' => 'vertical'],
//'phpdoc_line_span' => ['method' => 'multi', 'property' => 'multi'],
'phpdoc_no_package' => true,
'phpdoc_no_useless_inheritdoc' => true,
'phpdoc_scalar' => true,
'phpdoc_separation' => true,
'phpdoc_single_line_var_spacing' => true,
'phpdoc_trim' => true,
'phpdoc_trim_consecutive_blank_line_separation' => true,
'phpdoc_types' => true,
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
'phpdoc_var_without_name' => true,
'return_assignment' => true,
'short_scalar_cast' => true,
'single_trait_insert_per_statement' => true,
'standardize_not_equals' => true,
//'static_lambda' => true,
'ternary_to_null_coalescing' => true,
'trim_array_spaces' => true,
'visibility_required' => true,
'yoda_style' => false,
// 'native_function_invocation' => true,
'braces' => ['allow_single_line_closure'=>true],
])
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__.'/src')
->in(__DIR__.'/tests')
->name('*.php')
)
;

return $config;
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"php": ">=5.5"
},
"require-dev": {
"phpunit/phpunit": "^4.8.36 || ^5.7.27 || ^7.5"
"symfony/phpunit-bridge": "^4.4 || ^5.1"
},
"autoload": {
"psr-4": {
Expand All @@ -28,8 +28,8 @@
}
},
"scripts": {
"test": "vendor/bin/phpunit",
"test-ci": "vendor/bin/phpunit --coverage-text"
"test": "vendor/bin/simple-phpunit",
"test-ci": "vendor/bin/simple-phpunit --coverage-text"
},
"extra": {
"branch-alias": {
Expand Down
82 changes: 82 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
parameters:
ignoreErrors:
-
message: "#^If condition is always true\\.$#"
count: 3
path: src/EachPromise.php

-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
count: 1
path: src/EachPromise.php

-
message: "#^Property GuzzleHttp\\\\Promise\\\\EachPromise\\:\\:\\$concurrency \\(\\(callable\\(\\)\\: mixed\\)\\|int\\) does not accept null\\.$#"
count: 1
path: src/EachPromise.php

-
message: "#^Property GuzzleHttp\\\\Promise\\\\EachPromise\\:\\:\\$iterable \\(Iterator\\) does not accept null\\.$#"
count: 1
path: src/EachPromise.php

-
message: "#^Property GuzzleHttp\\\\Promise\\\\EachPromise\\:\\:\\$onFulfilled \\(callable\\(\\)\\: mixed\\) does not accept null\\.$#"
count: 1
path: src/EachPromise.php

-
message: "#^Property GuzzleHttp\\\\Promise\\\\EachPromise\\:\\:\\$onRejected \\(callable\\(\\)\\: mixed\\) does not accept null\\.$#"
count: 1
path: src/EachPromise.php

-
message: "#^Negated boolean expression is always false\\.$#"
count: 1
path: src/EachPromise.php

-
message: "#^Dead catch \\- Exception is already caught by Throwable above\\.$#"
count: 1
path: src/EachPromise.php

-
message: "#^Dead catch \\- Exception is already caught by Throwable above\\.$#"
count: 1
path: src/FulfilledPromise.php

-
message: "#^Dead catch \\- Exception is already caught by Throwable above\\.$#"
count: 2
path: src/Promise.php

-
message: "#^Method GuzzleHttp\\\\Promise\\\\Promise\\:\\:callHandler\\(\\) should return array but empty return statement found\\.$#"
count: 1
path: src/Promise.php

-
message: "#^Method GuzzleHttp\\\\Promise\\\\Promise\\:\\:callHandler\\(\\) should return array but return statement is missing\\.$#"
count: 1
path: src/Promise.php

-
message: "#^Dead catch \\- Exception is already caught by Throwable above\\.$#"
count: 1
path: src/RejectedPromise.php

-
message: "#^Parameter \\#1 \\$function of function register_shutdown_function expects callable\\(\\)\\: void, Closure\\(\\)\\: mixed given\\.$#"
count: 1
path: src/TaskQueue.php

-
message: "#^Variable \\$task in PHPDoc tag @var does not exist\\.$#"
count: 1
path: src/TaskQueue.php

-
message: "#^Dead catch \\- Exception is already caught by Throwable above\\.$#"
count: 2
path: src/Utils.php

7 changes: 7 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
includes:
- phpstan-baseline.neon

parameters:
level: 5
paths:
- src
17 changes: 17 additions & 0 deletions psalm.baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="3.11.5@3c60609c218d4d4b3b257728b8089094e5c6c6c2">
<file src="src/Promise.php">
<InvalidReturnType occurrences="1">
<code>array</code>
</InvalidReturnType>
<RedundantCondition occurrences="2">
<code>$this-&gt;state === self::PENDING</code>
<code>$this-&gt;state === self::PENDING</code>
</RedundantCondition>
</file>
<file src="src/RejectedPromise.php">
<InvalidReturnType occurrences="1">
<code>wait</code>
</InvalidReturnType>
</file>
</files>
16 changes: 16 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<psalm
errorLevel="4"
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"
errorBaseline="psalm.baseline.xml"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
1 change: 1 addition & 0 deletions src/Coroutine.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
* @param callable $generatorFn Generator function to wrap into a promise.
*
* @return Promise
*
* @link https://github.com/petkaantonov/bluebird/blob/master/API.md#generators inspiration
*/
final class Coroutine implements PromiseInterface
Expand Down
14 changes: 10 additions & 4 deletions src/EachPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class EachPromise implements PromisorInterface
* allowed number of outstanding concurrently executing promises,
* creating a capped pool of promises. There is no limit by default.
*
* @param mixed $iterable Promises or values to iterate.
* @param array $config Configuration options
* @param mixed $iterable Promises or values to iterate.
* @param array $config Configuration options
*/
public function __construct($iterable, array $config = [])
{
Expand Down Expand Up @@ -159,15 +159,21 @@ private function addPending()
function ($value) use ($idx, $key) {
if ($this->onFulfilled) {
call_user_func(
$this->onFulfilled, $value, $key, $this->aggregate
$this->onFulfilled,
$value,
$key,
$this->aggregate
);
}
$this->step($idx);
},
function ($reason) use ($idx, $key) {
if ($this->onRejected) {
call_user_func(
$this->onRejected, $reason, $key, $this->aggregate
$this->onRejected,
$reason,
$key,
$this->aggregate
);
}
$this->step($idx);
Expand Down
3 changes: 2 additions & 1 deletion src/FulfilledPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public function __construct($value)
{
if (is_object($value) && method_exists($value, 'then')) {
throw new \InvalidArgumentException(
'You cannot create a FulfilledPromise with a promise.');
'You cannot create a FulfilledPromise with a promise.'
);
}

$this->value = $value;
Expand Down
Loading

0 comments on commit cb78c99

Please sign in to comment.