utopia-php / tests
Lite & fast micro PHP test framework that is **easy to use**.
Installs: 207
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/utopia-php/tests
Requires
- php: >=8.3
Requires (Dev)
- laravel/pint: 1.25.*
- phpstan/phpstan: 2.0.*
- phpunit/phpunit: 12.4.*
This package is auto-updated.
Last update: 2025-12-16 06:17:37 UTC
README
A lightweight PHP testing library that provides useful testing utilities and extensions for PHPUnit.
Installation
composer require utopia-php/tests
Requirements
- PHP 8.3 or later
- PHPUnit 12.4 or later
Features
Async Extension
The Async trait provides utilities for testing asynchronous or eventually consistent behavior.
assertEventually()
Repeatedly executes a callable until it succeeds or times out. This is useful for testing:
- Asynchronous operations
- Eventually consistent systems
- Polling-based workflows
- Background jobs
Usage:
use PHPUnit\Framework\TestCase; use Utopia\Tests\Extensions\Async; class MyTest extends TestCase { use Async; public function testAsyncOperation(): void { $result = null; // Start some async operation $this->startAsyncJob(function ($data) use (&$result) { $result = $data; }); // Wait until the result is set (max 10 seconds, check every 500ms) self::assertEventually(function () use (&$result) { $this->assertNotNull($result); $this->assertSame('expected', $result); }, timeoutMs: 10000, waitMs: 500); } }
Parameters:
callable $probe- The function to execute repeatedly. Should contain assertions.int $timeoutMs- Maximum time to wait in milliseconds (default: 10000)int $waitMs- Time to wait between attempts in milliseconds (default: 500)
Critical Exceptions:
If you need to immediately fail the test without retrying, throw a Critical exception:
use Utopia\Tests\Extensions\Async\Exceptions\Critical; self::assertEventually(function () use ($connection) { if ($connection->isClosed()) { throw new Critical('Connection closed unexpectedly'); } $this->assertTrue($connection->hasData()); });
Development
Run Tests
composer install --ignore-platform-reqs
composer test
Code Formatting
composer format
Static Analysis
composer check
Linting
composer lint
License
MIT License. See LICENSE for more information.