Introduction to Testing with PHPUnit
4.3 (129 ratings)
Instead of using a simple lifetime average, Udemy calculates a course's star rating by considering a number of different factors such as the number of ratings, the age of ratings, and the likelihood of fraudulent ratings.
642 students enrolled
Wishlisted Wishlist

Please confirm that you want to add Introduction to Testing with PHPUnit to your Wishlist.

Add to Wishlist

Introduction to Testing with PHPUnit

An introduction to testing your code with PHPUnit
Bestselling
4.3 (129 ratings)
Instead of using a simple lifetime average, Udemy calculates a course's star rating by considering a number of different factors such as the number of ratings, the age of ratings, and the likelihood of fraudulent ratings.
642 students enrolled
Created by Trevor Sawler
Last updated 1/2016
English
Current price: $10 Original price: $20 Discount: 50% off
5 hours left at this price!
30-Day Money-Back Guarantee
Includes:
  • 5 hours on-demand video
  • 3 Supplemental Resources
  • Full lifetime access
  • Access on mobile and TV
  • Certificate of Completion
What Will I Learn?
  • Write unit, integration, and functional tests in PHP
  • Generate code coverage reports
  • Learn how to refactor code to make it more testable (and better!)
  • Understand how to mock classes/objects, and why that's a good thing
  • Learn how to stub classes, methods and variables
  • Test controllers, models, views, and classes
  • Simulate visitors to your site from within PHPUnit
  • Test the functionality of every public facing page in your site
  • Write tests suites that strive for 100% code coverage
View Curriculum
Requirements
  • You should have at least a basic knowledge of PHP
  • You should have at least a basic understanding of Object Oriented programming principles
Description

Writing tests for modern PHP code can be intimidating for those who have never done so before, and this course is intended to remove the mystery from writing tests. We'll explore how to write tests for every part of your code -- from models, to views, to controllers, and every single line of code in your application. We'll start with very simple tests, and gradually move into more complex strategies. Initially, we will write unit tests, where we test our code at a granular level. Next we move into integration testing, we we ensure that each piece of our code interacts with other components properly. Then we look at functional testing, where we automate the process of testing the end-user's experience.

The course is structured so that all students download the same codebase, and we go through the entire process from start to finish. The source code is available on a GitHub repository, and is tagged so that you have ready access to the source code as it exists for a particular lecture.

Who is the target audience?
  • This course is intended for people with some knowledge of PHP, but little or no experience writing tests
  • This course is an introduction to writing test suites. If you are looking for advanced test writing techniques, this course is probably not for you.
Students Who Viewed This Course Also Viewed
Curriculum For This Course
33 Lectures
04:50:00
+
Why Testing is Critical to Good Development
1 Lecture 06:19

What testing is, the different kinds of testing, and what we are going to cover

Preview 06:19
+
Setting up our project files
5 Lectures 42:21

A good Integrated Development Environment, or IDE, will make your life every so much easier. I'm going to use PHPStorm, but you don't have to buy it -- Atom will work just fine.

Choosing an IDE - Atom, or your choice
00:52

When we test, it is helpful to have our testing environment mirror our production environment. Vagrant & Virtualbox make this possible.

Preview 10:47

When we test, it is helpful to have our testing environment mirror our production environment. Vagrant & Virtualbox make this possible, and GitBash gives Windows users access to the same LInux commands I use in this course.
Installing Vagrant, Virtualbox and GitBash for Windows
14:45

Download the source code for this course. Note that it has deliberate bugs, and I know this! We need something for our tests to find...

Getting our sample code up and running
07:20

Let's run through the sample code, and find out how we can get the code that I write in the lectures from a Git repository.

Quick overview of the code
08:37
+
Setting up and using PHPUnit
3 Lectures 08:49

Use composer to install PHPUnit

Installing PHPUnit
02:00

Let's configure PHP Unit and get it working with our code.

Configuring PHPUnit
03:25

Code Coverage
03:24
+
Basic Unit Testing
4 Lectures 34:45

Let's write our first unit test.

Preview 07:49

Writing slightly more complex tests against our code base.

Testing the Validator in more detail
13:47

Our code is a bit messy, so let's optimize it.

Cleaning up the code a bit
06:42

Sometimes you know what you want to test, but not how to test it. This is a sample case.

Preview 06:27
+
Getting Our Code Ready for Testing
3 Lectures 21:32

Dependency injection has the reputation of being difficult. It isn't.

Dependency Injection, and why you should use it
02:36

There are many to choose from, but I like one in particular. Here's why.

Choosing a Dependency Injection container
02:54

Getting started with dependency injection.

Setting up Dependency Injection in our codebase
16:02
+
Mocking Objects & Using mockBuilder & @dataProvider
5 Lectures 01:05:22

Mocking makes testing ever so much easier -- and it's easy to implement.

Mocking objects & updating our tests to use DI
14:24

Moving our validator class into the DI container.

Updating the Validator class to use DI & more about mockBuilder
19:34

Back to the Validator class, and writing tests to cover as much as we can.

Finally testing the validate function, and a smoke test
11:56

Why write 10 tests when you can write one, and provide that test with ten pieces of data?

Using @dataProvider for tests
09:56

Making our tests cover even more code.

Improving our validation tests
09:32
+
Integration Testing
6 Lectures 01:02:55

Let's test our code and see how it interacts with other parts of our code.

Setting up integration tests and testing the User model
10:26

A sample integration test for the getRows method.

Preview 09:59

What about protected methods? Can I test those?

Aside: Testing protected methods
05:35

Testing controller methods can be daunting. Let's make it simpler.

Testing the PageController->getShowHomePage() method
09:14

Let's test showing a page from our site.

Testing the getShowPage method
13:16

An example of cheating. We'll remove the cheat in the next lecture.

Finishing the PageController tests (and a total hack, just for fun)
14:25
+
Functional Testing
3 Lectures 36:16

Functional tests allow us to simulate visitors to our site without ever firing up a web browser.

Geting rid of our Hack & Writing functional tests
12:59

Curl is hard. Let's find an easier way to test things like forms on a web page, and let's test the session while we're at it.

Writing tests for pages that use the session
19:04

Functional testing is easy, so let's write some more.

Additional functional tests
04:13
+
Acceptance Testing Strategies
1 Lecture 07:12

Acceptance testing is all about planning.

This is the easy part... sort of
07:12
+
Final Thoughts & Housekeeping
2 Lectures 04:29

How to exclude directories (or files) from our test suite.

Let's not test our tests... excluding directories & files from test suites
01:23

There are alternatives and extensions to PHPUnit. Let's have a quick look at some.

Where to go from here
03:06
About the Instructor
Trevor Sawler
4.4 Average rating
367 Reviews
1,833 Students
3 Courses
Ph.D.

I have twenty years of experience in professional software development, and twenty years of experience as a University level educator and researcher.

As an entrepreneur, I have worked with a broad range of clients, including Thomson Nelson, Hewlett Packard, the Royal Bank of Canada, Keybank, Sprint, and many, many others. I also have extensive management and project management experience. I have led teams of fifty developers and artists on multi-million dollar projects, and much smaller teams on much smaller projects.

As a professor, I have taught in a wide variety of course areas, including Computer Science, English, Irish, and American literature, and a number of "crossover" courses that bridge the liberal arts and technologies.

I have won regional, national, and international awards for my work in the IT field, and have also won awards for my teaching and research efforts as a University professor.