views:

5

answers:

1

I'm trying to test the result of a background shell process (ran with exec()). For this, I need the PHPUnit assertion to wait until the process ends.

I was wondering what is the best way to do this? Should I place the check for the running process in a loop, and use sleep() with a very small parameter to wait until it's finished?

A: 

Since no one answered for a day i'm going to take a shot:

The first impulsive Answer would be: "You shouldn't do that". It doesn't really match with the goals of Unittesting (e.g. it's not really fast to run that test).

If you're writing a Test for a Class that calls that Script your not really testing one thing but two. The Class that calls the command line Script and that Script it's self and you could mock out the shell part.

If you're just trying to make sure that exec works my first idea would be to build your Test in a way that doesn't spawn that shell process as a background Task but as a Foreground Task and eliminating the need for some "wait" workaround.

Hope that helped a litte

edorian