Skip to content

Commit 1ac4e9f

Browse files
Merge pull request #16 from martin-helmich/feature/support-phpunit9
Add support for PHPUnit 9 and migrate to Github Actions
2 parents 917da61 + 8cbab18 commit 1ac4e9f

File tree

7 files changed

+113
-50
lines changed

7 files changed

+113
-50
lines changed

.github/workflows/php.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Unit tests
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
strategy:
8+
matrix:
9+
php: ['7.2', '7.3', '7.4']
10+
phpunit: ['8.0', '9.0']
11+
exclude:
12+
- php: '7.2'
13+
phpunit: '9.0'
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v1
18+
19+
- name: Setup PHP
20+
uses: shivammathur/setup-php@v1
21+
with:
22+
php-version: ${{ matrix.php }}
23+
extensions: mbstring, intl, json
24+
coverage: pcov
25+
26+
- name: Validate composer.json and composer.lock
27+
run: composer validate
28+
29+
- name: Declare required PHPUnit version
30+
run: |
31+
composer require --no-update --dev phpunit/phpunit ~${{ matrix.phpunit }}
32+
33+
- name: Install dependencies
34+
run: composer install --prefer-dist --no-progress --no-suggest
35+
36+
#- name: Run type checker
37+
# run: ./vendor/bin/psalm
38+
39+
- name: Run unit tests
40+
run: ./vendor/bin/phpunit --testdox
41+
42+
coverage:
43+
runs-on: ubuntu-latest
44+
45+
steps:
46+
- uses: actions/checkout@v1
47+
48+
- name: Setup PHP
49+
uses: shivammathur/setup-php@v1
50+
with:
51+
php-version: 7.4
52+
extensions: mbstring, intl, json
53+
coverage: pcov
54+
55+
- name: Install dependencies
56+
run: composer install --prefer-dist --no-progress --no-suggest
57+
58+
- name: Test & publish code coverage
59+
uses: paambaati/codeclimate-action@v2.3.0
60+
env:
61+
CC_TEST_REPORTER_ID: ${{ secrets.codeClimateReporterID }}
62+
with:
63+
coverageCommand: ./vendor/bin/phpunit --coverage-clover=clover.xml
64+
debug: true

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ There are several release branches of this library, each of these being compatib
2424
with different releases of PHPUnit and PHP. The following table should give an
2525
easy overview:
2626

27-
| PSR-7 assertion version | PHPUnit 4 | PHPUnit 5 | PHPUnit 6 | PHPUnit 7 | PHPUnit 8 |
28-
| ----------------------- | --------- | --------- | --------- | --------- | --------- |
29-
| v1 (branch `v1`), **unsupported** | :white_check_mark: | :white_check_mark: | :no_entry_sign: | :no_entry_sign: | :no_entry_sign: |
30-
| v2 (branch `v2`), **unsupported** | :no_entry_sign: | :no_entry_sign: | :white_check_mark: | :no_entry_sign: | :no_entry_sign: |
31-
| v3 (branch `v3`) | :no_entry_sign: | :no_entry_sign: | :no_entry_sign: | :white_check_mark: | :no_entry_sign: |
32-
| v4 (branch `master`) | :no_entry_sign: | :no_entry_sign: | :no_entry_sign: | :no_entry_sign: | :white_check_mark: |
27+
| PSR-7 assertion version | PHPUnit 4 | PHPUnit 5 | PHPUnit 6 | PHPUnit 7 | PHPUnit 8 | PHPUnit 9 |
28+
| ----------------------- | --------- | --------- | --------- | --------- | --------- | --------- |
29+
| v1 (branch `v1`), **unsupported** | :white_check_mark: | :white_check_mark: | :no_entry_sign: | :no_entry_sign: | :no_entry_sign: | :no_entry_sign: |
30+
| v2 (branch `v2`), **unsupported** | :no_entry_sign: | :no_entry_sign: | :white_check_mark: | :no_entry_sign: | :no_entry_sign: | :no_entry_sign: |
31+
| v3 (branch `v3`) | :no_entry_sign: | :no_entry_sign: | :no_entry_sign: | :white_check_mark: | :no_entry_sign: | :no_entry_sign: |
32+
| v4 (branch `master`) | :no_entry_sign: | :no_entry_sign: | :no_entry_sign: | :no_entry_sign: | :white_check_mark: | :white_check_mark: |
3333

