amphp / phpunit-util
Helper package to ease testing with PHPUnit.
Fund package maintenance!
amphp
Installs: 37 872
Dependents: 100
Suggesters: 0
Security: 0
Stars: 14
Watchers: 5
Forks: 5
Open Issues: 3
Requires
- php: >=7.1
- phpunit/phpunit: ^6 | ^7 | ^8 | ^9
Requires (Dev)
- amphp/amp: ^2
- amphp/php-cs-fixer-config: dev-master
This package is auto-updated.
Last update: 2021-01-12 18:36:26 UTC
README
amphp/phpunit-util
is a small helper package to ease testing with PHPUnit in combination with the Amp
concurrency framework.
Required PHP Version
- PHP 7.0+
Installation
composer require --dev amphp/phpunit-util
Usage
<?php namespace Foo; use Amp\ByteStream; use Amp\PHPUnit\AsyncTestCase; use Amp\Socket; class BarTest extends AsyncTestCase { // Each test case is executed as a coroutine and checked to run to completion public function test() { $socket = yield Socket\connect('tcp://localhost:12345'); yield $socket->write('foobar'); $this->assertSame('foobar', yield ByteStream\buffer($socket)); } }
Deprecated Functionality
This package also provides a PHPUnit TestListener
to reset the global event loop after each test, but this is deprecated.
<phpunit> <!-- ... --> <!-- DEPRECATED, use AsyncTestCase instead --> <listeners> <!-- DEPRECATED, use AsyncTestCase instead --> <listener class="Amp\PHPUnit\LoopReset" /> </listeners> <!-- ... --> </phpunit>