Udemy

PHP Unit Testing with PHPUnit

立即報名
  • 11,866 名學生
  • 更新於 12/2025
4.7
(2,774 個評分)
  • 提示:
  • 透過本站連結購買Udemy課程,本站將獲得推廣佣金,有助未來提供更多實用進修課程資訊給讀者。

課程資料

報名日期*
全年招生
課程級別
學習模式
修業期
2 小時 49 分鐘
教學語言
英語
授課導師
Dave Hollingworth
評分
4.7
(2,774 個評分)
課程連結
*提示: 以上時間表僅供參考,以機構網站為準。

課程簡介

PHP Unit Testing with PHPUnit

Unit test your PHP code using the PHPUnit testing framework: find bugs quickly and early, and improve your code quality

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!

課程章節

  • 13 個章節
  • 62 堂課
  • 第 1 章 Introduction
  • 第 2 章 Installation and Setup
  • 第 3 章 Testing Basics: Getting Started with PHPUnit
  • 第 4 章 Configuring the Command-Line Test Runner
  • 第 5 章 Organising Tests and Managing Different Output Types
  • 第 6 章 Test Dependencies, Fixtures and Exceptions
  • 第 7 章 Test Doubles: Stubbing and Mocking
  • 第 8 章 Test-Driven Development (TDD)
  • 第 9 章 Code Coverage
  • 第 10 章 Testing Non-Public Members and Abstract Classes
  • 第 11 章 Testing Static Methods
  • 第 12 章 Using Mockery with PHPUnit
  • 第 13 章 Conclusion

課程內容

  • 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


評價

  • M
    Mahammadali Manknojiya
    5.0

    I had a great experience with this PHPUnit course. The concepts were explained clearly, with practical examples that made testing easy to understand and apply. It strengthened my confidence in writing effective unit tests and integrating them into real projects. Highly recommended for anyone looking to level up their PHP testing skills.

  • K
    KJ Roelke
    5.0

    The test-driven development section is where this really came together for me—gave me a real sense of why TDD is so powerful while reinforcing what we'd learned up to that point. Great course, and grateful for the content update!

  • J
    Jörg Thode
    4.0

    Testing static methods, a little crazy, too fast, too much code changes in short time :-)

  • P
    Pablo Gandul Romero
    4.5

    Very good content and explanations. Thanks!

立即關注瀏覽更多

本網站使用Cookies來改善您的瀏覽體驗,請確定您同意及接受我們的私隱政策與使用條款才繼續瀏覽。

我已閱讀及同意