From 601a637800f7aaffe42b54cb2917d8c27a5a54f9 Mon Sep 17 00:00:00 2001 From: Piotr Horzycki Date: Thu, 26 Nov 2020 12:16:40 +0100 Subject: [PATCH 1/2] PHP 8 and PHPUnit 9 support --- .travis.yml | 1 + composer.json | 4 ++-- tests/BuilderTest.php | 10 +++++----- tests/Service/FactoryTest.php | 25 +++++++++++++------------ 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7579ef1..c56cdaa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ matrix: - php: 7.2 - php: 7.3 - php: 7.4 + - php: 8.0 cache: directories: diff --git a/composer.json b/composer.json index 8f4bc29..47f3129 100644 --- a/composer.json +++ b/composer.json @@ -21,11 +21,11 @@ } }, "require": { - "php": "^7.1.3", + "php": "^7.1.3 || ^8.0", "florianv/exchanger": "^2.0" }, "require-dev": { - "phpunit/phpunit": "^7.5", + "phpunit/phpunit": "^7 || ^8 || ^9", "php-http/mock-client": "^1.0", "php-http/message": "^1.7", "nyholm/psr7": "^1.0" diff --git a/tests/BuilderTest.php b/tests/BuilderTest.php index 766b677..5c7cf79 100644 --- a/tests/BuilderTest.php +++ b/tests/BuilderTest.php @@ -28,7 +28,7 @@ class BuilderTest extends TestCase */ private $builder; - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -56,12 +56,12 @@ public function testBuildMultipleServicesAdded() $this->assertInstanceOf(Swap::class, $this->builder->build()); } - /** - * @expectedException \LogicException - * @expectedExceptionMessage Client must be an instance of Http\Client\HttpClient or Psr\Http\Client\ClientInterface - */ public function testUseInvalidClient() { + $this->expectException(\LogicException::class); + $expectedExceptionMessage = 'Client must be an instance of Http\Client\HttpClient or Psr\Http\Client\ClientInterface'; + $this->expectExceptionMessage($expectedExceptionMessage); + $builder = new Builder(); $builder->useHttpClient(new \stdClass()); } diff --git a/tests/Service/FactoryTest.php b/tests/Service/FactoryTest.php index 4756df9..11711f1 100644 --- a/tests/Service/FactoryTest.php +++ b/tests/Service/FactoryTest.php @@ -28,6 +28,7 @@ use Exchanger\Service\Xignite; use Exchanger\Service\RussianCentralBank; use Exchanger\Service\XchangeApi; +use Http\Discovery\NotFoundException; use Http\Mock\Client; use PHPUnit\Framework\TestCase; use Swap\Service\Factory; @@ -87,30 +88,30 @@ public function testCustomServices() $this->assertSame($service, $factory->create('baz')); } - /** - * @expectedException \LogicException - * @expectedExceptionMessage Client must be an instance of Http\Client\HttpClient or Psr\Http\Client\ClientInterface - */ public function testConstructInvalidClient() { + $this->expectException(\LogicException::class); + $expectedExceptionMessage = 'Client must be an instance of Http\Client\HttpClient or Psr\Http\Client\ClientInterface'; + $this->expectExceptionMessage($expectedExceptionMessage); + $factory = new Factory(new \stdClass()); } - /** - * @expectedException \Http\Discovery\NotFoundException - * @expectedExceptionMessage No HTTPlug clients found. Make sure to install a package providing "php-http/client-implementation" - */ public function testWithNullAsClient() { + $this->expectException(NotFoundException::class); + $expectedExceptionMessage = 'No HTTPlug clients found. Make sure to install a package providing "php-http/client-implementation"'; + $this->expectExceptionMessage($expectedExceptionMessage); + $factory = new Factory(); } - /** - * @expectedException \LogicException - * @expectedExceptionMessage Client must be an instance of Http\Client\HttpClient or Psr\Http\Client\ClientInterface - */ public function testSetInvalidClient() { + $this->expectException(\LogicException::class); + $expectedExceptionMessage = 'Client must be an instance of Http\Client\HttpClient or Psr\Http\Client\ClientInterface'; + $this->expectExceptionMessage($expectedExceptionMessage); + $factory = new Factory(new Client()); $factory->setHttpClient(new \stdClass()); } From d760c2ed8dff02fbefb968ae5b6ecc2433905d42 Mon Sep 17 00:00:00 2001 From: Piotr Horzycki Date: Thu, 26 Nov 2020 12:20:42 +0100 Subject: [PATCH 2/2] Tiny style fix --- tests/Service/FactoryTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Service/FactoryTest.php b/tests/Service/FactoryTest.php index 11711f1..3112392 100644 --- a/tests/Service/FactoryTest.php +++ b/tests/Service/FactoryTest.php @@ -63,7 +63,7 @@ public function servicesProvider() ['xignite', Xignite::class, ['token' => 'token']], ['russian_central_bank', RussianCentralBank::class], ['cryptonator', Cryptonator::class], - ['xchangeapi', XchangeApi::class, ['api-key' => 'api-key']] + ['xchangeapi', XchangeApi::class, ['api-key' => 'api-key']], ]; }