I have found this very nice suggestion to simulate a socket in PHP unit tests by creating a Socket stub: How do I unit test socket code with PHPUnit?
However, it is not clear to me how I should use this class. If I instantiate it:
$stub = new ListeningServerStub();
$stub->listen();
nothing will happen afterwards, because socket_accept blocks until it receives data. I thought about running listen() in a separate thread, but then multi-threading is not so easy in PHP. So what is a simple solution here?
Aucun commentaire:
Enregistrer un commentaire