I'm creating multi-thread fully scalable PHP socket server library, but what I do not know is how to cover this library with unit test's.
Let's say we have class called Server with methods:
-> create
-> connect
-> disconnect
-> start
-> stop
-> restart
Method create is simple testable, we testing if the method have been called and if there is no exception.
Method connect contain this code
public function connect($socket){
if(($acceptSocket = socket_accept($socket)) < 0){
}
$this->sockets[] = $socket;
}
Issue is when you call socket_accept, PHP will get stuck here until new connection will come to this socket. So in this case I cannot test if it was accepted becaseu unit test will not continue here but just het stop.
Same with method run where is infinite loop.
How then I'm suppose to do tests ?
What I have tried:
I've tried to find response regarding to this issue but haven't been that lucky to found one, workig one.