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
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.yml]
indent_size = 2
61 changes: 18 additions & 43 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,22 @@
name: build
on:
pull_request:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'

on: [push, pull_request]
push:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'

env:
DEFAULT_COMPOSER_FLAGS: "--prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi"
name: build

jobs:
phpunit:
name: PHP ${{ matrix.php }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
php: ['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1']

steps:
- name: Checkout
uses: actions/checkout@v2
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache composer dependencies
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install dependencies
run: composer update $DEFAULT_COMPOSER_FLAGS
- name: Run unit tests with coverage
run: vendor/bin/phpunit --verbose --coverage-clover=coverage.clover --colors=always
if: matrix.php == '7.1'
- name: Run unit tests without coverage
run: vendor/bin/phpunit --verbose --colors=always
if: matrix.php != '7.1'
- name: Upload code coverage
run: |
wget https://scrutinizer-ci.com/ocular.phar
php ocular.phar code-coverage:upload --format=php-clover coverage.clover
if: matrix.php == '7.1'
continue-on-error: true # if is fork
phpunit:
uses: yiisoft/actions/.github/workflows/phpunit.yml@master
37 changes: 10 additions & 27 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{
"name": "yiisoft/yii2-httpclient",
"description": "HTTP client extension for the Yii framework",
"keywords": ["yii2", "http", "httpclient", "curl"],
"keywords": [
"yii2",
"http",
"httpclient",
"curl"
],
"type": "yii2-extension",
"license": "BSD-3-Clause",
"support": {
Expand All @@ -17,42 +22,20 @@
"email": "klimov.paul@gmail.com"
}
],
"minimum-stability": "dev",
"require": {
"yiisoft/yii2": "~2.0.13",
"paragonie/random_compat": ">=1"
"php": ">=8.1",
"yiisoft/yii2": "22.0.x-dev"
},
"require-dev": {
"cweagans/composer-patches": "^1.7",
"phpunit/phpunit": "4.8.34"
"phpunit/phpunit": "^9.6"
},
"repositories": [
{
"type": "composer",
"url": "https://asset-packagist.org"
}
],
"config": {
"allow-plugins": {
"cweagans/composer-patches": true,
"yiisoft/yii2-composer": true
}
},
"autoload": {
"psr-4": { "yii\\httpclient\\": "src" }
},
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
},
"composer-exit-on-patch-failure": true,
"patches": {
"phpunit/phpunit-mock-objects": {
"Fix PHP 7 and 8 compatibility": "https://yiisoft.github.io/phpunit-patches/phpunit_mock_objects.patch"
},
"phpunit/phpunit": {
"Fix PHP 7 compatibility": "https://yiisoft.github.io/phpunit-patches/phpunit_php7.patch",
"Fix PHP 8 compatibility": "https://yiisoft.github.io/phpunit-patches/phpunit_php8.patch"
}
}
}
}
40 changes: 20 additions & 20 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit bootstrap="./tests/bootstrap.php"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false">
<testsuites>
<testsuite name="Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
<exclude>
<directory suffix=".php">./src/debug</directory>
</exclude>
</whitelist>
</filter>
<phpunit
bootstrap="./tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
>
<testsuites>
<testsuite name="Yii2-HttpClient">
<directory>./tests</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
</phpunit>
22 changes: 11 additions & 11 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use yii\base\Component;
use Yii;
use yii\base\InvalidParamException;
use yii\base\InvalidArgumentException;
use yii\helpers\StringHelper;

/**
Expand Down Expand Up @@ -124,7 +124,7 @@ public function getTransport()
* Returns HTTP message formatter instance for the specified format.
* @param string $format format name.
* @return FormatterInterface formatter instance.
* @throws InvalidParamException on invalid format name.
* @throws InvalidArgumentException on invalid format name.
* @throws \yii\base\InvalidConfigException
*/
public function getFormatter($format)
Expand All @@ -145,7 +145,7 @@ public function getFormatter($format)

if (!isset($this->formatters[$format])) {
if (!isset($defaultFormatters[$format])) {
throw new InvalidParamException("Unrecognized format '{$format}'");
throw new InvalidArgumentException("Unrecognized format '{$format}'");
}
$this->formatters[$format] = $defaultFormatters[$format];
}
Expand All @@ -161,7 +161,7 @@ public function getFormatter($format)
* Returns HTTP message parser instance for the specified format.
* @param string $format format name
* @return ParserInterface parser instance.
* @throws InvalidParamException on invalid format name.
* @throws InvalidArgumentException on invalid format name.
* @throws \yii\base\InvalidConfigException
*/
public function getParser($format)
Expand All @@ -175,7 +175,7 @@ public function getParser($format)

if (!isset($this->parsers[$format])) {
if (!isset($defaultParsers[$format])) {
throw new InvalidParamException("Unrecognized format '{$format}'");
throw new InvalidArgumentException("Unrecognized format '{$format}'");
}
$this->parsers[$format] = $defaultParsers[$format];
}
Expand Down Expand Up @@ -203,7 +203,7 @@ public function createRequest()

