Skip to content

Commit

Permalink
Psalm improvements, add unit tests update of workflow actions (#10)
Browse files Browse the repository at this point in the history
* Update dev dependencies

* Psalm improvements

* Add more test cases for code coverage

* Update .scrutinizer.yml

* Update of workflow actions
  • Loading branch information
devanych committed Jul 12, 2021
1 parent 7f5e381 commit 0d4e0ed
Show file tree
Hide file tree
Showing 15 changed files with 208 additions and 104 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Expand Up @@ -12,3 +12,6 @@ trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.yml]
indent_size = 2
46 changes: 13 additions & 33 deletions .github/workflows/build.yml
Expand Up @@ -6,10 +6,11 @@ name: build

jobs:
tests:
name: PHP ${{ matrix.php-version }}-${{ matrix.os }}
name: PHP ${{ matrix.php }}-${{ matrix.os }}

runs-on: ${{ matrix.os }}

env:
extensions: curl, mbstring, dom
key: cache-v1

strategy:
Expand All @@ -18,19 +19,18 @@ jobs:
- ubuntu-latest
- windows-latest

php-version:
php:
- "7.4"
- "8.0"

steps:
- name: Checkout
uses: actions/checkout@v2.3.4
uses: actions/checkout@v2

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: ${{ env.extensions }}
php-version: ${{ matrix.php }}
ini-values: date.timezone='UTC'
tools: composer:v2
coverage: pcov
Expand All @@ -44,38 +44,18 @@ jobs:
run: echo "COMPOSER_CACHE_DIR=~\AppData\Local\Composer" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append

- name: Cache dependencies installed with composer
uses: actions/cache@v1
uses: actions/cache@v2
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.json') }}
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php-version }}-composer-
php${{ matrix.php }}-composer-
- name: Update composer
run: composer self-update

- name: Install dependencies with composer php 7.4
if: matrix.php-version == '7.4'
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader

- name: Install dependencies with composer php 8.0
if: matrix.php-version == '8.0'
run: composer update --ignore-platform-reqs --prefer-dist --no-interaction --no-progress --optimize-autoloader

- name: PHPUnit run with coverage on Linux PHP 7.4
if: matrix.os == 'ubuntu-latest' && matrix.php-version == '7.4'
run: vendor/bin/phpunit --coverage-clover=coverage.clover

- name: PHPUnit run without coverage on Linux PHP 8.0
if: matrix.os == 'ubuntu-latest' && matrix.php-version == '8.0'
run: vendor/bin/phpunit

- name: PHPUnit run without coverage on Windows
if: matrix.os == 'windows-latest'
run: vendor/bin/phpunit
- name: Install dependencies with composer
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Code coverage scrutinizer on Linux PHP 7.4
if: matrix.os == 'ubuntu-latest' && matrix.php-version == '7.4'
run: |
wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover coverage.clover
- name: Run tests with phpunit
run: vendor/bin/phpunit --colors=always
19 changes: 9 additions & 10 deletions .github/workflows/mutation.yml
Expand Up @@ -8,7 +8,7 @@ name: mutation

jobs:
mutation:
name: PHP ${{ matrix.php-version }}-${{ matrix.os }}
name: PHP ${{ matrix.php }}-${{ matrix.os }}

runs-on: ${{ matrix.os }}

Expand All @@ -17,17 +17,17 @@ jobs:
os:
- ubuntu-latest

php-version:
php:
- "7.4"

steps:
- name: Checkout
uses: actions/checkout@v2.3.4
uses: actions/checkout@v2

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
php-version: ${{ matrix.php }}
ini-values: memory_limit=-1
tools: composer:v2
coverage: pcov
Expand All @@ -39,20 +39,19 @@ jobs:
uses: actions/cache@v2
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.json') }}
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php-version }}-composer-
php${{ matrix.php }}-composer-
- name: Update composer
run: composer self-update

- name: Install dependencies with composer
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Run test mutation infection with coverage
run: |
mkdir -p build/logs
vendor/bin/phpunit --coverage-xml=build/logs/coverage-xml --log-junit=build/logs/junit.xml
vendor/bin/infection --threads=2 --coverage=build/logs --show-mutations --no-progress --min-msi=10 --min-covered-msi=10
git fetch --depth=1 origin $GITHUB_BASE_REF
vendor/bin/roave-infection-static-analysis-plugin -j2 --git-diff-filter=A --git-diff-base=origin/$GITHUB_BASE_REF --logger-github --ignore-msi-with-no-mutations --only-covered
env:
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
15 changes: 8 additions & 7 deletions .github/workflows/static.yml
Expand Up @@ -6,7 +6,7 @@ name: static

jobs:
static:
name: PHP ${{ matrix.php-version }}-${{ matrix.os }}
name: PHP ${{ matrix.php }}-${{ matrix.os }}

runs-on: ${{ matrix.os }}

Expand All @@ -15,17 +15,18 @@ jobs:
os:
- ubuntu-latest

