Skip to content

Commit

Permalink
Add support for PHPUnit 9
Browse files Browse the repository at this point in the history
  • Loading branch information
rybakit committed Mar 26, 2020
1 parent f4cd488 commit 0c8693c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"ext-sockets": "*",
"friendsofphp/php-cs-fixer": "^2.14",
"monolog/monolog": "^1.24|^2.0",
"phpunit/phpunit": "^7.1|^8",
"phpunit/phpunit": "^7.1|^8|^9",
"psr/log": "^1.1",
"rybakit/msgpack": "^0.7",
"vimeo/psalm": "^3.9"
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/Connection/ParseGreetingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function testParseGreetingWithInvalidSalt(string $greeting) : void
$client = $clientBuilder->setOptions(['username' => 'guest'])->build();

$this->expectException(\RuntimeException::class);
$this->expectExceptionMessageRegExp('/(Unable to decode salt|Salt is too short)/');
$this->expectExceptionMessageMatches('/(Unable to decode salt|Salt is too short)/');

$client->ping();
}
Expand Down
3 changes: 3 additions & 0 deletions tests/Integration/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
use Tarantool\Client\Exception\CommunicationFailed;
use Tarantool\Client\Handler\Handler;
use Tarantool\Client\Request\Request;
use Tarantool\Client\Tests\PhpUnitCompat;

abstract class TestCase extends BaseTestCase
{
use PhpUnitCompat;

protected const STAT_REQUEST_SELECT = 'SELECT';
protected const STAT_REQUEST_AUTH = 'AUTH';

Expand Down
31 changes: 31 additions & 0 deletions tests/PhpUnitCompat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/**
* This file is part of the Tarantool Client package.
*
* (c) Eugene Leonovich <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Tarantool\Client\Tests;

/**
* A compatibility layer for the legacy PHPUnit 7.
*/
trait PhpUnitCompat
{
public function expectExceptionMessageMatches(string $regularExpression) : void
{
if (is_callable('parent::expectExceptionMessageRegExp')) {
parent::expectExceptionMessageRegExp($regularExpression);

return;
}

parent::expectExceptionMessageMatches($regularExpression);
}
}
5 changes: 4 additions & 1 deletion tests/Unit/Packer/PeclPackerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
use Tarantool\Client\Keys;
use Tarantool\Client\Packer\Packer;
use Tarantool\Client\Packer\PeclPacker;
use Tarantool\Client\Tests\PhpUnitCompat;

/**
* @requires extension msgpack
*/
final class PeclPackerTest extends PackerTest
{
use PhpUnitCompat;

protected function createPacker() : Packer
{
return new PeclPacker();
Expand All @@ -33,7 +36,7 @@ protected function createPacker() : Packer
public function testThrowExceptionOnBadUnpackData(string $data) : void
{
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessageRegExp('/Unable to unpack response (header|body)/');
$this->expectExceptionMessageMatches('/Unable to unpack response (header|body)/');

$this->packer->unpack($data)->tryGetBodyField(Keys::DATA);
}
Expand Down

0 comments on commit 0c8693c

Please sign in to comment.