3434
When you are using `composer require` and have already declared a dependency to
3535
`phpunit/phpunit` in your `composer.json` file, Composer should pick latest

composer.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
],
1111
"require": {
1212
"php": "^7.1",
13-
"helmich/phpunit-json-assert": "^3.0",
13+
"helmich/phpunit-json-assert": "^3.1",
1414
"psr/http-message": "^1.0"
1515
},
1616
"require-dev": {
1717
"guzzlehttp/psr7": "^1.2",
18-
"phpunit/phpunit": "^8.0"
18+
"phpunit/phpunit": "^8.0 || ^9.0"
1919
},
2020
"conflict": {
21-
"phpunit/phpunit": "<8.0 || >= 9.0"
21+
"phpunit/phpunit": "<8.0 || >= 10.0"
2222
},
2323
"autoload": {
2424
"psr-4": {
@@ -27,12 +27,11 @@
2727
},
2828
"autoload-dev": {
2929
"files": [
30-
"vendor/phpunit/phpunit/src/Framework/Assert/Functions.php",
3130
"vendor/helmich/phpunit-json-assert/src/Functions.php",
3231
"src/Functions.php"
3332
]
3433
},
3534
"config": {
3635
"sort-packages": true
3736
}
38-
}
37+
}

tests/Functional/FunctionalConstraintTest.php

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,49 +14,49 @@ class FunctionalConstraintTest extends TestCase
1414
public function testHasUriCanSucceed()
1515
{
1616
$request = new Request('GET', '/foo');
17-
assertThat($request, hasUri('/foo'));
17+
self::assertThat($request, hasUri('/foo'));
1818
}
1919

2020
public function testHasUriCanFail()
2121
{
2222
$this->expectException(AssertionFailedError::class);
2323

2424
$request = new Request('GET', '/foo');
25-
assertThat($request, hasUri('/bar'));
25+
self::assertThat($request, hasUri('/bar'));
2626
}
2727

2828
public function testHasHeaderCanSucceedWithPrimitiveValue()
2929
{
3030
$request = new Request('GET', '/', ['x-foo' => 'bar']);
31-
assertThat($request, hasHeader('X-Foo', 'bar'));
31+
self::assertThat($request, hasHeader('X-Foo', 'bar'));
3232
}
3333

3434
public function testHasHeaderCanFailWithPrimitiveValue()
3535
{
3636
$this->expectException(AssertionFailedError::class);
3737

3838
$request = new Request('GET', '/', ['x-foo' => 'baz']);
39-
assertThat($request, hasHeader('X-Foo', 'bar'));
39+
self::assertThat($request, hasHeader('X-Foo', 'bar'));
4040
}
4141

4242
public function testHasHeaderCanFailWithNonExistingHeader()
4343
{
4444
$this->expectException(AssertionFailedError::class);
4545

4646
$request = new Request('GET', '/', []);
47-
assertThat($request, hasHeader('X-Foo', 'bar'));
47+
self::assertThat($request, hasHeader('X-Foo', 'bar'));
4848
}
4949

5050
public function testHasHeaderCanSucceedWithConstraint()
5151
{
5252
$request = new Request('GET', '/', ['x-foo' => 14]);
53-
assertThat($request, hasHeader('X-Foo', greaterThanOrEqual(10)));
53+
self::assertThat($request, hasHeader('X-Foo', self::greaterThanOrEqual(10)));
5454
}
5555