php-version:
php:
- "7.4"
- "8.0"

steps:
- name: Checkout
uses: actions/checkout@v2.3.4
uses: actions/checkout@v2

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
php-version: ${{ matrix.php }}
ini-values: memory_limit=-1
tools: composer:v2

Expand All @@ -36,15 +37,15 @@ jobs:
uses: actions/cache@v2
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.json') }}
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php-version }}-composer-
php${{ matrix.php }}-composer-
- name: Update composer
run: composer self-update

- name: Install dependencies with composer
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: PHPCS check
run: vendor/bin/phpcs
Expand Down
49 changes: 32 additions & 17 deletions .scrutinizer.yml
@@ -1,18 +1,33 @@
build:
environment:
php: "7.4"
nodes:
analysis:
tests:
override:
- php-scrutinizer-run
filter:
paths:
- "src/*"
checks:
php: true
tools:
php_code_coverage:
enabled: true
external_code_coverage:
timeout: 600
php: true

filter:
paths:
- "src/*"

build:
nodes:
analysis:
environment:
php: 7.4.12

tests:
override:
- php-scrutinizer-run

tests-and-coverage:
environment:
php: 7.4.12

dependencies:
override:
- composer self-update
- composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

tests:
override:
- command: "./vendor/bin/phpunit --coverage-clover ./coverage.xml"
on_node: 1
coverage:
file: coverage.xml
format: php-clover
6 changes: 3 additions & 3 deletions composer.json
Expand Up @@ -24,11 +24,11 @@
"psr/http-message": "^1.0"
},
"require-dev": {
"infection/infection": "^0.21",
"phpunit/phpunit": "^9.5",
"php-http/psr7-integration-tests": "1.1.1",
"squizlabs/php_codesniffer": "^3.5",
"vimeo/psalm": "^4.6"
"roave/infection-static-analysis-plugin": "^1.8",
"squizlabs/php_codesniffer": "^3.6",
"vimeo/psalm": "^4.8"
},
"provide": {
"psr/http-message-implementation": "1.0",
Expand Down
6 changes: 1 addition & 5 deletions psalm.xml
@@ -1,16 +1,12 @@
<?xml version="1.0"?>
<psalm
totallyTyped="true"
resolveFromConfigFile="true"
errorLevel="1"
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>
Expand Down
12 changes: 6 additions & 6 deletions src/ServerRequest.php
Expand Up @@ -103,7 +103,7 @@ public function getCookieParams(): array
/**
* {@inheritDoc}
*/
public function withCookieParams(array $cookies): self
public function withCookieParams(array $cookies): ServerRequestInterface
{
$new = clone $this;
$new->cookieParams = $cookies;
Expand All @@ -121,7 +121,7 @@ public function getQueryParams(): array
/**
* {@inheritDoc}
*/
public function withQueryParams(array $query): self
public function withQueryParams(array $query): ServerRequestInterface
{
$new = clone $this;
$new->queryParams = $query;
Expand All @@ -139,7 +139,7 @@ public function getUploadedFiles(): array
/**
* {@inheritDoc}
*/
public function withUploadedFiles(array $uploadedFiles): self
public function withUploadedFiles(array $uploadedFiles): ServerRequestInterface
{
$this->validateUploadedFiles($uploadedFiles);
$new = clone $this;
Expand All @@ -160,7 +160,7 @@ public function getParsedBody()
*
* @psalm-suppress DocblockTypeContradiction
*/
public function withParsedBody($data): self
public function withParsedBody($data): ServerRequestInterface
{
if (!is_array($data) && !is_object($data) && $data !== null) {
throw new InvalidArgumentException(sprintf(
Expand Down Expand Up @@ -197,7 +197,7 @@ public function getAttribute($name, $default = null)
/**
* {@inheritDoc}
*/
public function withAttribute($name, $value): self
public function withAttribute($name, $value): ServerRequestInterface
{
if (array_key_exists($name, $this->attributes) && $this->attributes[$name] === $value) {
return $this;
Expand All @@ -211,7 +211,7 @@ public function withAttribute($name, $value): self
/**
* {@inheritDoc}
*/
public function withoutAttribute($name): self
public function withoutAttribute($name): ServerRequestInterface
{
if (!array_key_exists($name, $this->attributes)) {
return $this;
Expand Down
2 changes: 1 addition & 1 deletion src/UploadedFile.php
Expand Up @@ -246,7 +246,7 @@ public function getClientMediaType(): ?string
*/
private function moveOrWriteFile(string $targetPath): void
{
if ($this->file) {
if ($this->file !== null) {
$isCliEnv = (!PHP_SAPI || strpos(PHP_SAPI, 'cli') === 0 || strpos(PHP_SAPI, 'phpdbg') === 0);

if (!($isCliEnv ? rename($this->file, $targetPath) : move_uploaded_file($this->file, $targetPath))) {
Expand Down

0 comments on commit 0d4e0ed

Please sign in to comment.