Introduction to Testing with PHPUnit

An introduction to testing your code with PHPUnit
4.2 (51 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.
254 students enrolled
$19
$20
5% off
Take This Course
  • Lectures 33
  • Length 5 hours
  • Skill Level Intermediate Level
  • Languages English
  • Includes Lifetime access
    30 day money back guarantee!
    Available on iOS and Android
    Certificate of Completion
Wishlisted Wishlist

How taking a course works

Discover

Find online courses made by experts from around the world.

Learn

Take your courses with you and learn anywhere, anytime.

Master

Learn and practice real-world skills and achieve your goals.

About This Course

Published 1/2016 English

Course 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.

What are the requirements?

  • You should have at least a basic knowledge of PHP
  • You should have at least a basic understanding of Object Oriented programming principles

What am I going to get from this course?

  • 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

What 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.

What you get with this course?

Not for you? No problem.
30 day money back guarantee.

Forever yours.
Lifetime access.

Learn on the go.
Desktop, iOS and Android.

Get rewarded.
Certificate of completion.

Curriculum

Section 1: Why Testing is Critical to Good Development
06:19

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

Section 2: Setting up our project files
00:52

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.

10:47

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

14:45
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.
07:20

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...

08:37

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.

Section 3: Setting up and using PHPUnit
02:00

Use composer to install PHPUnit

03:25

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

Code Coverage
03:24
Section 4: Basic Unit Testing
07:49

Let's write our first unit test.

13:47

Writing slightly more complex tests against our code base.

06:42

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

06:27

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

Section 5: Getting Our Code Ready for Testing
02:36

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

02:54

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

16:02

Getting started with dependency injection.

Section 6: Mocking Objects & Using mockBuilder & @dataProvider
14:24

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

19:34

Moving our validator class into the DI container.

11:56

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

09:56

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

09:32

Making our tests cover even more code.

Section 7: Integration Testing
10:26

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

09:59

A sample integration test for the getRows method.

05:35

What about protected methods? Can I test those?

09:14

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

13:16

Let's test showing a page from our site.

14:25

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

Section 8: Functional Testing
12:59

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

19:04

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.

04:13

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

Section 9: Acceptance Testing Strategies
07:12

Acceptance testing is all about planning.

Section 10: Final Thoughts & Housekeeping
01:23

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

03:06

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

Students Who Viewed This Course Also Viewed

  • Loading
  • Loading
  • Loading

Instructor Biography

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.

Ready to start learning?
Take This Course