PHPUnit Essentials

Get started with PHPUnit and learn how to write and test codes using advanced technologies

PHPUnit Essentials

Starting
Zdenek Machek

Get started with PHPUnit and learn how to write and test codes using advanced technologies
$26.99
$44.99
RRP $26.99
RRP $44.99
eBook
Print + eBook
$12.99 p/month

Want this title & more? Subscribe to PacktLib

Enjoy full and instant access to over 2000 books and videos – you’ll find everything you need to stay ahead of the curve and make sure you can always get the job done.
+ Collection
Free Sample

Book Details

ISBN 139781783283439
Paperback314 pages

About This Book

  • Learn how to install PHPUnit as well as how to write and execute tests
  • Understand the advanced concepts of testing using test doubles and the continuous integration process
  • A hands-on, step-by-step guide full of real-life examples to help you learn quickly and effectively

Who This Book Is For

This book is a practical guide featuring a step-by-step approach that aims to help PHP developers who want to learn or improve their software testing skills. It also takes you through many real-life examples encountered by PHP developers to help you avoid common pitfalls.

Table of Contents

Chapter 1: Installing PHPUnit
Requirements
Composer – the dependency manager for PHP
Installing PEAR
Other installation methods
Testing the installation
Summary
Chapter 2: PHPUnit Support in IDEs
IDEs and PHPUnit
Summary
Chapter 3: Tests and What They're All About
Understanding unit testing
Anatomy of a PHPUnit test
The MVC application architecture and tests
Summary
Chapter 4: Testing Dependencies and Exceptions
Detecting dependencies
Handling dependencies
Exceptions are expected
Summary
Chapter 5: Running Tests from the Command Line
Running tests
Summary
Chapter 6: Test Isolation and Interaction
Test fixtures
Global state
Test dependencies
Data providers
Summary
Chapter 7: Organizing Tests
The PHPUnit XML configuration file
Where to store tests
Using the bootstrap file
Summary
Chapter 8: Using Test Doubles
Creating test doubles
Test doubles in action
Understanding Mockery
Summary
Chapter 9: Database Testing
Which database to use
Tests for a database
DBUnit
Doctrine 2 ORM and database testing
Summary
Chapter 10: Testing APIs
An example of integration testing
Testing the PayPal API
Testing the Facebook API
Testing the Twitter API
Testing the service-oriented architecture
Summary
Chapter 11: Testing Legacy Code
Testing spaghetti code
Handling dependencies
Summary
Chapter 12: Functional Tests in the Web Browser Using Selenium
Installing Selenium
Testing in the browser
Writing Selenium tests
PHP-SeleniumClient
Organizing Selenium tests
Summary
Chapter 13: Continuous Integration
Using a Travis CI hosted service
Using the Jenkins CI server
Using the Xinc PHP CI server
Summary
Chapter 14: PHPUnit Alternatives, Extensions, Relatives, and BDD
Unit testing alternatives
PHPUnit extensions
Behavior-driven development
Summary

What You Will Learn

  • How to install PHPUnit and confi gure IDEs for PHPUnit support
  • What are unit tests and why to test code
  • Write test doubles and learn how to replace dependencies
  • Explore how to test legacy code
  • Test code calling APIs and connecting to the database
  • Run functional tests in a web browser using Selenium tests
  • Use tests as part of the continuous integration process
  • Discover the alternatives to PHPUnit
  • Use PHPUnit tests in the Jenkins and Travis CI servers

In Detail

The ability to write unit tests and software testing have become skills that every PHP developer should master.

This book is a practical guide to PHPUnit and unit testing, covering all aspects of writing PHPUnit tests and using them. The book shows why testable code is better code and how to write good tests with the help of simple and easy-to-understand examples.

With this book, you will learn how to write, organize, and execute effective tests. Step-by-step techniques of how to write testable code, how to refactor the code, and how to run your tests are shown. You will also learn about advanced testing techniques, including how to test databases, APIs, and legacy code. PHPUnit Essentials is a guide for PHP developers who want to learn or improve their software testing skills. It is a book for developers who begin with testing but is also a good source of information for developers who are already familiar with PHPUnit.

Authors

Table of Contents

Chapter 1: Installing PHPUnit
Requirements
Composer – the dependency manager for PHP
Installing PEAR
Other installation methods
Testing the installation
Summary
Chapter 2: PHPUnit Support in IDEs
IDEs and PHPUnit
Summary
Chapter 3: Tests and What They're All About
Understanding unit testing
Anatomy of a PHPUnit test
The MVC application architecture and tests
Summary
Chapter 4: Testing Dependencies and Exceptions
Detecting dependencies
Handling dependencies
Exceptions are expected
Summary
Chapter 5: Running Tests from the Command Line
Running tests
Summary
Chapter 6: Test Isolation and Interaction
Test fixtures
Global state
Test dependencies
Data providers
Summary
Chapter 7: Organizing Tests
The PHPUnit XML configuration file
Where to store tests
Using the bootstrap file
Summary
Chapter 8: Using Test Doubles
Creating test doubles
Test doubles in action
Understanding Mockery
Summary
Chapter 9: Database Testing
Which database to use
Tests for a database
DBUnit
Doctrine 2 ORM and database testing
Summary
Chapter 10: Testing APIs
An example of integration testing
Testing the PayPal API
Testing the Facebook API
Testing the Twitter API
Testing the service-oriented architecture
Summary
Chapter 11: Testing Legacy Code
Testing spaghetti code
Handling dependencies
Summary
Chapter 12: Functional Tests in the Web Browser Using Selenium
Installing Selenium
Testing in the browser
Writing Selenium tests
PHP-SeleniumClient
Organizing Selenium tests
Summary
Chapter 13: Continuous Integration
Using a Travis CI hosted service
Using the Jenkins CI server
Using the Xinc PHP CI server
Summary
Chapter 14: PHPUnit Alternatives, Extensions, Relatives, and BDD
Unit testing alternatives
PHPUnit extensions
Behavior-driven development
Summary

Book Details

ISBN 139781783283439
Paperback314 pages
Read More