Skip to content

Commit

Permalink
Fix CI tests and add recent PHP versions to matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
ostrolucky committed Jun 14, 2024
1 parent 725165c commit af462df
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 18 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ jobs:
- "7.4"
- "8.0"
- "8.1"
- "8.2"
- "8.3"
dependencies:
- "lowest"
- "highest"

steps:
- name: "Checkout repository"
uses: "actions/checkout@v2"
uses: "actions/checkout@v4"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
Expand All @@ -63,10 +65,10 @@ jobs:
coverage: "none"

- name: "Install dependencies (Composer)"
uses: "ramsey/composer-install@v2"
uses: "ramsey/composer-install@v3"
with:
dependency-versions: "${{ matrix.dependencies }}"

- name: "Run unit tests (PHPUnit)"
shell: "bash"
run: "vendor/bin/simple-phpunit"
run: "vendor/bin/phpunit"
9 changes: 6 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
"require": {
"php": ">=7.4",
"php-http/client-common": ">=1.3",
"symfony/rate-limiter": ">=5.2"
"symfony/rate-limiter": ">=5.4"
},
"require-dev": {
"nyholm/psr7": "^1.0",
"php-http/mock-client": "*",
"ramsey/coding-standard": "^2.0",
"symfony/phpunit-bridge": ">=6.0"
"symfony/phpunit-bridge": ">=6.0",
"phpunit/phpunit": "^9.6",
"psr/http-factory": "^1.1"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand All @@ -42,7 +44,8 @@
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"ergebnis/composer-normalize": true
"ergebnis/composer-normalize": true,
"php-http/discovery": true
}
}
}
2 changes: 2 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
<arg value="sp"/>

<file>./src</file>
<file>./tests</file>

<rule ref="Ramsey">
<exclude name="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFallbackGlobalName"/>
<exclude name="SlevomatCodingStandard.TypeHints.DeclareStrictTypes.IncorrectWhitespaceBeforeDeclare"/>
</rule>

</ruleset>
18 changes: 11 additions & 7 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/bin/.phpunit/phpunit/phpunit.xsd"
bootstrap="./vendor/autoload.php"
colors="true"
verbose="true">

<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
colors="true"
bootstrap="./vendor/autoload.php"
>
<php>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0" />
</php>

<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
</listeners>

<testsuites>
<testsuite name="unit-tests">
<directory>./src</directory>
<directory>tests</directory>
</testsuite>
</testsuites>

Expand Down
2 changes: 1 addition & 1 deletion src/ThrottlePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct(LimiterInterface $rateLimiter, int $tokens = 1, ?flo
}

/**
* @throws MaxWaitDurationExceededException if $maxTime is set and the process needs to wait longer than its value (in seconds)
* @throws MaxWaitDurationExceededException if $maxTime is set and the process needs to wait longer than its value
* @throws ReserveNotSupportedException if this limiter implementation doesn't support reserving tokens
* @throws InvalidArgumentException if $tokens is larger than the maximum burst size
*/
Expand Down
10 changes: 6 additions & 4 deletions tests/ThrottlePluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Http\Client\Common\Plugin\ThrottlePlugin;
use Http\Client\Common\PluginClient;
use Http\Mock\Client;
use Nyholm\Psr7\Factory\HttplugFactory;
use Nyholm\Psr7\Factory\Psr17Factory;
use Nyholm\Psr7\Request;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ClockMock;
Expand All @@ -27,7 +27,7 @@ class ThrottlePluginTest extends TestCase
protected function setUp(): void
{
ClockMock::register(RateLimit::class);
$this->mockClient = new Client(new HttplugFactory());
$this->mockClient = new Client(new Psr17Factory());
$this->client = new PluginClient($this->mockClient, [
new ThrottlePlugin(
(new RateLimiterFactory(
Expand Down Expand Up @@ -83,7 +83,7 @@ public function testMaxTime(): void
{
$this->client = new PluginClient($this->mockClient, [
new ThrottlePlugin(
$rateLimit = (new RateLimiterFactory(
(new RateLimiterFactory(
['id' => 'foo', 'policy' => 'fixed_window', 'limit' => 2, 'interval' => '3 seconds'],
new InMemoryStorage(),
))->create(),
Expand All @@ -93,7 +93,9 @@ public function testMaxTime(): void
]);

$this->expectException(MaxWaitDurationExceededException::class);
$this->expectExceptionMessage('The rate limiter wait time ("3" seconds) is longer than the provided maximum time ("1" seconds).');
$this->expectExceptionMessage(
'The rate limiter wait time ("3" seconds) is longer than the provided maximum time ("1" seconds).',
);

$time = time();
$this->client->sendRequest(new Request('GET', ''));
Expand Down

0 comments on commit af462df

Please sign in to comment.