Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
PHP
public function connect($socket){
    if(($acceptSocket = socket_accept($socket)) < 0){
          //exception
    }

   $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.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900