mercredi 28 octobre 2020

I can't figure out how to PHPUnit test Ratchet/Sockets

Let me first confess that I absolutely am a novice in the field of TDD and unit tests. Currently, I am learning to work with TDD to advance myself in my career.

I am reprogramming a program I wrote a year ago using TDD. The program is not that complex. It listens to a socket (Ratchet), receives information, parses the information, and sends messages through a message bus (RabbitMQ).

I am trying to approach this via TDD so I am starting to write my test first.

My listener class has 4 methods.

  • Connect (connects to the stream via Ratchet)
  • Listen (starts listening)
  • Parse (parses received information)
  • SendMessage (send a message to the RabbitMQ bus)

The problems I encounter while writing the test first.

  • How can I mock a Ratchet connection and assert that my function can "connect"
  • How can I assert that the information received matches my expectations

I find it really hard to find information on this specific subject and I understand that my question is broad. I do not expect a complete solution or answer but hopefully, the terminology to further investigate this subject and lectures/tutorials about writing tests for methods of this kind.

Aucun commentaire:

Enregistrer un commentaire