Skip to main content


Showing posts from August, 2011

Quality Assurance on PHP projects - PHPUnit part 3

Time for the third part on unit testing with phpunit in my Quality Assurance on PHP projects series. In part one we started writing unit tests for a simple game of tic-tac-toe. In part two we started converting our unit tests into actual code and moved our general unit test code for grids into a Grid focussed unit test. In this part, we're looking at how we can optimize the tests for our players.

When we look at our initial tests for players, we only focussed on two things: each player has a symbol and players are managed within a collection class.
public function testGamePlayersAreSetAtStart() { $players = $this->_ttt->getPlayers(); $this->assertInstanceOf('Players', $players); $this->assertEquals(2, count($players)); $this->assertEquals(Player::PLAYER_X, $players->seek(0)->current()->getSymbol()); $this->assertEquals(Player::PLAYER_O, $players->seek(1)->current()->getSymbol()); }…

Quality Assurance on PHP projects - PHPUnit part 2

I hope everyone enjoyed my first article on unit testing with phpunit where I started writing a few tests that would guide us building our little game of tictactoe. Today I'm going start with turning these tests into working code and adjusting our tests to have a clear separation of responsibility. Since we already know what the code should produce, we only have to work out the details.

Our tests tell us we have four classes:
Tictactoe: the main class that is responsible for the game and how it should be playedGrid: is the class that's responsible for setting up the playing gridPlayers: a collection class containing both player objectsPlayer: the class defining a single player Our first test concerns all about the grid we're going to use. Here's the test again:
public function testGameGridIsSetAtStart() { $grid = $this->_ttt->getGrid(); $this->assertInstanceOf('Grid', $grid); …

Quality Assurance on PHP projects - PHPUnit part 1

Of all tools available for improving quality assurance, there's one tool that is the core tool you have to master: PHPUnit. PHPUnit is a complete testing framework crafted by Sebastian Bergmann (@s_bergmann), who ported existing xUnit frameworks to PHP. And with this testing framework you're able to test your functionality in an automated way before you push code into production.

[editorial] As I cannot summarize the whole usage of phpunit in one blogpost, this will be a sequence of several articles that will pick up a specific task you want to cover with phpunit.

Installation Well, first of all you need to have PHPUnit installed on your system. The easiest way to accomplish this is to use the PEAR installer.
user@server: $ pear channel-discover user@server: $ pear channel-discover user@server: $ pear channel-discover
Once you've got the right channels, you can install the framework:
user@server: $ pear install phpunit/PHPU…

Quality Assurance on PHP projects - PHPDocumentor feedback

First of all, thank you all for the enormous feedback I got on my latest article on documentation of code. I got a lot of comments on the usage of PHPDocumentor for the following reasons:
the project seems to be no longer maintainedit's not ready for php 5.3it uses too much resources when using it on big projectsI have to agree that these reasons are valid enough to step away from PHPDocumentor as a tool for documentation purposes and look for a better alternative. So I've investigated one tool most people have commented on or tweet-ed/facebook-ed/g+-ed on: DocBlox.
Before I start a flamewar, I'm all for investigating more tools as time permits me, but these are my first impressions on the tool that had the most buzz in my personal social zone. If your tool of preference is not listed here, write an article on it and put the link here in the comments (or ping back to this article in your own post).
DocBlox seems to be the youngest project of all the various projects suggested…