wyrihaximus / react-phpunit-run-tests-in-fiber
Trait to run all tests in a fiber
Fund package maintenance!
WyriHaximus
Installs: 116 849
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 3
Language:Makefile
Requires
- php: ^8.2
- phpunit/phpunit: ^10.5
- react/async: ^4.2.0
- react/event-loop: ^1.5.0
- react/promise: ^3.1
Requires (Dev)
- react/promise-timer: ^1.10.0
- wyrihaximus/test-utilities: ^6.0
Conflicts
- phpunit/phpunit: <10
This package is auto-updated.
Last update: 2024-12-10 22:52:35 UTC
README
Install
To install via Composer, use the command below, it will automatically detect the latest version and bind it with ^
.
composer require wyrihaximus/react-phpunit-run-tests-in-fiber
Usage
<?php declare(strict_types=1); use PHPUnit\Framework\TestCase; use React\Promise\Promise; use WyriHaximus\React\PHPUnit\RunTestsInFibersTrait; use function React\Async\await; final class SomeTest extends TestCase { use RunTestsInFibersTrait; /** * @test */ public function happyFlow() { self::assertTrue(await(new Promise(static function (callable $resolve): void { $resolve(true); }))); } }
Timeouts
This package supports marking a test failed once a timeout has been reached. Note that this doesn't stop anything running in the fiber the rest runs in or cleans up the loop as we cannot kill the running fiber once it starts. An exception is thrown in the scope between the test and PHPUnit that handles running the test in a fiber. And this is out of control of the test.
<?php declare(strict_types=1); use PHPUnit\Framework\TestCase; use React\Promise\Promise; use WyriHaximus\React\PHPUnit\RunTestsInFibersTrait; use WyriHaximus\React\PHPUnit\TimeOut; use function React\Async\await; #[TimeOut(30)] final class SomeTest extends TestCase { use RunTestsInFibersTrait; /** * @test */ #[TimeOut(0.1)] public function happyFlow() { self::assertTrue(await(new Promise(static function (callable $resolve): void { $resolve(true); }))); } }
License
The MIT License (MIT)
Copyright (c) 2024 Cees-Jan Kiewiet
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.