D
D
Dmitry Smolyakov2018-07-10 10:13:18
PHP
Dmitry Smolyakov, 2018-07-10 10:13:18

How to write tests for ReactPHP?

I'm trying to make tests for a server written in ReactPHP
Here is the code of the method that raises the server

public function createServer($uri = '127.0.0.1:5555'): LoopInterface
    {
        $loop = Factory::create();
        $server = new Server($uri, $loop);

        $connectionPool = new ConnectionPool();

        $server->on('connection', function (ConnectionInterface $connection) use (&$connectionPool) {
            $connectionPool->add($connection);
        });

        $loop->run();

        return $loop;
    }

In the test I raise it
public function testConnection(): void
    {
        $this->serverLoop = $this->createServer();
    }

Unfortunately the test stops with the letter E

PHPUnit 7.2.6 by Sebastian Bergmann and contributors.
Runtime: PHP 7.2.3 with Xdebug 2.6.0
Configuration: /Users/PhpstormProjects/ReactPHPChat/phpunit.xml
E

I understand that the server is blocking the unit test, how can I organize the tests?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hOtRush, 2018-07-10
@spudro

Writing tests for react is hard and painful. It's worth taking a look at the developer tests for ideas https://github.com/reactphp/http/tree/master/tests

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question