SlideShare a Scribd company logo
1 of 21
Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org PHPUnit Automated Unit Testing Framework June 5, 2008
Dave Ross “ I grew up around computers, fell in love with the Internet way back in 1994, and built a successful career around my interests in computers and business. My career focus has been on e-commerce, and in my personal time I study issues related to digital identity, trust, and reputation tracking. I’m also an small business owner, an avid Scrabble player, and a b-movie junkie.” 9 years professional development experience PHP developer, certified Java developer LinkedIn profile: http://www.linkedin.com/pub/2/832/9b0 Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org
The West Suburban Chicago PHP Meetup ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org
[object Object],[object Object],Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org
[object Object],[object Object],[object Object],[object Object],Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org
[object Object],[object Object],[object Object],[object Object],[object Object],Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org
Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Make it  easy  to test, and you'll do it more often. If you use version control, test before every check-in
Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org You can wrap a set of tests into a  test suite A suite tests larger units of your application, even the application itself
Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org PHP itself is tested using automated tests They use a framework called  phpt
The PHPUnit Pocket Guide Tells you everything you need to know when writing PHPUnit test cases Buy the book, or read the HTML version at: http://www.phpunit.de/pocket_guide/index.en.php Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org
Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Let's look at a test case!
Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org <?php require_once 'PHPUnit/Framework.php'; class ArrayTest extends PHPUnit_Framework_TestCase { protected $fixture; protected function setUp() { // Create the Array fixture. $this->fixture = array(); } public function testNewArrayIsEmpty() { // Assert that the size of the Array fixture is 0. $this->assertEquals(0, sizeof($this->fixture)); } public function testArrayContainsAnElement() { // Add an element to the Array fixture. $this->fixture[] = 'Element'; // Assert that the size of the Array fixture is 1. $this->assertEquals(1, sizeof($this->fixture)); } } ?>
Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Tests should be run against a known, fixed state called a  fixture setUp() creates this state tearDown() destroys the state and puts things back the way they were
Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Test cases are implemented as functions whose names start with the word “ test ” This example has: testNewArrayIsEmpty() testArrayContainsAnElement()
Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Run  a PHPUnit test case with the  phpunit  command phpunit UnitTest UnitTest.php tells PHPUnit to look for a class UnitTest in the UnitTest.php file (filename is optional)
Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org phpunit ArrayTest PHPUnit 3.3.0 by Sebastian Bergmann. .. Time: 0 seconds OK (2 tests)
Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Can output test logs to a variety of  formats : GraphViz JSON TAP XML
Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Test suite + Exported results allows for Continuous Integration
Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Continuous integration is a way to automatically run your test suite regularly Once a day... Once an hour... Every time someone checks in code...
Official PHPUnit page: http://www.phpunit.de/ PHPUnit Pocket Guide: http://www.phpunit.de/pocket_guide Effective Unit Testing: http://www.acm.org/ubiquity/views/t_burns_1.html For More Information Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org
Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org

More Related Content

What's hot

Behaviour Testing and Continuous Integration with Drupal
Behaviour Testing and Continuous Integration with DrupalBehaviour Testing and Continuous Integration with Drupal
Behaviour Testing and Continuous Integration with Drupal
smithmilner
 

What's hot (20)

Unit testing plugins: The 5 W's and an H
Unit testing plugins: The 5 W's and an HUnit testing plugins: The 5 W's and an H
Unit testing plugins: The 5 W's and an H
 
Phing
PhingPhing
Phing
 
Mocking in python
Mocking in pythonMocking in python
Mocking in python
 
TDD for joomla extensions
TDD for joomla extensionsTDD for joomla extensions
TDD for joomla extensions
 
Php test fest
Php test festPhp test fest
Php test fest
 
Webdevcon pierrejoye-php54-and-other
Webdevcon pierrejoye-php54-and-otherWebdevcon pierrejoye-php54-and-other
Webdevcon pierrejoye-php54-and-other
 
Is your python application secure? - PyCon Canada - 2015-11-07
Is your python application secure? - PyCon Canada - 2015-11-07Is your python application secure? - PyCon Canada - 2015-11-07
Is your python application secure? - PyCon Canada - 2015-11-07
 
PHPNW Test Fest Pre-presentation
PHPNW Test Fest Pre-presentationPHPNW Test Fest Pre-presentation
PHPNW Test Fest Pre-presentation
 
Behaviour Testing and Continuous Integration with Drupal
Behaviour Testing and Continuous Integration with DrupalBehaviour Testing and Continuous Integration with Drupal
Behaviour Testing and Continuous Integration with Drupal
 
Php 7 evolution
Php 7 evolutionPhp 7 evolution
Php 7 evolution
 
Build a chatroom!
Build a chatroom!Build a chatroom!
Build a chatroom!
 
Joomla! JavaScript Testing
Joomla! JavaScript TestingJoomla! JavaScript Testing
Joomla! JavaScript Testing
 
STAMP, or Test Amplification to DevTestOps service, OW2con'18, June 7-8, 2018...
STAMP, or Test Amplification to DevTestOps service, OW2con'18, June 7-8, 2018...STAMP, or Test Amplification to DevTestOps service, OW2con'18, June 7-8, 2018...
STAMP, or Test Amplification to DevTestOps service, OW2con'18, June 7-8, 2018...
 
PyCon Canada 2015 - Is your python application secure
PyCon Canada 2015 - Is your python application securePyCon Canada 2015 - Is your python application secure
PyCon Canada 2015 - Is your python application secure
 
IPC 2013 - High Performance PHP with HipHop
IPC 2013 - High Performance PHP with HipHopIPC 2013 - High Performance PHP with HipHop
IPC 2013 - High Performance PHP with HipHop
 
Debugging Your Plone Site
Debugging Your Plone SiteDebugging Your Plone Site
Debugging Your Plone Site
 
Git hooks For PHP Developers
Git hooks For PHP DevelopersGit hooks For PHP Developers
Git hooks For PHP Developers
 
AntiVirus Evasion Reconstructed - Veil 3.0
AntiVirus Evasion Reconstructed - Veil 3.0AntiVirus Evasion Reconstructed - Veil 3.0
AntiVirus Evasion Reconstructed - Veil 3.0
 
Static analysis for beginners
Static analysis for beginnersStatic analysis for beginners
Static analysis for beginners
 
Introduction to TYPO3 Neos - mUXcamp Worms 2014
Introduction to TYPO3 Neos -  mUXcamp Worms 2014Introduction to TYPO3 Neos -  mUXcamp Worms 2014
Introduction to TYPO3 Neos - mUXcamp Worms 2014
 

Similar to PHPUnit Automated Unit Testing Framework

Passing The Joel Test In The PHP World
Passing The Joel Test In The PHP WorldPassing The Joel Test In The PHP World
Passing The Joel Test In The PHP World
Lorna Mitchell
 
Behavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWestBehavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWest
Joshua Warren
 
Intro to PHP Testing
Intro to PHP TestingIntro to PHP Testing
Intro to PHP Testing
Ran Mizrahi
 
2013 - Dustin whittle - Escalando PHP en la vida real
2013 - Dustin whittle - Escalando PHP en la vida real2013 - Dustin whittle - Escalando PHP en la vida real
2013 - Dustin whittle - Escalando PHP en la vida real
PHP Conference Argentina
 

Similar to PHPUnit Automated Unit Testing Framework (20)

Fighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnitFighting Fear-Driven-Development With PHPUnit
Fighting Fear-Driven-Development With PHPUnit
 
Simplify your professional web development with symfony
Simplify your professional web development with symfonySimplify your professional web development with symfony
Simplify your professional web development with symfony
 
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit SoftwaretestsEffizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
 
Automated Unit Testing
Automated Unit TestingAutomated Unit Testing
Automated Unit Testing
 
Leveling Up With Unit Testing - LonghornPHP 2022
Leveling Up With Unit Testing - LonghornPHP 2022Leveling Up With Unit Testing - LonghornPHP 2022
Leveling Up With Unit Testing - LonghornPHP 2022
 
Passing The Joel Test In The PHP World
Passing The Joel Test In The PHP WorldPassing The Joel Test In The PHP World
Passing The Joel Test In The PHP World
 
Automatic testing and quality assurance for WordPress plugins and themes
Automatic testing and quality assurance for WordPress plugins and themesAutomatic testing and quality assurance for WordPress plugins and themes
Automatic testing and quality assurance for WordPress plugins and themes
 
Behavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWestBehavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWest
 
PHPUnit best practices presentation
PHPUnit best practices presentationPHPUnit best practices presentation
PHPUnit best practices presentation
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12
 
Intro to PHP Testing
Intro to PHP TestingIntro to PHP Testing
Intro to PHP Testing
 
BDD with Behat and Symfony2
BDD with Behat and Symfony2BDD with Behat and Symfony2
BDD with Behat and Symfony2
 
Continuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CIContinuous Delivery - Automate & Build Better Software with Travis CI
Continuous Delivery - Automate & Build Better Software with Travis CI
 
Current state-of-php
Current state-of-phpCurrent state-of-php
Current state-of-php
 
Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScript
 
2013 - Dustin whittle - Escalando PHP en la vida real
2013 - Dustin whittle - Escalando PHP en la vida real2013 - Dustin whittle - Escalando PHP en la vida real
2013 - Dustin whittle - Escalando PHP en la vida real
 
Prepare for PHP Test Fest 2009
Prepare for PHP Test Fest 2009Prepare for PHP Test Fest 2009
Prepare for PHP Test Fest 2009
 
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
 
Php unit (eng)
Php unit (eng)Php unit (eng)
Php unit (eng)
 
Your code are my tests
Your code are my testsYour code are my tests
Your code are my tests
 

More from Dave Ross

Stylesheets of the future with Sass and Compass
Stylesheets of the future with Sass and CompassStylesheets of the future with Sass and Compass
Stylesheets of the future with Sass and Compass
Dave Ross
 
Date and Time programming in PHP & Javascript
Date and Time programming in PHP & JavascriptDate and Time programming in PHP & Javascript
Date and Time programming in PHP & Javascript
Dave Ross
 
Web App Security: XSS and CSRF
Web App Security: XSS and CSRFWeb App Security: XSS and CSRF
Web App Security: XSS and CSRF
Dave Ross
 
The Mobile Web: A developer's perspective
The Mobile Web: A developer's perspectiveThe Mobile Web: A developer's perspective
The Mobile Web: A developer's perspective
Dave Ross
 
Balsamiq Mockups
Balsamiq MockupsBalsamiq Mockups
Balsamiq Mockups
Dave Ross
 
LAMP Optimization
LAMP OptimizationLAMP Optimization
LAMP Optimization
Dave Ross
 
Lint - PHP & Javascript Code Checking
Lint - PHP & Javascript Code CheckingLint - PHP & Javascript Code Checking
Lint - PHP & Javascript Code Checking
Dave Ross
 
Cufon - Javascript Font Replacement
Cufon - Javascript Font ReplacementCufon - Javascript Font Replacement
Cufon - Javascript Font Replacement
Dave Ross
 

More from Dave Ross (20)

Stylesheets of the future with Sass and Compass
Stylesheets of the future with Sass and CompassStylesheets of the future with Sass and Compass
Stylesheets of the future with Sass and Compass
 
HTML5 History & Features
HTML5 History & FeaturesHTML5 History & Features
HTML5 History & Features
 
A geek's guide to getting hired
A geek's guide to getting hiredA geek's guide to getting hired
A geek's guide to getting hired
 
NoSQL & MongoDB
NoSQL & MongoDBNoSQL & MongoDB
NoSQL & MongoDB
 
Date and Time programming in PHP & Javascript
Date and Time programming in PHP & JavascriptDate and Time programming in PHP & Javascript
Date and Time programming in PHP & Javascript
 
Simulated Eye Tracking with Attention Wizard
Simulated Eye Tracking with Attention WizardSimulated Eye Tracking with Attention Wizard
Simulated Eye Tracking with Attention Wizard
 
What's new in HTML5?
What's new in HTML5?What's new in HTML5?
What's new in HTML5?
 
The Canvas Tag
The Canvas TagThe Canvas Tag
The Canvas Tag
 
Wordpress
WordpressWordpress
Wordpress
 
Lamp Stack Optimization
Lamp Stack OptimizationLamp Stack Optimization
Lamp Stack Optimization
 
The FPDF Library
The FPDF LibraryThe FPDF Library
The FPDF Library
 
FirePHP
FirePHPFirePHP
FirePHP
 
Bayesian Inference using b8
Bayesian Inference using b8Bayesian Inference using b8
Bayesian Inference using b8
 
SQL Injection in PHP
SQL Injection in PHPSQL Injection in PHP
SQL Injection in PHP
 
Web App Security: XSS and CSRF
Web App Security: XSS and CSRFWeb App Security: XSS and CSRF
Web App Security: XSS and CSRF
 
The Mobile Web: A developer's perspective
The Mobile Web: A developer's perspectiveThe Mobile Web: A developer's perspective
The Mobile Web: A developer's perspective
 
Balsamiq Mockups
Balsamiq MockupsBalsamiq Mockups
Balsamiq Mockups
 
LAMP Optimization
LAMP OptimizationLAMP Optimization
LAMP Optimization
 
Lint - PHP & Javascript Code Checking
Lint - PHP & Javascript Code CheckingLint - PHP & Javascript Code Checking
Lint - PHP & Javascript Code Checking
 
Cufon - Javascript Font Replacement
Cufon - Javascript Font ReplacementCufon - Javascript Font Replacement
Cufon - Javascript Font Replacement
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 

PHPUnit Automated Unit Testing Framework

  • 1. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org PHPUnit Automated Unit Testing Framework June 5, 2008
  • 2. Dave Ross “ I grew up around computers, fell in love with the Internet way back in 1994, and built a successful career around my interests in computers and business. My career focus has been on e-commerce, and in my personal time I study issues related to digital identity, trust, and reputation tracking. I’m also an small business owner, an avid Scrabble player, and a b-movie junkie.” 9 years professional development experience PHP developer, certified Java developer LinkedIn profile: http://www.linkedin.com/pub/2/832/9b0 Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org
  • 3.
  • 4.
  • 5.
  • 6.
  • 7. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Make it easy to test, and you'll do it more often. If you use version control, test before every check-in
  • 8. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org You can wrap a set of tests into a test suite A suite tests larger units of your application, even the application itself
  • 9. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org PHP itself is tested using automated tests They use a framework called phpt
  • 10. The PHPUnit Pocket Guide Tells you everything you need to know when writing PHPUnit test cases Buy the book, or read the HTML version at: http://www.phpunit.de/pocket_guide/index.en.php Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org
  • 11. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Let's look at a test case!
  • 12. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org <?php require_once 'PHPUnit/Framework.php'; class ArrayTest extends PHPUnit_Framework_TestCase { protected $fixture; protected function setUp() { // Create the Array fixture. $this->fixture = array(); } public function testNewArrayIsEmpty() { // Assert that the size of the Array fixture is 0. $this->assertEquals(0, sizeof($this->fixture)); } public function testArrayContainsAnElement() { // Add an element to the Array fixture. $this->fixture[] = 'Element'; // Assert that the size of the Array fixture is 1. $this->assertEquals(1, sizeof($this->fixture)); } } ?>
  • 13. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Tests should be run against a known, fixed state called a fixture setUp() creates this state tearDown() destroys the state and puts things back the way they were
  • 14. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Test cases are implemented as functions whose names start with the word “ test ” This example has: testNewArrayIsEmpty() testArrayContainsAnElement()
  • 15. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Run a PHPUnit test case with the phpunit command phpunit UnitTest UnitTest.php tells PHPUnit to look for a class UnitTest in the UnitTest.php file (filename is optional)
  • 16. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org phpunit ArrayTest PHPUnit 3.3.0 by Sebastian Bergmann. .. Time: 0 seconds OK (2 tests)
  • 17. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Can output test logs to a variety of formats : GraphViz JSON TAP XML
  • 18. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Test suite + Exported results allows for Continuous Integration
  • 19. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org Continuous integration is a way to automatically run your test suite regularly Once a day... Once an hour... Every time someone checks in code...
  • 20. Official PHPUnit page: http://www.phpunit.de/ PHPUnit Pocket Guide: http://www.phpunit.de/pocket_guide Effective Unit Testing: http://www.acm.org/ubiquity/views/t_burns_1.html For More Information Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org
  • 21. Dave Ross | West Suburban Chicago PHP Meetup | suburbanchicagophp.org