Skip to content

Commit 22c70c7

Browse files
authored
Add test cases for code coverage, update of workflow actions (#1)
* Update dev dependencies * Cleanup psalm.xml * Add more test cases for code coverage * Update .scrutinizer.yml * Update of workflow actions * Format phpunit.xml.dist
1 parent 7082b8e commit 22c70c7

File tree

10 files changed

+194
-88
lines changed

10 files changed

+194
-88
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ trim_trailing_whitespace = true
1212

1313
[*.md]
1414
trim_trailing_whitespace = false
15+
16+
[*.yml]
17+
indent_size = 2

.github/workflows/build.yml

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ name: build
66

77
jobs:
88
tests:
9-
name: PHP ${{ matrix.php-version }}-${{ matrix.os }}
9+
name: PHP ${{ matrix.php }}-${{ matrix.os }}
10+
1011
runs-on: ${{ matrix.os }}
12+
1113
env:
12-
extensions: curl, mbstring, dom
1314
key: cache-v1
1415

1516
strategy:
@@ -18,19 +19,18 @@ jobs:
1819
- ubuntu-latest
1920
- windows-latest
2021

21-
php-version:
22+
php:
2223
- "7.4"
2324
- "8.0"
2425

2526
steps:
2627
- name: Checkout
27-
uses: actions/checkout@v2.3.4
28+
uses: actions/checkout@v2
2829

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

4646
- name: Cache dependencies installed with composer
47-
uses: actions/cache@v1
47+
uses: actions/cache@v2
4848
with:
4949
path: ${{ env.COMPOSER_CACHE_DIR }}
50-
key: php${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.json') }}
50+
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
5151
restore-keys: |
52-
php${{ matrix.php-version }}-composer-
52+
php${{ matrix.php }}-composer-
5353
5454
- name: Update composer
5555
run: composer self-update
5656

57-
- name: Install dependencies with composer php 7.4
58-
if: matrix.php-version == '7.4'
59-
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader
60-
61-
- name: Install dependencies with composer php 8.0
62-
if: matrix.php-version == '8.0'
63-
run: composer update --ignore-platform-reqs --prefer-dist --no-interaction --no-progress --optimize-autoloader
64-
65-
- name: PHPUnit run with coverage on Linux PHP 7.4
66-
if: matrix.os == 'ubuntu-latest' && matrix.php-version == '7.4'
67-
run: vendor/bin/phpunit --coverage-clover=coverage.clover
68-
69-
- name: PHPUnit run without coverage on Linux PHP 8.0
70-
if: matrix.os == 'ubuntu-latest' && matrix.php-version == '8.0'
71-
run: vendor/bin/phpunit
72-
73-
- name: PHPUnit run without coverage on Windows
74-
if: matrix.os == 'windows-latest'
75-
run: vendor/bin/phpunit
57+
- name: Install dependencies with composer
58+
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
7659

77-
- name: Code coverage scrutinizer on Linux PHP 7.4
78-
if: matrix.os == 'ubuntu-latest' && matrix.php-version == '7.4'
79-
run: |
80-
wget https://scrutinizer-ci.com/ocular.phar
81-
php ocular.phar code-coverage:upload --format=php-clover coverage.clover
60+
- name: Run tests with phpunit
61+
run: vendor/bin/phpunit --colors=always

.github/workflows/static.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ name: static
66

77
jobs:
88
static:
9-
name: PHP ${{ matrix.php-version }}-${{ matrix.os }}
9+
name: PHP ${{ matrix.php }}-${{ matrix.os }}
1010

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

@@ -15,17 +15,18 @@ jobs:
1515
os:
1616
- ubuntu-latest
1717

18-
php-version:
18+
php:
1919
- "7.4"
20+
- "8.0"
2021

2122
steps:
2223
- name: Checkout
23-
uses: actions/checkout@v2.3.4
24+
uses: actions/checkout@v2
2425

2526
- name: Install PHP
2627
uses: shivammathur/setup-php@v2
2728
with:
28-
php-version: ${{ matrix.php-version }}
29+
php-version: ${{ matrix.php }}
2930
ini-values: memory_limit=-1
3031
tools: composer:v2
3132

@@ -36,15 +37,15 @@ jobs:
3637
uses: actions/cache@v2
3738
with:
3839
path: ${{ env.COMPOSER_CACHE_DIR }}
39-
key: php${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.json') }}
40+
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
4041
restore-keys: |
41-
php${{ matrix.php-version }}-composer-
42+
php${{ matrix.php }}-composer-
4243
4344
- name: Update composer
4445
run: composer self-update
4546

4647
- name: Install dependencies with composer
47-
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader
48+
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
4849

4950
- name: PHPCS check
5051
run: vendor/bin/phpcs

.scrutinizer.yml

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
1-
build:
2-
environment:
3-
php: "7.4"
4-
nodes:
5-
analysis:
6-
tests:
7-
override:
8-
- php-scrutinizer-run
9-
filter:
10-
paths:
11-
- "src/*"
121
checks:
13-
php: true
14-
tools:
15-
php_code_coverage:
16-
enabled: true
17-
external_code_coverage:
18-
timeout: 600
2+
php: true
3+
4+
filter:
5+
paths:
6+
- "src/*"
7+
8+
build:
9+
nodes:
10+
analysis:
11+
environment:
12+
php: 7.4.12
13+
14+
tests:
15+
override:
16+
- php-scrutinizer-run
17+
18+
tests-and-coverage:
19+
environment:
20+
php: 7.4.12
21+
22+
dependencies:
23+
override:
24+
- composer self-update
25+
- composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
26+
27+
tests:
28+
override:
29+
- command: "./vendor/bin/phpunit --coverage-clover ./coverage.xml"
30+
on_node: 1
31+
coverage:
32+
file: coverage.xml
33+
format: php-clover

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
},
2525
"require-dev": {
2626
"phpunit/phpunit": "^9.5",
27-
"squizlabs/php_codesniffer": "^3.5",
28-
"vimeo/psalm": "^4.3"
27+
"squizlabs/php_codesniffer": "^3.6",
28+
"vimeo/psalm": "^4.8"
2929
},
3030
"provide": {
3131
"psr/http-message-implementation": "1.0"

phpunit.xml.dist

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<phpunit
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
5-
bootstrap="./vendor/autoload.php"
6-
executionOrder="depends,defects"
7-
beStrictAboutCoversAnnotation="true"
8-
beStrictAboutOutputDuringTests="true"
9-
beStrictAboutTodoAnnotatedTests="true"
10-
convertWarningsToExceptions="true"
11-
convertNoticesToExceptions="true"
12-
convertErrorsToExceptions="true"
13-
stopOnFailure="false"
14-
verbose="true"
15-
colors="true"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
5+
bootstrap="./vendor/autoload.php"
6+
executionOrder="depends,defects"
7+
beStrictAboutCoversAnnotation="true"
8+
beStrictAboutOutputDuringTests="true"
9+
beStrictAboutTodoAnnotatedTests="true"
10+
convertWarningsToExceptions="true"
11+
convertNoticesToExceptions="true"
12+
convertErrorsToExceptions="true"
13+
stopOnFailure="false"
14+
verbose="true"
15+
colors="true"
1616
>
1717
<php>
1818
<ini name="error_reporting" value="-1" />

psalm.xml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
<?xml version="1.0"?>
22
<psalm
3-
totallyTyped="true"
4-
resolveFromConfigFile="true"
3+
errorLevel="1"
54
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
65
xmlns="https://getpsalm.org/schema/config"
76
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
87
>
98
<projectFiles>
109
<directory name="src" />
11-
<ignoreFiles>
12-
<directory name="vendor" />
13-
</ignoreFiles>
1410
</projectFiles>
1511
</psalm>

tests/PhpInputStreamTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ public function testGetContentsReturnRemainingContents()
138138

139139
$stream = new PhpInputStream('data://,123');
140140
$this->assertSame('123', $stream->getContents());
141+
$this->assertSame('123', $stream->getContents());
141142

142143
$stream = new PhpInputStream('data://,123');
143144
$stream->read(1);

tests/SapiNormalizerTest.php

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,16 @@ public function setUp(): void
2828
'SERVER_PORT' => '443',
2929
'REQUEST_METHOD' => 'GET',
3030
'SERVER_PROTOCOL' => 'HTTP/1.1',
31+
'SERVER_NAME' => 'example.org',
3132
'HTTP_HOST' => 'example.com',
3233
'HTTP_CACHE_CONTROL' => 'max-age=0',
3334
'HTTP_X_FORWARDED_PROTO' => 'https',
3435
'CONTENT_TYPE' => 'text/html; charset=UTF-8',
3536
'REQUEST_URI' => '/path?name=value',
3637
'QUERY_STRING' => 'name=value',
38+
'REDIRECT_STATUS' => '200',
39+
'REDIRECT_HTTP_HOST' => 'example.org',
40+
'REDIRECT_HTTP_CONNECTION' => 'keep-alive',
3741
];
3842
}
3943

@@ -97,6 +101,19 @@ public function testNormalizeUri(): void
97101
$this->assertSame('/path', $uri->getPath());
98102
$this->assertSame($this->server['QUERY_STRING'], $uri->getQuery());
99103
$this->assertSame('https://example.com/path?name=value', (string) $uri);
104+
105+
unset($this->server['HTTPS'], $this->server['HTTP_HOST']);
106+
107+
$uri = $this->normalizer->normalizeUri($this->server);
108+
$this->assertInstanceOf(UriInterface::class, $uri);
109+
$this->assertSame($this->server['HTTP_X_FORWARDED_PROTO'], $uri->getScheme());
110+
$this->assertSame($this->server['SERVER_NAME'], $uri->getAuthority());
111+
$this->assertSame('', $uri->getUserInfo());
112+
$this->assertSame($this->server['SERVER_NAME'], $uri->getHost());
113+
$this->assertSame(null, $uri->getPort());
114+
$this->assertSame('/path', $uri->getPath());
115+
$this->assertSame($this->server['QUERY_STRING'], $uri->getQuery());
116+
$this->assertSame('https://example.org/path?name=value', (string) $uri);
100117
}
101118

