diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..02521fd --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,48 @@ +name: CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + test: + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + php: ['8.2', '8.3', '8.4'] + dependencies: ['lowest', 'highest'] + + name: PHP ${{ matrix.php }} - ${{ matrix.dependencies }} + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: mbstring + + - name: Cache Composer packages + uses: actions/cache@v3 + with: + path: vendor + key: ${{ runner.os }}-php-${{ matrix.php }}-${{ matrix.dependencies }}-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php-${{ matrix.php }}-${{ matrix.dependencies }}- + + - name: Install dependencies (highest) + if: matrix.dependencies == 'highest' + run: composer update --no-interaction --no-progress + + - name: Install dependencies (lowest) + if: matrix.dependencies == 'lowest' + run: composer update --prefer-lowest --no-interaction --no-progress + + - name: Run test suite + run: vendor/bin/phpunit diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 8d09dec..0000000 --- a/.travis.yml +++ /dev/null @@ -1,29 +0,0 @@ -language: php - -php: - - 7.0 - - 7.1 - - 7.2 - - 7.3 - - 7.4 - - 8.0 - -env: - global: - - XDEBUG_MODE=coverage - matrix: - - COMPOSER_FLAGS="--prefer-lowest" - - COMPOSER_FLAGS="" - -cache: - directories: - - $HOME/.composer/cache - -before_script: - - travis_retry composer update ${COMPOSER_FLAGS} --no-interaction - -script: - - vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover - -after_script: - - php vendor/bin/php-coveralls -v -x coverage.clover -o coveralls-upload.json diff --git a/README.md b/README.md index 64d46ee..a33c7f8 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ # RingPHP Guzzle Handler [![Latest Version on Packagist](https://img.shields.io/packagist/v/lukewaite/ringphp-guzzle-handler.svg?style=flat-square)](https://packagist.org/packages/lukewaite/ringphp-guzzle-handler) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) -[![Build Status](https://img.shields.io/travis/lukewaite/ringphp-guzzle-handler/master.svg?style=flat-square)](https://travis-ci.org/lukewaite/ringphp-guzzle-handler) -[![Coveralls](https://img.shields.io/coveralls/github/lukewaite/ringphp-guzzle-handler/master.svg?style=flat-square)](https://coveralls.io/github/lukewaite/ringphp-guzzle-handler) [![Total Downloads](https://img.shields.io/packagist/dt/lukewaite/ringphp-guzzle-handler.svg?style=flat-square)](https://packagist.org/packages/lukewaite/ringphp-guzzle-handler) ## Usage diff --git a/composer.json b/composer.json index c79e269..2189215 100644 --- a/composer.json +++ b/composer.json @@ -8,13 +8,13 @@ } ], "require": { - "php": ">=7.0", + "php": "^8.2|^8.3|^8.4", "guzzlehttp/ringphp": "^1.1", - "guzzlehttp/guzzle": "^6.2", - "guzzlehttp/psr7": "^1.4" + "guzzlehttp/guzzle": "^7.0", + "guzzlehttp/psr7": "^2.0" }, "require-dev": { - "phpunit/phpunit": "^5.7.11||^6.0||^7.0||^8.0", + "phpunit/phpunit": "^9.0|^10.0|^11.0", "php-coveralls/php-coveralls": "^2.1" }, "autoload": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 0ab862f..b6e0582 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,5 +1,7 @@ - + + + src/ + + tests - - - src/ - - - - - - - + + diff --git a/tests/GuzzleHandlerTest.php b/tests/GuzzleHandlerTest.php index 9fdff12..af67aee 100644 --- a/tests/GuzzleHandlerTest.php +++ b/tests/GuzzleHandlerTest.php @@ -18,14 +18,17 @@ public function it_makes_a_request() { $response = new Response(200, ['Content-Type' => ['application/json']], 'testResponseBody'); - $client = $this->prophesize(Client::class); - $client->requestAsync('POST', 'https://example.com/', [ - 'body' => 'testBody', - 'headers' => ['host'=>['example.com']], - 'http_errors' => false - ])->willReturn(new FulfilledPromise($response)); - - $handler = new GuzzleHandler($client->reveal()); + $client = $this->createMock(Client::class); + $client->expects($this->once()) + ->method('requestAsync') + ->with('POST', 'https://example.com/', [ + 'body' => 'testBody', + 'headers' => ['host'=>['example.com']], + 'http_errors' => false + ]) + ->willReturn(new FulfilledPromise($response)); + + $handler = new GuzzleHandler($client); $response = $handler([ 'http_method' => 'POST', 'scheme' => 'https', @@ -43,15 +46,18 @@ public function it_makes_requests_with_authentication() { $response = new Response(200, ['Content-Type' => ['application/json']], 'testResponseBody'); - $client = $this->prophesize(Client::class); - $client->requestAsync('POST', 'https://example.com/', [ - 'body' => 'testBody', - 'headers' => ['host' => ['example.com']], - 'http_errors' => false, - 'auth' => ['user', 'password'] - ])->willReturn(new FulfilledPromise($response)); - - $handler = new GuzzleHandler($client->reveal()); + $client = $this->createMock(Client::class); + $client->expects($this->once()) + ->method('requestAsync') + ->with('POST', 'https://example.com/', [ + 'body' => 'testBody', + 'headers' => ['host' => ['example.com']], + 'http_errors' => false, + 'auth' => ['user', 'password'] + ]) + ->willReturn(new FulfilledPromise($response)); + + $handler = new GuzzleHandler($client); $response = $handler([ 'http_method' => 'POST', 'scheme' => 'https', @@ -87,7 +93,7 @@ public function it_should_format_transfer_stats_that_elasticsearch_needs($respon { $stats = $response['transfer_stats']; $this->assertEquals('https://example.com/', $stats['url']); - $this->assertInternalType('float', $stats['total_time']); + $this->assertIsFloat($stats['total_time']); $this->assertEquals('application/json', $stats['content_type']); $this->assertEquals('200', $stats['http_code']); } @@ -97,14 +103,17 @@ public function it_should_catch_guzzle_exceptions_and_pass_as_an_error() { $exception = new TransferException('Test Exception'); - $client = $this->prophesize(Client::class); - $client->requestAsync('POST', 'https://example.com/', [ - 'body' => 'testBody', - 'headers' => ['host' => ['example.com']], - 'http_errors' => false, - ])->willReturn(new RejectedPromise($exception)); - - $handler = new GuzzleHandler($client->reveal()); + $client = $this->createMock(Client::class); + $client->expects($this->once()) + ->method('requestAsync') + ->with('POST', 'https://example.com/', [ + 'body' => 'testBody', + 'headers' => ['host' => ['example.com']], + 'http_errors' => false, + ]) + ->willReturn(new RejectedPromise($exception)); + + $handler = new GuzzleHandler($client); $response = $handler([ 'http_method' => 'POST', 'scheme' => 'https',