/**
* Creates a response instance.
* @param string $content raw content
* @param string|null $content raw content
* @param array $headers headers list.
* @return Response request instance.
* @throws \yii\base\InvalidConfigException
Expand Down Expand Up @@ -285,7 +285,7 @@ public function createRequestLogToken($method, $url, $headers, $content)
/**
* Creates 'GET' request.
* @param array|string $url target URL.
* @param array|string $data if array - request data, otherwise - request content.
* @param array|string|null $data if array - request data, otherwise - request content.
* @param array $headers request headers.
* @param array $options request options.
* @return Request request instance.
Expand All @@ -298,7 +298,7 @@ public function get($url, $data = null, $headers = [], $options = [])
/**
* Creates 'POST' request.
* @param array|string $url target URL.
* @param array|string $data if array - request data, otherwise - request content.
* @param array|string|null $data if array - request data, otherwise - request content.
* @param array $headers request headers.
* @param array $options request options.
* @return Request request instance.
Expand All @@ -311,7 +311,7 @@ public function post($url, $data = null, $headers = [], $options = [])
/**
* Creates 'PUT' request.
* @param array|string $url target URL.
* @param array|string $data if array - request data, otherwise - request content.
* @param array|string|null $data if array - request data, otherwise - request content.
* @param array $headers request headers.
* @param array $options request options.
* @return Request request instance.
Expand All @@ -324,7 +324,7 @@ public function put($url, $data = null, $headers = [], $options = [])
/**
* Creates 'PATCH' request.
* @param array|string $url target URL.
* @param array|string $data if array - request data, otherwise - request content.
* @param array|string|null $data if array - request data, otherwise - request content.
* @param array $headers request headers.
* @param array $options request options.
* @return Request request instance.
Expand All @@ -337,7 +337,7 @@ public function patch($url, $data = null, $headers = [], $options = [])
/**
* Creates 'DELETE' request.
* @param array|string $url target URL.
* @param array|string $data if array - request data, otherwise - request content.
* @param array|string|null $data if array - request data, otherwise - request content.
* @param array $headers request headers.
* @param array $options request options.
* @return Request request instance.
Expand Down
6 changes: 3 additions & 3 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function testGetUnrecognizedFormatter()
{
$client = new Client();
$unrecognizedFormat = 'unrecognizedFormat';
$this->expectException('\yii\base\InvalidParamException');
$this->expectException('\yii\base\InvalidArgumentException');
$this->expectExceptionMessage("Unrecognized format '{$unrecognizedFormat}'");
$client->getFormatter($unrecognizedFormat);
}
Expand Down Expand Up @@ -108,7 +108,7 @@ public function testGetUnrecognizedParser()
{
$client = new Client();
$unrecognizedParser = 'unrecognizedParser';
$this->expectException('\yii\base\InvalidParamException');
$this->expectException('\yii\base\InvalidargumentException');
$this->expectExceptionMessage("Unrecognized format '{$unrecognizedParser}'");
$client->getParser($unrecognizedParser);
}
Expand Down Expand Up @@ -273,4 +273,4 @@ public function testRequestShortcutMethods()
$client->head($url, $headers, $options);
$client->options($url, $options);
}
}
}
4 changes: 2 additions & 2 deletions tests/CurlFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class CurlFormatterTest extends TestCase
{
protected function setUp()
protected function setUp(): void
{
$this->mockApplication();
}
Expand Down Expand Up @@ -52,7 +52,7 @@ public function testFormatMethodGet()
$formatter = new CurlFormatter();
$formatter->format($request);
$this->assertEmpty($request->getContent());
$this->assertContains(http_build_query($data), $request->getFullUrl());
$this->assertStringContainsString(http_build_query($data), $request->getFullUrl());
$this->assertFalse($request->getHeaders()->has('Content-Type'));
}

Expand Down
2 changes: 1 addition & 1 deletion tests/MockTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class MockTransportTest extends TestCase
*/
private $transport;

protected function setUp()
protected function setUp(): void
{
$this->transport = new MockTransport();
$this->client = new Client(['transport' => $this->transport]);
Expand Down
6 changes: 3 additions & 3 deletions tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class RequestTest extends TestCase
{
protected function setUp()
protected function setUp(): void
{
$this->mockApplication();
}
Expand Down Expand Up @@ -216,8 +216,8 @@ public function testToString()
$request->addFileContent('some-file', 'some content');

$result = $request->toString();
$this->assertContains('Content-Type: multipart/form-data; boundary=', $result);
$this->assertContains('some content', $result);
$this->assertStringContainsString('Content-Type: multipart/form-data; boundary=', $result);
$this->assertStringContainsString('some content', $result);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
* Clean up after test.
* By default the application created with [[mockApplication]] will be destroyed.
*/
protected function tearDown()
protected function tearDown(): void
{
parent::tearDown();
$this->destroyApplication();
Expand Down
Loading