102119
public function testNormalizeUriIfServerIsEmpty(): void
@@ -117,17 +134,13 @@ public function testNormalizeHeaders(): void
117134
{
118135
$headers = $this->normalizer->normalizeHeaders($this->server);
119136

120-
$this->assertSame($this->server['HTTP_HOST'], $headers['Host']);
121-
$this->assertSame($this->server['HTTP_CACHE_CONTROL'], $headers['Cache-Control']);
122-
$this->assertSame($this->server['HTTP_X_FORWARDED_PROTO'], $headers['X-Forwarded-Proto']);
123-
$this->assertSame($this->server['CONTENT_TYPE'], $headers['Content-Type']);
124-
125-
$this->assertFalse(isset($headers['HTTPS']));
126-
$this->assertFalse(isset($headers['SERVER_PORT']));
127-
$this->assertFalse(isset($headers['REQUEST_METHOD']));
128-
$this->assertFalse(isset($headers['SERVER_PROTOCOL']));
129-
$this->assertFalse(isset($headers['REQUEST_URI']));
130-
$this->assertFalse(isset($headers['QUERY_STRING']));
137+
$this->assertSame($headers, [
138+
'Host' => 'example.com',
139+
'Cache-Control' => 'max-age=0',
140+
'X-Forwarded-Proto' => 'https',
141+
'Content-Type' => 'text/html; charset=UTF-8',
142+
'Connection' => 'keep-alive',
143+
]);
131144
}
132145

133146
public function testNormalizeHeadersIfServerIsEmpty(): void

0 commit comments

Comments
 (0)