News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Kurt Payne's Blog:
How to Unit Test pcntl_fork()
January 19, 2012 @ 13:40:20

Kurt Payne has a new post to his blog showing how you can unit test your process forking in your PHP application (pcntl).

At some point, many php developers turn to the pcntl functions in php to write a daemon, or server, or simulate threading. But how do you unit test this with complete code coverage? [...] We need to engage some black arts php extensions to make this happen. An installation guide follows, and the post ends with a complete listing of the unit test.

He uses the test_helpers extension (as provided by Sebastian Bergmann) and Runkit to allow the test to define new methods copying the current pcntl methods and mocks up the responses. Tests are included to check the parent of a process, checking the children of a process and testing that a fork could be made. Hes's even included visual proof of this working.

0 comments voice your opinion now!
unittest pcntl pcntlfork testhelper runkit mock


blog comments powered by Disqus

Similar Posts

Wojciech Sznapka's Blog: Why Mockery is better than PHPUnit Mock Builder (with Symfony2)

NetTuts.com: Refactoring Legacy Code: Part 9 - Analyzing Concerns

Sameer Borate's Blog: Test dependencies in PHPUnit 3.4

Sebastian Bergmann's Blog: Copy & Paste Detection in PHPUnit 3.2

Federico Cargnelutti: TDD: Checking the return value of a Stub


Community Events





Don't see your event here?
Let us know!


list testing refactor install interview developer community release framework unittest code introduction language wordpress opinion threedevsandamaybe api podcast series laravel

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework