wyrihaximus/async-test-utilities
Async test utilities for PHP/React tests. Extend AsyncTestCase to run each test inside a Fiber, get random namespaces/directories for filesystem tests, and control per-test or per-class timeouts via the TimeOut attribute (default 30s).
Starting this major release when adding running composer install/update with this package, and wyrihaximus/makefiles in your require-dev. The following bit in composer.json:
"scripts": {
"post-install-cmd": [
"composer normalize",
"composer update --lock --no-scripts"
],
"post-update-cmd": [
"composer normalize",
"composer update --lock --no-scripts"
]
}
Will be replaced with:
"scripts": {
"post-install-cmd": [
"composer normalize",
"make on-install-or-update || true"
],
"post-update-cmd": [
"composer normalize",
"make on-install-or-update || true"
]
}
If neither of those scripts blocks are found, they will be created and make on-install-or-update || true will be put in each of those.
AFAIK I'm the only one using this package, plus the orgs I use it in. Adding this here to make sure that other that use it are aware of this impactful change.
:tada: Promise v3 :tada:
This release drops all deprecated await methods. Use the await and other related functions directly.
Major new feature in this release:
Since all tests are executed inside a fiber, there is a default timeout of 30 seconds. To lower or raise that timeout
this package comes with a TimeOut attribute. It can be set on the class and method level. When set on both the method level it takes priority over the class level.
<?php
declare(strict_types=1);
namespace WyriHaximus\Tests\AsyncTestUtilities;
use ReactventLoop\Loop;
use WyriHaximus\AsyncTestUtilities\AsyncTestCase;
use WyriHaximus\AsyncTestUtilities\TimeOut;
use function React\Asyncsync;
use function React\Asyncwait;
use function React\Promise
esolve;
use function React\Promise\Timer\sleep;
use function time;
#[TimeOut(0.3)]
final class AsyncTestCaseTest extends AsyncTestCase
{
#[TimeOut(1)]
public function testAllTestsAreRanInAFiber(): void
{
self::expectOutputString('ab');
Loop::futureTick(async(static function (): void {
echo 'a';
}));
await(sleep(1));
echo 'b';
}
public function testExpectCallableExactly(): void
{
$callable = $this->expectCallableExactly(3);
Loop::futureTick($callable);
Loop::futureTick($callable);
Loop::futureTick($callable);
}
public function testExpectCallableOnce(): void
{
Loop::futureTick($this->expectCallableOnce());
}
}
How can I help you explore Laravel packages today?