Course Overview
If you are a PHP developer and you want to learn how to write better code, with fewer bugs, you will need to know how to write unit tests.
Learn how to unit test your PHP code using the PHPUnit testing framework.
Learn what unit tests are
Learn how to write unit tests using PHPUnit
Build a test suite for PHP functions and classes
Make test methods dependent on each other
Use test doubles: mocks and stubs, including how to use Mockery
Learn how and why you should use dependency injection
Learn test-driven development (TDD)
Learn how to test protected and private methods and properties (and whether you actually should or not!)
Learn how to test abstract classes
A skill that will enable you to write higher quality code, in a shorter time, with better documentation and fewer bugs.
Learning how to write unit tests for your code will make you write better code. With automated tests, you can find bugs more easily, and if you break something you'll notice straight away.
Many experienced developers write unit tests for their code. It's a repeatable way of checking that the code works as intended, and also serves as documentation. Many popular PHP projects are unit tested, such as WordPress and Moodle, and if you use frameworks such as Laravel or Symfony, these provide tight integration with the PHPUnit testing framework.
Content and Overview
How do you currently test your code? Maybe you run your code in a browser, use var_dump a lot and so on. The problem with this is that you only tend to test new code - you don't go back and test old code. What if you add some new code that breaks the old code?
With automated unit tests, you have more control. If your new code breaks something, you'll notice straight away. You can fix bugs more easily, thereby reducing development time.
Tests are also a form of documentation, just like comments: they serve to show why the code has been written that way.
Suitable for all PHP developers, you'll start by learning the basics of unit testing PHP code, including how to use assertions.
Then you'll learn how to test functions and classes, and how to configure the PHPUnit framework.
Next you'll learn how to use test dependencies, fixtures and how to test for exceptions.
You'll also see how test doubles work - mock objects and stub methods.
Then you'll learn how to write code using test-driven development - writing the tests first, then the code.
You'll also learn how to test protected and private class methods and properties, and whether this is actually a good idea or not.
Testing static methods is covered in detail, including several methods for dealing with static dependencies.
When you complete the course you'll be able to write unit tests for your existing PHP code, and develop new code using test-driven development.
Complete with all the code shown in the lectures, you'll be able to work alongside the instructor and will receive a verifiable certificate of completion upon finishing the course.
Also, at all times throughout the course you have access to the instructor in the Q&A section to ask for help with any topic related to the course.
Enrol now and add unit testing to your PHP skillset!
FAQ
FAQ area empty
Course curriculum
Chương 1 Introduction 2 bài
Chương 2 Installation and Setup 4 bài
Chương 3 Testing Basics: Getting Started with PHPUnit 4 bài
Chương 4 Configuring the Command-Line Test Runner 5 bài
- Controlling the Test Runner Output: Colours, Testdox and More Xem trước
- Running a Script Before the Tests are Executed: the Bootstrap Script Xem trước
- Add an Autoloader to Load Classes Automatically Xem trước
- Using Composer's Autoloader to Load Classes and Functions Xem trước
- The PHPUnit Configuration File: phpunit.xml Xem trước
Chương 5 Organising Tests and Managing Different Output Types 6 bài
- Running Multiple Tests: Organising Tests Into Test Suites Xem trước
- Running Individual Tests with Filters Xem trước
- Two Ways of Marking Methods as Test Methods Xem trước
- Add a Test but Mark It to Be Implemented Later Xem trước
- Fixing a Bug Through Testing: The Difference Between Errors and Failures Xem trước
- Simplifying Tests with Test Method Arguments and Data Providers Xem trước
Chương 6 Test Dependencies, Fixtures and Exceptions 5 bài
- Unit Test a Queue Class: Multiple Assertions in a Single Test Method Xem trước
- Test Dependencies: Make a Test Method Dependent on Another Xem trước
- Fixtures: Set Up the Known State of the Tests Using setUp and tearDown Xem trước
- Easily Add a New Test Method When Fixtures are Being Used Xem trước
- Testing Exceptions: Expecting Code to Throw an Exception Xem trước
Chương 7 Test Doubles: Stubbing and Mocking 6 bài
- Unit Testing Classes in Isolation: An Introduction to Test Doubles Xem trước
- Dependency Injection: Inject Objects That a Class Depends On Xem trước
- Test Doubles: Create and Configure Test Stubs Xem trước
- Expecting and Handling Exceptions in Test Stubs Xem trước
- Use Mocking to Assert Test Double Behaviour Xem trước
- Customise the Test Double Generation with the getMockBuilder Method Xem trước
Chương 8 Test-Driven Development (TDD) 6 bài
- Set Up a Project for Test-Driven Development Xem trước
- Start TDD: Write a Test First, Then Write the Code to Make it Pass Xem trước
- Include Refactoring in The TDD Process Xem trước
- Add Another Test Class To Satisfy a Design Requirement Xem trước
- Rewrite Code To Make Additional Tests Pass Xem trước
- Add Further Tests to Drive the Development of Additonal Functionality Xem trước
Chương 9 Code Coverage 5 bài
- Install a Code Coverage Driver Xem trước
- Configure Your Development Environment So PHPUnit Can Use Xdebug Xem trước
- Configure PHPUnit With the Location of the Project Source Code Xem trước
- Generate Code Coverage Reports in Different Formats Xem trước
- Add Tests to Increase Coverage Based on the Report Xem trước
Chương 10 Testing Non-Public Members and Abstract Classes 5 bài
Chương 11 Testing Static Methods 4 bài
Chương 12 Using Mockery with PHPUnit 6 bài
- Installation of Mockery and Integration with PHPUnit Xem trước
- Comparing Mock Objects: PHPUnit vs Mockery Xem trước
- Using Mockery to Mock a Dependency that Doesn't Exist Yet Xem trước
- Multiple Method Calls: Returning Different Values with Different Argumen Xem trước
- Use Mockery Alias Mocks to Stub a Static Method Call Xem trước
- Mockery Spies: Verify Test Double Method Calls After They Happen Xem trước
Chương 13 Conclusion 1 bài
Requirment
-
You must know PHP, including object-oriented code
-
Be happy running commands in the terminal / command line on your computer
-
Ideally have PHP and Composer installed, but a brief overview of installing these will be covered
Outcomes
-
Write automated tests for your PHP functions and classes
-
Write better code with less bugs, in less time
-
Develop code using test-driven development (TDD)
-
Know that the code you write works how you want it to
-
Learn the industry-standard PHPUnit testing framework
-
Get support directly from the instructor
0 Student
24 Courses
0 review