Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
29 changes: 0 additions & 29 deletions .travis.yml

This file was deleted.

2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
21 changes: 10 additions & 11 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
Expand All @@ -9,21 +11,18 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="RingPHP Guzzle Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<logging>
<log type="tap" target="build/report.tap"/>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<junit outputFile="build/report.junit.xml"/>
<testdoxText outputFile="build/report.tap"/>
</logging>
</phpunit>
61 changes: 35 additions & 26 deletions tests/GuzzleHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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']);
}
Expand All @@ -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',
Expand Down