Skip to content

Latest commit

 

History

History
47 lines (36 loc) · 1.29 KB

phpunit-util.md

File metadata and controls

47 lines (36 loc) · 1.29 KB
notice title description image permalink source layout
This file is imported and can be edited at https://github.com/amphp/phpunit-util/blob/3.x/README.md
Simplify PHPUnit Tests Involving Asynchronous Behavior
Learn how to write tests with PHPUnit while making use of timeouts and minimum runtimes.
undraw/undraw_qa_engineers.svg
/phpunit-util
docs

AMPHP is a collection of event-driven libraries for PHP designed with fibers and concurrency in mind. amphp/phpunit-util is a small helper package to ease testing with PHPUnit.

License

Installation

This package can be installed as a Composer dependency.

composer require --dev amphp/phpunit-util

The package requires PHP 8.1 or later.

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(): void
    {
        $socket = Socket\connect('tcp://localhost:12345');
        $socket->write('foobar');

        $this->assertSame('foobar', ByteStream\buffer($socket));
    }
}