Skip to Main Content
Learning PHP, MySQL, and JavaScript
book

Learning PHP, MySQL, and JavaScript

by Robin Nixon
July 2009
Beginner content levelBeginner
526 pages
14h 24m
English
O'Reilly Media, Inc.
Content preview from Learning PHP, MySQL, and JavaScript

Unit Testing with PHPUnit

Now that you are familiar with object-oriented programming, it’s a good idea to get a taste of unit testing. This is a method of code testing that verifies whether individual units of source code are working correctly.

Unit testing provides the following benefits:

  • It allows for automation of the testing process.

  • It reduces the difficulty of discovering errors within more complex code.

  • Testing is often enhanced because attention is given to each unit.

Install PHPUnit with the PEAR installer. To do this, go to a Command or Terminal prompt, ensure that you have Administrator or Superuser privileges, and issue the two lines of code in Table E-3, according to your operating system. (On Windows systems, ignore and close any pop-up “Invalid configuration directive” alerts that may appear.)

Table E-3. Commands for Installing PHPUnit on different systems

System

Instructions to type from an Administrator Command prompt or a Terminal window

XP/Vista

(4 instructions)

cd \Program Files\EasyPHP 3.0\php

pear channel-discover pear.phpunit.de

pear install phpunit/PHPUnit

Xcopy /E pear\*.* includes

Mac OS X

(3 instructions)

cd /Applications/MAMP/bin

pear channel-discover pear.phpunit.de

pear install phpunit/PHPUnit

Linux/Unix

(2 instructions)

pear channel-discover pear.phpunit.de

pear install phpunit/PHPUnit

The two main commands register the PEAR channel on your system, download PHPUnit, and install it. On Windows, you need the additional XCOPY command to resolve a file and path bug ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Web Database Applications with PHP and MySQL, 2nd Edition

Web Database Applications with PHP and MySQL, 2nd Edition

Hugh E. Williams, David Lane
Learning PHP

Learning PHP

David Sklar

Publisher Resources

ISBN: 9780596803605Supplemental ContentErrata Page