 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
NetTuts.com: Testing your PHP Codebase with EnhancePHP
by Chris Cornutt January 23, 2012 @ 09:25:45
On NetTuts.com today a new tutorial has been posted to help you test your applications and make it a simpler process using the EnhancePHP framework. EnhancePHP is a lightweight Open Source PHP unit testing framework with support for mocks and stubs.
You know it; I know it. We should be testing our code more than we do. Part of the reason we don't, I think, is that we don't know exactly how. Well, I'm getting rid of that excuse today: I'm teaching you to test your PHP with the EnhancePHP framework.
He shows you how to download it, get it installed and creates a simple structure to do some TDD (Test-Driven Development) with it. His tests check three things - valid email addresses, username restrictions and phone number formatting. He also includes a look at creating mocks/stubs for a "scoreboard" example.
You can find out more about the EnhancePHP framework on its github page.
voice your opinion now!
unittest enhancephp framework tdd tutorial
DZone.com: PHPUnit_Selenium
by Chris Cornutt January 20, 2012 @ 09:12:18
On DZone.com today Giorgio Sironi has a quick tutorial showing you how to set up and use the PHPUnit_Selenium component in the latest releases of the popular testing software.
With the 1.2 release, PHPUnit_Selenium supports (basically) for the first time the Selenium 2 WebDriver API. While PHPUnit_Selenium already worked with Selenium 2, it did so only by using the Selenium 1 emulation included in the jar; now it provides an object-oriented API right natively supported in a base PHPUnit test case, shipped in PHPUnit's PEAR channel.
He includes the steps you'll need to pull it from the PEAR channel and how to set up a test case based on the PHPUnit_Extensions_Selenium2TestCase object. He gives a few examples of how to select various components on the page (via CSS selectors and XPath), assert that the right information is there and interact with forms.
voice your opinion now!
phpunit selenium install unittest tutorial example select interact
Kurt Payne's Blog: How to Unit Test pcntl_fork()
by Chris Cornutt 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.
voice your opinion now!
unittest pcntl pcntlfork testhelper runkit mock
Chris Hartjes' Blog: PHPUnit Aborted Fix
by Chris Cornutt January 19, 2012 @ 11:16:53
Chris Hartjes ran into an issue with hit unit tests where PHPUnit was throwing an "aborted" error no matter what tests were run. Thankfully, in this new post, he shares a solution.
That was a pretty annoying bug. I never did find out what the problem was as I moved onto other problems and chalked that error up to some undiagnosed weirdness on that particular server. From time to time I would get asked on Twitter if I had ever solved the problem. My answer was always "no, and if you do solve it please let met know how you fixed it." Today, my friends, was the day.
Based on a response from Demian Katz, he was able to get around the issue with flag set on the PHPUnit command line - "-dzend.enable_gc=0". Apparently the issue has to do with garbage collection and has been a known issue since the beginning of 2011.
voice your opinion now!
phpunit aborted unittest fix garbage collection bug
Brian Swan's Blog: Running PHPUnit in Windows Azure
by Chris Cornutt December 09, 2011 @ 10:08:47
Brian Swan has a recent post to his MSDN blog about setting up PHPUnit for testing on a Windows Azure platform (as installed via PEAR).
After figuring out how to run PHPUnit from the command line in a Windows Azure instance, I did find that a bit more configuration work than I anticipated was necessary. I'm not 100% certain that this is the best way to run PHPUnit in Windows Azure, but it is one way. I'd be interested in hearing better ways to do this.
He breaks it up into a few different steps:
- Building the application with your tests locally
- Package the application up for Azure deployment
- Enable RDP access on your Azure instance
- Find your PHP and PEAR install on your instance and, logged in via RDP, add their locations to your current path
- Edit the phpunit.bat file to point to the right PHP location
- Execute the tests!
For other options for testing Azure-based applications, see Brian's previous post.
voice your opinion now!
phpunit windows azure unittest rdp
VG Tech Blog: Mocking the File System Using PHPUnit and vfsStream
by Chris Cornutt December 09, 2011 @ 09:40:13
On the VG Tech blog today there's another post related to unit testing (here's one from before) but this time they're talking about mocking the filesystem with vfsStream, a powerful tool that lets you interact with PHP streams as a virtual file system.
This article is about how to mock the file system when writing unit tests, and it will be rather code-heavy. [...] PHPUnit is the de-facto standard for unit testing in PHP projects, and this is what we will be using together with vfsStream in this article.
The include the code for a simple storage driver (VGF_Storage_Driver_Filesystem) to use with vfsStream with "store", "delete" and "get" methods. Also included are examples of using vfsStream to check things like directory existence, if a file exists, or if a file can be read. A few simple assertions are set up in their sample test to check the methods in their "VGF_Storage_Driver_Filesystem" class.
voice your opinion now!
unittest phpunit vfsstream tutorial filesystem mock
|
Community Events
Don't see your event here? Let us know!
|