reactphp / socket

Async, streaming plaintext TCP/IP and secure TLS socket server and client connections for ReactPHP.
https://reactphp.org/socket/
MIT License
1.2k stars 156 forks source link

PHPUnit - Test Loop and Event on ConnectionInterface :: Dummy question #234

Closed gravataLonga closed 3 years ago

gravataLonga commented 4 years ago

Hello i have a really dumb quesiton, i'm trying to test some application that use reactphp/socket over TCP connection it's half-duplex communication..

Who i can simulate the event loop and test the on event, like on('data',, etc..

p.s.: I don't want to use mock, i think that mocking isn't a good case for me, or at least i think using "real" colaborator is better.

clue commented 3 years ago

@gravataLonga Good question!

There are multiple ways to test socket connections. On a lower level, you may want to (partially) mock the ConnectionInterface to test event handlers for unit testing. On a higher level, you may want to create actual socket connections and transmit data for some integration tests. On the highest level, you may want to run your actual network service in a CI environment and run actual commands against this service for some integration and/or acceptance tests.

There's really no right or wrong here, it all depends on what you're trying to build specifically. As a starting point, I would always recommend taking a look at existing implementations with high test coverage, e.g. https://github.com/clue/reactphp-redis/tree/main/tests or https://github.com/friends-of-reactphp/mysql/tree/master/tests.

I hope this helps :+1:

I believe this has been answered, so I'm closing this for now. Please come back with more details if this problem persists and we can always reopen this :+1:

gravataLonga commented 3 years ago

@clue let me search more about that links, thanks for reply! :)