Giter VIP home page Giter VIP logo

phpunit-example's Introduction

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.

phpunit-example's People

Contributors

jsgriffin avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.