Using PHPUnit with Eclipse PDT (PHP Development Tools)
Eclipse PHP Developer Tools (PDT) is a very capable and mature platform for developing PHP applications. For those that develop only in PHP, an integrated installation is available that includes the Eclipse platform and any dependencies. For developers that may already be using Eclipse for development in another language, PDT can be installed using Eclipse's software update facility.
The one feature that PDT lacks is integration with PHPUnit. This can be a real hindrance for teams using Test Driven Development, and discourages everyone from frequently running their unit test suite while developing.
Luckily, the Eclipse platform has a mechanism for adding external tools to a project, and makes it very easy to call these tools once they are configured. In this post, I'll outline the steps I took to add PHPUnit support to my installation of PDT.
This post assumes that you have already installed Eclipse, and have a local development environment for PHP and PHPUnit. Jonathan Tran has a handy tutorial on installing PHPUnit on a Windows machine that I found very helpful.
In my PHP projects, I keep my unit tests in a directory called /tests. To start, select any unit test file - I chose AllTests.php, which executes a test suite containing all my unit tests for the project. Once the file is selected, select the menu item Run->External Tools->External Tools Configurations... That brings up a dialog box similar to this.
Select the Program configuration category, and click on the first icon - New Launch Configuration. Name your new configuration PHPUnit.
The location field should contain the full path to your phpunit shell script. On windows, this will be called phpunit.bat. On my computer, the correct location is c:\pear\phpunit.bat; however, this will vary by system.
The Working Directory should be set to the base location of your unit test files. In my case, this is the fully qualified \tests path.
For the Arguments list, you should have one entry - ${resource_name}. This tells Eclipse to pass the name of the currently highlighted unit test to phpunit.bat. To add this, click on the Variables... button and find resource_name in the displayed list.
The remainder of the tabs can be left with their default values. Your finished configuration should look like this:
Press Apply to save your changes. You can now press the Run button to execute PHPUnit immediately, or press Close to exit this dialog box.
After the first time you run PHPUnit using the External Tools Configurations dialog box, your PHPUnit configuration will be associated with the Run External Tools icon on you Eclipse workspace - this is the green Play Button icon decorated with a little red toolbox. To execute any unit test script as you develop, simply select the script in the PHP Explorer and press the Run External Tools icon.
Writing a last.fm plug-in for Wordpress – Part Three: The Plug-In
This is the third and final post describing how to write a plug-in to last.fm for Wordpress. In the first post, we looked at the last.fm API. In the second post, we took this information and made a PHP application to create a weekly Album Chart using the API. In this post, we use the PHP appication as the basis for a Wordpress plugin.
Writing a last.fm plug-in for Wordpress – Part Two: The PHP Application
This is the second post in a three part series on writing last.fm plug-in for Wordpress. In the first part of this series, we explored the last.fm API and wrote some simple PHP scripts to demonstrate two of the last.fm API methods. In this post, we'll create a complete PHP application that creates the last.api widget. This application will be generic enough to use in any web page. In the third post in this series, we'll convert the generic application into a Wordpress plug-in.
Before getting started, we should decide what we want to the widget to look like, and what information it should display. Since we'll be pulling in the weekly Album Chart, it makes sense for our widget to display the top five albums that the user has listened to over the past week - that is, the first five entries in the Album Chart. Once we have the list, we'll pull in additional information about each album. This will allow us to display a little thumbnail image of the album's CD cover if one is available.
Writing a last.fm plug-in for Wordpress – Part One: The last.fm API
last.fm is an online music listening and recommendation service that began life as a University project by one of it's cofounders, Richard Jones. In addition to generating custom online "radio stations", users can create a profile that keeps track of the music they listen to. This process is called scrobbling and is used as a baseline for generating recommendations and custom playlists. To keep the data flowing, last.fm provides an easy-to-use API based on passing XML over HTTP.
This post is the first in a series of three exploring this API, and showing how the API can used to create a Wordpress plug-in for displaying information from your last.fm profile on your blog. In this first post, we'll take a look at the last.fm API, and create some simple PHP scripts to test out the API. In the second post, we'll turn our simple scripts into a complete PHP application. In the third post, we'll create a Wordpress plug-in that leverages our PHP application to display our last.fm data on a blog.


