Skip to content

Commit 78f30d5

Browse files
authored
Add PHP 8 support (#34)
Fixes #33.
1 parent 6c8b5c1 commit 78f30d5

7 files changed

Lines changed: 51 additions & 17 deletions

File tree

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ env:
1010
- PHP_RUNTIME='php:7.2-cli'
1111
- PHP_RUNTIME='php:7.3-cli' CHECK_CS=1
1212
- PHP_RUNTIME='php:7.4-cli' PHPUNIT_OPTS='--coverage-text --coverage-clover=coverage.clover'
13+
- PHP_RUNTIME='php:8.0-cli'
1314

1415
matrix:
1516
fast_finish: true

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,11 +432,11 @@ First, create a container:
432432
./dockerfile.sh | docker build -t msgpack -
433433
```
434434

435-
The command above will create a container named `msgpack` with PHP 7.4 runtime.
435+
The command above will create a container named `msgpack` with PHP 8.0 runtime.
436436
You may change the default runtime by defining the `PHP_RUNTIME` environment variable:
437437

438438
```sh
439-
PHP_RUNTIME='php:7.3-cli' ./dockerfile.sh | docker build -t msgpack -
439+
PHP_RUNTIME='php:7.4-cli' ./dockerfile.sh | docker build -t msgpack -
440440
```
441441

442442
> *See a list of various runtimes [here](.travis.yml#L8).*

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@
1111
}
1212
],
1313
"require": {
14-
"php": "^7.1.1"
14+
"php": "^7.1.1|^8"
1515
},
1616
"require-dev": {
17-
"ext-decimal": "*",
1817
"ext-gmp": "*",
1918
"friendsofphp/php-cs-fixer": "^2.14",
20-
"phpunit/phpunit": "^7.1|^8.0"
19+
"phpunit/phpunit": "^7.1|^8|^9"
2120
},
2221
"suggest": {
2322
"ext-decimal": "For converting overflowed integers to Decimal objects",

dockerfile.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#!/usr/bin/env bash
22

33
if [[ -z "$PHP_RUNTIME" ]]; then
4-
PHP_RUNTIME='php:7.4-cli'
4+
PHP_RUNTIME='php:8.0-cli'
55
fi
66

77
RUN_CMDS=''
8-
RUN_CMDS="$RUN_CMDS && \\\\\n apt-get install -y libmpdec-dev"
9-
RUN_CMDS="$RUN_CMDS && \\\\\n pecl install decimal && docker-php-ext-enable decimal"
8+
if [[ $PHP_RUNTIME != php:8* ]]; then
9+
RUN_CMDS="$RUN_CMDS && \\\\\n apt-get install -y libmpdec-dev"
10+
RUN_CMDS="$RUN_CMDS && \\\\\n pecl install decimal && docker-php-ext-enable decimal"
11+
fi
1012

1113
if [[ $PHPUNIT_OPTS =~ (^|[[:space:]])--coverage-[[:alpha:]] ]]; then
1214
RUN_CMDS="$RUN_CMDS && \\\\\n pecl install pcov && docker-php-ext-enable pcov"

tests/Unit/BufferUnpackerTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
final class BufferUnpackerTest extends TestCase
2626
{
27+
use PhpUnitCompat;
28+
2729
/**
2830
* @var BufferUnpacker
2931
*/
@@ -357,7 +359,7 @@ public function provideOptionsData() : iterable
357359
public function testConstructorThrowsExceptionOnInvalidOptions($options) : void
358360
{
359361
$this->expectException(InvalidOptionException::class);
360-
$this->expectExceptionMessageRegExp('/Invalid option .+?, use .+?/');
362+
$this->expectExceptionMessageMatches('/Invalid option .+?, use .+?/');
361363

362364
new BufferUnpacker('', $options);
363365
}
@@ -380,7 +382,7 @@ public function testConstructorSetsTransformers() : void
380382
$transformer = $this->createMock(Extension::class);
381383
$transformer->method('getType')->willReturn($type);
382384
$transformer->expects(self::once())->method('unpackExt')
383-
->with($this->isInstanceOf(BufferUnpacker::class), 1)
385+
->with(self::isInstanceOf(BufferUnpacker::class), 1)
384386
->willReturn($obj);
385387

386388
$unpacker = new BufferUnpacker('', null, [$transformer]);
@@ -399,13 +401,13 @@ public function testUnpackCustomType() : void
399401
$extension1 = $this->createMock(Extension::class);
400402
$extension1->method('getType')->willReturn($type1);
401403
$extension1->expects(self::once())->method('unpackExt')
402-
->with($this->isInstanceOf(BufferUnpacker::class), 1)
404+
->with(self::isInstanceOf(BufferUnpacker::class), 1)
403405
->willReturn($obj1);
404406

405407
$extension2 = $this->createMock(Extension::class);
406408
$extension2->method('getType')->willReturn($type2);
407409
$extension2->expects(self::once())->method('unpackExt')
408-
->with($this->isInstanceOf(BufferUnpacker::class), 1)
410+
->with(self::isInstanceOf(BufferUnpacker::class), 1)
409411
->willReturn($obj2);
410412

411413
$unpacker = $this->unpacker->extendWith($extension1, $extension2);

tests/Unit/PackerTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
final class PackerTest extends TestCase
2323
{
24+
use PhpUnitCompat;
25+
2426
/**
2527
* @var Packer
2628
*/
@@ -104,7 +106,7 @@ public function provideOptionsData() : array
104106
public function testConstructorThrowsExceptionOnInvalidOptions($options) : void
105107
{
106108
$this->expectException(InvalidOptionException::class);
107-
$this->expectExceptionMessageRegExp('/Invalid option .+?, use .+?/');
109+
$this->expectExceptionMessageMatches('/Invalid option .+?, use .+?/');
108110

109111
new Packer($options);
110112
}
@@ -127,7 +129,7 @@ public function testConstructorSetsTransformers() : void
127129

128130
$transformer = $this->createMock(CanPack::class);
129131
$transformer->expects(self::once())->method('pack')
130-
->with($this->isInstanceOf(Packer::class), $obj)
132+
->with(self::isInstanceOf(Packer::class), $obj)
131133
->willReturn($packed);
132134

133135
$packer = new Packer(null, [$transformer]);
@@ -146,7 +148,7 @@ public function testPackCustomType() : void
146148
$transformer1 = $this->createMock(CanPack::class);
147149
$transformer1->expects(self::atMost(2))->method('pack')
148150
->with(
149-
$this->isInstanceOf(Packer::class),
151+
self::isInstanceOf(Packer::class),
150152
self::logicalOr(self::identicalTo($obj1), self::identicalTo($obj2))
151153
)
152154
->willReturnCallback(static function ($packer, $value) use ($obj1, $packed1) {
@@ -156,7 +158,7 @@ public function testPackCustomType() : void
156158
$transformer2 = $this->createMock(CanPack::class);
157159
$transformer2->expects(self::atMost(2))->method('pack')
158160
->with(
159-
$this->isInstanceOf(Packer::class),
161+
self::isInstanceOf(Packer::class),
160162
self::logicalOr(self::identicalTo($obj1), self::identicalTo($obj2))
161163
)
162164
->willReturnCallback(static function ($packer, $value) use ($obj2, $packed2) {
@@ -175,7 +177,7 @@ public function testPackThrowsExceptionOnUnsupportedCustomType() : void
175177

176178
$transformer = $this->createMock(CanPack::class);
177179
$transformer->expects(self::once())->method('pack')
178-
->with($this->isInstanceOf(Packer::class), $obj)
180+
->with(self::isInstanceOf(Packer::class), $obj)
179181
->willReturn(null);
180182

181183
$packer = $this->packer->extendWith($transformer);

tests/Unit/PhpUnitCompat.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the rybakit/msgpack.php package.
5+
*
6+
* (c) Eugene Leonovich <gen.work@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace MessagePack\Tests\Unit;
13+
14+
/**
15+
* Compatibility layer for legacy PHPUnit versions.
16+
*/
17+
trait PhpUnitCompat
18+
{
19+
/**
20+
* TestCase::expectExceptionMessageRegExp() is deprecated since PHPUnit 8.4.
21+
*/
22+
public function expectExceptionMessageMatches(string $regularExpression) : void
23+
{
24+
is_callable('parent::expectExceptionMessageMatches')
25+
? parent::expectExceptionMessageMatches(...func_get_args())
26+
: parent::expectExceptionMessageRegExp(...func_get_args());
27+
}
28+
}

0 commit comments

Comments
 (0)