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
4 changes: 4 additions & 0 deletions .github/workflows/isolated-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ jobs:
extensions: dom, curl, libxml, mbstring, pcntl, fileinfo, intl
coverage: pcov

- name: Setup Redis
if: ${{ matrix.os != 'windows-latest' && matrix.package.name == 'kv-store' }}
uses: supercharge/[email protected]

- name: Install PHPUnit
run: composer global require phpunit/phpunit:^12.2.3

Expand Down
2 changes: 1 addition & 1 deletion packages/cryptography/tests/Encryption/EncryptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function test_time_protection(): void
$this->assertSame('important data', $encrypter->decrypt($encrypted));
$elapsed = microtime(true) - $start;

$this->assertEqualsToMoreOrLess(0.3, $elapsed, margin: 0.015);
$this->assertEqualsToMoreOrLess(0.3, $elapsed, margin: 0.020, windowsMargin: 0.025);
}

public function test_wrong_key(): void
Expand Down
6 changes: 5 additions & 1 deletion packages/cryptography/tests/HasMoreIntegerAssertions.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@

trait HasMoreIntegerAssertions
{
private function assertEqualsToMoreOrLess(int|float $expected, int|float $actual, int|float $margin): void
private function assertEqualsToMoreOrLess(int|float $expected, int|float $actual, int|float $margin, null|int|float $windowsMargin = null): void
{
if ($windowsMargin && PHP_OS_FAMILY === 'Windows') {
$margin = $windowsMargin;
}

try {
$this->assertGreaterThanOrEqual($expected - $margin, $actual);
$this->assertLessThanOrEqual($expected + $margin, $actual);
Expand Down
2 changes: 1 addition & 1 deletion packages/cryptography/tests/Signing/SignerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function test_time_protection(): void
$this->assertTrue($signer->verify($data, $signature));
$elapsed = microtime(true) - $start;

$this->assertEqualsToMoreOrLess(0.3, $elapsed, margin: 0.015);
$this->assertEqualsToMoreOrLess(0.3, $elapsed, margin: 0.015, windowsMargin: 0.025);
}

public function test_time_protection_with_mock_clock(): void
Expand Down
4 changes: 2 additions & 2 deletions packages/cryptography/tests/TimelockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function test_locks_for_duration(): void

$elapsed = microtime(true) - $start;

$this->assertEqualsToMoreOrLess(0.1, $elapsed, margin: 0.015);
$this->assertEqualsToMoreOrLess(0.1, $elapsed, margin: 0.015, windowsMargin: 0.025);
}

public function test_return_early(): void
Expand Down Expand Up @@ -63,7 +63,7 @@ public function test_throws_exception_after_delay(): void
);
} catch (\RuntimeException) {
$elapsed = microtime(true) - $start;
$this->assertEqualsToMoreOrLess(0.1, $elapsed, margin: 0.015);
$this->assertEqualsToMoreOrLess(0.1, $elapsed, margin: 0.015, windowsMargin: 0.025);
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/kv-store/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"require": {
"php": "^8.4",
"tempest/support": "dev-main",
"tempest/datetime": "dev-main",
"tempest/event-bus": "dev-main"
},
"require-dev": {
Expand Down
22 changes: 11 additions & 11 deletions packages/kv-store/tests/PhpRedisClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@

namespace Tempest\KeyValue\Tests;

use PHPUnit\Framework\Attributes\PostCondition;
use PHPUnit\Framework\Attributes\PreCondition;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use PHPUnit\Framework\TestCase;
use Tempest\KeyValue\Redis\Config\RedisConfig;
use Tempest\KeyValue\Redis\PhpRedisClient;
use Throwable;

#[RequiresPhpExtension('redis')]
final class PhpRedisClientTest extends TestCase
{
private PhpRedisClient $redis;

protected function setUp(): void
#[PreCondition]
protected function configure(): void
{
parent::setUp();

if (! extension_loaded('redis') || ! class_exists(\Redis::class)) {
$this->markTestSkipped('The `redis` extension is not loaded.');
}

$this->redis = new PhpRedisClient(
client: new \Redis(),
config: new RedisConfig(
Expand All @@ -29,18 +29,18 @@

try {
$this->redis->connect();
} catch (\Throwable) {
} catch (Throwable) {
$this->markTestSkipped('Could not connect to Redis.');
}
}

protected function tearDown(): void
#[PostCondition]
protected function cleanup(): void
{
try {
$this->redis->flush();
} finally {
parent::tearDown();
} catch (Throwable) {
}

Check warning on line 43 in packages/kv-store/tests/PhpRedisClientTest.php

View workflow job for this annotation

GitHub Actions / Run style check

best-practices/no-empty-catch-clause

Empty catch clause suppresses errors. Empty catch clauses hide exceptions and make debugging more difficult. Help: Add error handling or remove the catch clause.
}

public function test_basic(): void
Expand Down
17 changes: 9 additions & 8 deletions packages/kv-store/tests/PredisClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

namespace Tempest\KeyValue\Tests;

use PHPUnit\Framework\Attributes\PostCondition;
use PHPUnit\Framework\Attributes\PreCondition;
use PHPUnit\Framework\TestCase;
use Predis;
use Tempest\KeyValue\Redis\PhpRedisClient;
use Tempest\KeyValue\Redis\PredisClient;
use Throwable;

final class PredisClientTest extends TestCase
{
private PredisClient $redis;

protected function setUp(): void
#[PreCondition]
protected function configure(): void
{
parent::setUp();

if (! class_exists(Predis\Client::class)) {
$this->markTestSkipped('The `predis/predis` package is not installed.');
}
Expand All @@ -34,18 +35,18 @@

try {
$this->redis->connect();
} catch (\Throwable) {
} catch (Throwable) {
$this->markTestSkipped('Could not connect to Redis.');
}
}

protected function tearDown(): void
#[PostCondition]
protected function cleanup(): void
{
try {
$this->redis->flush();
} finally {
parent::tearDown();
} catch (Throwable) {
}

Check warning on line 49 in packages/kv-store/tests/PredisClientTest.php

View workflow job for this annotation

GitHub Actions / Run style check

best-practices/no-empty-catch-clause

Empty catch clause suppresses errors. Empty catch clauses hide exceptions and make debugging more difficult. Help: Add error handling or remove the catch clause.
}

public function test_basic(): void
Expand Down
16 changes: 10 additions & 6 deletions packages/support/tests/Filesystem/UnixFunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Tempest\Support\Tests\Filesystem;

use PHPUnit\Framework\Attributes\PostCondition;
use PHPUnit\Framework\Attributes\PreCondition;
use PHPUnit\Framework\Attributes\TestWith;
use PHPUnit\Framework\TestCase;
use Tempest\Support\Filesystem;
Expand All @@ -17,22 +19,24 @@ final class UnixFunctionsTest extends TestCase
{
private string $fixtures = __DIR__ . '/Fixtures';

protected function setUp(): void
#[PreCondition]
protected function configure(): void
{
parent::setUp();

if (PHP_OS_FAMILY === 'Windows') {
$this->markTestSkipped('Irrelevant on Windows.');
$this->markTestSkipped('This test is only for Unix-like systems.');
}

Filesystem\ensure_directory_empty($this->fixtures);

$this->assertTrue(is_dir($this->fixtures));
}

protected function tearDown(): void
#[PostCondition]
protected function cleanup(): void
{
parent::tearDown();
if (PHP_OS_FAMILY === 'Windows') {
return;
}

Filesystem\delete_directory($this->fixtures);

Expand Down
14 changes: 8 additions & 6 deletions tests/Integration/KeyValue/RedisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@

namespace Tests\Tempest\Integration\KeyValue;

use PHPUnit\Framework\Attributes\PostCondition;
use PHPUnit\Framework\Attributes\PreCondition;
use Tempest\KeyValue\Redis\Config\RedisConfig;
use Tempest\KeyValue\Redis\Redis;
use Tempest\KeyValue\Redis\RedisCommandExecuted;
use Tests\Tempest\Integration\FrameworkIntegrationTestCase;
use Throwable;

final class RedisTest extends FrameworkIntegrationTestCase
{
private Redis $redis;

protected function setUp(): void
#[PreCondition]
protected function configure(): void
{
parent::setUp();

$this->eventBus->preventEventHandling();

$this->container->config(new RedisConfig(
Expand All @@ -32,13 +34,13 @@
}
}

protected function tearDown(): void
#[PostCondition]
protected function cleanup(): void
{
try {
$this->redis->flush();
} finally {
parent::tearDown();
} catch (Throwable) {
}

Check warning on line 43 in tests/Integration/KeyValue/RedisTest.php

View workflow job for this annotation

GitHub Actions / Run style check

best-practices/no-empty-catch-clause

Empty catch clause suppresses errors. Empty catch clauses hide exceptions and make debugging more difficult. Help: Add error handling or remove the catch clause.
}

public function test_command_is_dispatched(): void
Expand Down
27 changes: 11 additions & 16 deletions tests/Integration/Mapper/PsrRequestToRequestMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,18 @@ public function test_files(): void

public function test_body_field_in_body(): void
{
$psrRequest = $this->http->makePsrRequest(
'/',
Method::POST,
body: [
'body' => 'text',
],
$request = new PsrRequestToGenericRequestMapper($this->encrypter)->map(
from: $this->http->makePsrRequest(
uri: '/',
body: [
'body' => 'text',
],
),
to: GenericRequest::class,
);

$mapper = new PsrRequestToGenericRequestMapper();

$request = $mapper->map($psrRequest, GenericRequest::class);

$this->assertSame(
[
'body' => 'text',
],
$request->body,
);
$this->assertSame([
'body' => 'text',
], $request->body);
}
}
Loading