5656
public function testHasHeadersCanSucceedWithConstraint()
5757
{
5858
$request = new Request('GET', '/', ['x-foo' => 14, 'content-type' => 'text/plain']);
59-
assertThat($request, hasHeaders([
59+
self::assertThat($request, hasHeaders([
6060
'X-Foo' => Assert::greaterThanOrEqual(10),
6161
'Content-Type' => 'text/plain',
6262
]));
@@ -67,27 +67,27 @@ public function testHasHeaderCanFailWithConstraint()
6767
$this->expectException(AssertionFailedError::class);
6868

6969
$request = new Request('GET', '/', ['x-foo' => 4]);
70-
assertThat($request, hasHeader('X-Foo', greaterThanOrEqual(10)));
70+
self::assertThat($request, hasHeader('X-Foo', self::greaterThanOrEqual(10)));
7171
}
7272

7373
public function testBodyMatchesCanSucceed()
7474
{
7575
$request = new Request('GET', '/', [], 'foobar');
76-
assertThat($request, bodyMatches(equalTo('foobar')));
76+
self::assertThat($request, bodyMatches(self::equalTo('foobar')));
7777
}
7878

7979
public function testBodyMatchesCanFail()
8080
{
8181
$this->expectException(AssertionFailedError::class);
8282

8383
$request = new Request('GET', '/', [], 'foobar');
84-
assertThat($request, bodyMatches(equalTo('barbaz')));
84+
self::assertThat($request, bodyMatches(self::equalTo('barbaz')));
8585
}
8686

8787
public function testBodyMatchesJsonCanSucceed()
8888
{
8989
$request = new Request('GET', '/foo', ['content-type' => 'application/json'], json_encode(['foo' => 'bar']));
90-
assertThat($request, bodyMatchesJson(['$.foo' => 'bar']));
90+
self::assertThat($request, bodyMatchesJson(['$.foo' => 'bar']));
9191
}
9292

9393
public function dataForRequestMethods()
@@ -109,55 +109,55 @@ public function dataForRequestMethods()
109109
*/
110110
public function testAssertRequestHasMethodCanSucceed($method)
111111
{
112-
assertThat(new Request($method, '/'), hasMethod($method));
112+
self::assertThat(new Request($method, '/'), hasMethod($method));
113113
}
114114

115115
public function testIsGetCanSucceed()
116116
{
117-
assertThat(new Request('GET', '/'), isGet());
117+
self::assertThat(new Request('GET', '/'), isGet());
118118
}
119119

120120
public function testIsGetCanFail()
121121
{
122122
$this->expectException(AssertionFailedError::class);
123123

124-
assertThat(new Request('POST', '/'), isGet());
124+
self::assertThat(new Request('POST', '/'), isGet());
125125
}
126126

127127
public function testIsPostCanSucceed()
128128
{
129-
assertThat(new Request('POST', '/'), isPost());
129+
self::assertThat(new Request('POST', '/'), isPost());
130130
}
131131

132132
public function testIsPostCanFail()
133133
{
134134
$this->expectException(AssertionFailedError::class);
135135

136-
assertThat(new Request('GET', '/'), isPost());
136+
self::assertThat(new Request('GET', '/'), isPost());
137137
}
138138

139139
public function testIsPutCanSucceed()
140140
{
141-
assertThat(new Request('PUT', '/'), isPut());
141+
self::assertThat(new Request('PUT', '/'), isPut());
142142
}
143143

144144
public function testIsPutCanFail()
145145
{
146146
$this->expectException(AssertionFailedError::class);
147147

148-
assertThat(new Request('GET', '/'), isPut());
148+
self::assertThat(new Request('GET', '/'), isPut());
149149
}
150150

151151
public function testIsDeleteCanSucceed()
152152
{
153-
assertThat(new Request('DELETE', '/'), isDelete());
153+
self::assertThat(new Request('DELETE', '/'), isDelete());
154154
}
155155

156156
public function testIsDeleteCanFail()
157157
{
158158
$this->expectException(AssertionFailedError::class);
159159

160-
assertThat(new Request('POST', '/'), isDelete());
160+
self::assertThat(new Request('POST', '/'), isDelete());
161161
}
162162

163163
public function dataForStatusCodes()
@@ -175,60 +175,60 @@ public function dataForStatusCodes()
175175
*/
176176
public function testHasStatusCanSucceed($status)
177177
{
178-
assertThat(new Response($status), hasStatus($status));
178+
self::assertThat(new Response($status), hasStatus($status));
179179
}
180180

181181
public function testHasStatusCanFail()
182182
{
183183
$this->expectException(AssertionFailedError::class);
184184

185-
assertThat(new Response(400), hasStatus(200));
185+
self::assertThat(new Response(400), hasStatus(200));
186186
}
187187

188188
public function testIsSuccessCanSucceed()
189189
{
190-
assertThat(new Response(200), isSuccess());
190+
self::assertThat(new Response(200), isSuccess());
191191
}
192192

193193
public function testIsSuccessCanFail()
194194
{
195195
$this->expectException(AssertionFailedError::class);
196196

197-
assertThat(new Response(404), isSuccess());
197+
self::assertThat(new Response(404), isSuccess());
198198
}
199199

200200
public function testIsClientErrorCanSucceed()
201201
{
202-
assertThat(new Response(404), isClientError());
202+
self::assertThat(new Response(404), isClientError());
203203
}
204204

205205
public function testIsClientErrorCanFail()
206206
{
207207
$this->expectException(AssertionFailedError::class);
208208

209-
assertThat(new Response(200), isClientError());
209+
self::assertThat(new Response(200), isClientError());
210210
}
211211

212212
public function testIsServerErrorCanSucceed()
213213
{
214-
assertThat(new Response(503), isServerError());
214+
self::assertThat(new Response(503), isServerError());
215215
}
216216

217217
public function testIsServerErrorCanFail()
218218
{
219219
$this->expectException(AssertionFailedError::class);
220220

221-
assertThat(new Response(200), isServerError());
221+
self::assertThat(new Response(200), isServerError());
222222
}
223223

224224
public function testHasContentTypeSucceedsOnEquality()
225225
{
226-
assertThat(new Response(200, ['content-type' => ['application/json']]), hasContentType('application/json'));
226+
self::assertThat(new Response(200, ['content-type' => ['application/json']]), hasContentType('application/json'));
227227
}
228228

229229
public function testHasContentTypeSucceedsWithCharset()
230230
{
231-
assertThat(new Response(200, ['content-type' => ['application/json;charset=utf8']]), hasContentType('application/json'));
231+
self::assertThat(new Response(200, ['content-type' => ['application/json;charset=utf8']]), hasContentType('application/json'));
232232
}
233233

234234
}

tests/Unit/Constraint/HasQueryParameterConstraintTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,31 @@ public function testMatchesStringUrls()
1414
$url = "https://some-domain.example/foo?bar=baz";
1515
$constraint = new HasQueryParameterConstraint("bar", "baz");
1616

17-
assertThat($constraint->evaluate($url, "", true), isTrue());
17+
self::assertThat($constraint->evaluate($url, "", true), self::isTrue());
1818
}
1919

2020
public function testMatchesStringUrlsNegative()
2121
{
2222
$url = "https://some-domain.example/foo?bar=baz";
2323
$constraint = new HasQueryParameterConstraint("tulpen", "bunt");
2424

25-
assertThat($constraint->evaluate($url, "", true), isFalse());
25+
self::assertThat($constraint->evaluate($url, "", true), self::isFalse());
2626
}
2727

2828
public function testMatchesPsr7Uris()
2929
{
3030
$uri = uri_for("https://some-domain.example/foo?bar=baz");
3131
$constraint = new HasQueryParameterConstraint("bar", "baz");
3232

33-
assertThat($constraint->evaluate($uri, "", true), isTrue());
33+
self::assertThat($constraint->evaluate($uri, "", true), self::isTrue());
3434
}
3535

3636
public function testMatchesPsr7UrisNegative()
3737
{
3838
$uri = uri_for("https://some-domain.example/foo?autobahn=1");
3939
$constraint = new HasQueryParameterConstraint("bar", "baz");
4040

41-
assertThat($constraint->evaluate($uri, "", true), isFalse());
41+
self::assertThat($constraint->evaluate($uri, "", true), self::isFalse());
4242
}
4343

4444
public function testMatchesRequest()
@@ -48,6 +48,6 @@ public function testMatchesRequest()
4848

4949
$constraint = new HasQueryParameterConstraint("bar", "baz");
5050

51-
assertThat($constraint->evaluate($request, "", true), isTrue());
51+
self::assertThat($constraint->evaluate($request, "", true), self::isTrue());
5252
}
5353
}

0 commit comments

Comments
 (0)