Skip to content

jsgriffin/PHPUnit-Example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Unit Testing Example

Intro

This is a small application which shows some of the features of PHPUnit and some of the benefits of Unit Testing. It tests a simple file which extracts articles from an RSS feed. There are three versions of this importer which can be tested, showing a progression of code and how the unit tests benefit that progression.

  • importer.php This is a first-pass at the import script, which works as a finite-state machine. It's quite complex, but passes all the unit tests.
  • importer_2.php This is a refactoring of the import script which uses SimplePie to parse the RSS feed rather than doing it by hand, thus improving the readability of the code.
  • importer_3.php This fixes some of the bugs that appeared during the refactoring of the original import script, thus completing the refactoring process.

Usage

Running normally

Running the index.php script will run the importer and output the articles extracted.

$ php index.php

You can alter which importer version is used by editing index.php and changing the file include at the top of the file.

Running the unit tests

Make sure you have PHPUnit installed. Follow the instructions on PHPUnit.de. On OS X, I've found that the tutorial on Frodo's Ghost is very helpful.

When PHPUnit is installed, change into the test cases directory:

$ cd tests/cases

And then run:

$ phpunit ImporterTest

This will run the test suite for the importer.

About

A unit testing example using PHP Unit

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages