Frage

I have an abstract PHP class that is responsible for doing process forks and also detaching the current process from terminal and continue as deamon.

I really would like to get tips about how to unit test this class (PHPUnit). Let's say implement a minimal socket server in the test based on this abstract and communicating with that? Any better ideas?

The class can be seen here: https://github.com/tcz/PHPTracker/blob/master/lib/PHPTracker/Threading/Forker.php

Thank you!

War es hilfreich?

Lösung

There are two things that need to be tested here:

  1. If forking works
  2. The rest of the code

Testing if the fork worked can be done by saving the ID of the forked process somewhere and see if it's still running, and the rest of the class can be tested as usual without forking.

Andere Tipps

As gphilip said, you can use runkit to mock pcntl_fork() and test all branches of code. Here's an example: http://kpayne.me/2012/01/17/how-to-unit-test-fork/

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top