Skip to content

Commit

Permalink
add workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
mikespub committed Dec 17, 2023
1 parent 1f533d5 commit f12f807
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 9 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: "testing"

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
qa:
name: Quality assurance
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Validate composer.json and composer.lock
run: composer validate

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer install --prefer-dist --no-progress

- name: Coding Standard
run: composer run-script phpstan

tests:
name: Tests
runs-on: ubuntu-latest

strategy:
matrix:
php:
- 8.1
- 8.2
- 8.3
composer-args: [ "" ]
fail-fast: false

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}

- name: Cache PHP dependencies
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-php-${{ matrix.php }}-composer-

- name: Install dependencies
run: composer install --prefer-dist --no-progress ${{ matrix.composer-args }}

- name: Tests
run: composer test

- name: Tests coverage
run: composer coverage
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,11 @@
"psr-4": {
"MichehTest\\Cache\\": "test/"
}
},
"scripts": {
"phpstan": "vendor/bin/phpstan analyse",
"test": "vendor/bin/phpunit",
"coverage": "vendor/bin/phpunit --coverage-text",
"coverage-html": "vendor/bin/phpunit --coverage-html=coverage"
}
}
16 changes: 16 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
parameters:
ignoreErrors:
-
message: "#^Unreachable statement \\- code above always terminates\\.$#"
count: 1
path: src/CacheUtil.php

-
message: "#^Result of \\|\\| is always false\\.$#"
count: 1
path: src/Header/CacheControl.php

-
message: "#^Unsafe usage of new static\\(\\)\\.$#"
count: 1
path: src/Header/CacheControl.php
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ includes:
#- phpstan-baseline.neon

parameters:
level: 5
level: 6
paths:
- src/
#- test/
Expand Down
1 change: 1 addition & 0 deletions src/CacheUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ protected function getTimestampFromValue($time)
return strtotime($time);
}

/** @phpstan-ignore-next-line */
throw new InvalidArgumentException('Could not create timestamp from ' . gettype($time) . '.');
}

Expand Down
2 changes: 2 additions & 0 deletions src/Header/CacheControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ abstract class CacheControl
*/
protected static function createFromString($string)
{
/** @phpstan-ignore-next-line */
$cacheControl = new static();

$parts = explode(',', $string);
Expand Down Expand Up @@ -158,6 +159,7 @@ public function hasNoTransform()
*/
public function withExtension($name, $value)
{
/** @phpstan-ignore-next-line */
if (!is_string($name) || !is_string($value)) {
throw new InvalidArgumentException('Name and value of the extension have to be a string.');
}
Expand Down
3 changes: 2 additions & 1 deletion test/CacheUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public function testWithRelativeExpiresAndString()
//'InvalidArgumentException',
'Expected an integer with the number of seconds, received string.'
);
/** @phpstan-ignore-next-line */
$this->cacheUtil->withRelativeExpires($response, 'now');
}

Expand Down Expand Up @@ -307,7 +308,7 @@ public function testHasCurrentStateWithModified($ifUnmodified, $lastModified, $i
$request->method('getHeaderLine')->willReturnMap($map);


$result = $this->cacheUtil->hasCurrentState($request, null, $lastModified);
$result = $this->cacheUtil->hasCurrentState($request, '', $lastModified);
$this->assertSame($isCurrent, $result);
}

Expand Down
3 changes: 2 additions & 1 deletion test/Header/CacheControlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function testFromStringWithUnknownDirectiveFlag()
public function testWithMaxAge()
{
$control = $this->getControlWithDirective('max-age', 5);
$this->assertReturn($control->withMaxAge('5'));
$this->assertReturn($control->withMaxAge(5));
}

/**
Expand Down Expand Up @@ -263,6 +263,7 @@ public function testWithExtensionInvalidType()
//'InvalidArgumentException',
'Name and value of the extension have to be a string.'
);
/** @phpstan-ignore-next-line */
$this->cacheControl->withExtension('foo', true);
}

Expand Down
14 changes: 8 additions & 6 deletions test/Header/CacheControlTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
namespace MichehTest\Cache\Header;

use Micheh\Cache\Header\CacheControl;
use Micheh\Cache\Header\RequestCacheControl;
use Micheh\Cache\Header\ResponseCacheControl;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

Expand All @@ -30,7 +32,7 @@ protected function setUp(): void
}

/**
* @param string $value
* @param string|int|bool|null $value
*/
protected function assertReturn($value)
{
Expand All @@ -39,7 +41,7 @@ protected function assertReturn($value)

/**
* @param array<string, mixed> $directives
* @param MockObject|CacheControl
* @param MockObject|CacheControl $control
*/
protected function assertSameDirectives($directives, $control)
{
Expand All @@ -54,8 +56,8 @@ protected function assertSameDirectives($directives, $control)

/**
* @param string $name
* @param string|int $value
* @return MockObject|CacheControl
* @param string|int|bool|null $value
* @return MockObject|CacheControl|RequestCacheControl|ResponseCacheControl
*/
protected function getControlWithDirective($name, $value)
{
Expand All @@ -68,7 +70,7 @@ protected function getControlWithDirective($name, $value)

/**
* @param string $name
* @return MockObject|CacheControl
* @return MockObject|CacheControl|RequestCacheControl|ResponseCacheControl
*/
protected function getControlWithGetDirective($name)
{
Expand All @@ -81,7 +83,7 @@ protected function getControlWithGetDirective($name)

/**
* @param string $name
* @return MockObject|CacheControl
* @return MockObject|CacheControl|RequestCacheControl|ResponseCacheControl
*/
protected function getControlWithHasFlag($name)
{
Expand Down

0 comments on commit f12f807

Please sign in to comment.