🏫 PhpHooligans Workshop - Unit-Testing - The Basics 🎓
Introduction
This workshop is a first introductory course to isolated automated checks
(also known as unit-testing). It is geared towards explaining how to create and
run automated checks on a PHP code-base with PhpUnit., (*1)
After a short theoretical introduction, participants will gain the knowledge and
ability to create unit-tests, and run them on a local or remote environment
(such as build/CI server)., (*2)
Overview
The workshop is structured as follows:, (*3)
Preparation:
- Make sure PHP + Xdebug is installed and correctly configured
- Open the PhpUnit manual
Theory
A brief introduction on what automated checks are and how they work, (*4)
- What is an automated check?
- What is an automated check not? (i.e. exploratory)
- How do automated checks work?
- Various benefits
- A word on xUnit
- Testing old Code vs. Checking new Code
Practice
- Installing PHPUnit
- Globally
- Per project
- Using different versions (using phpunit.phar)
- Pick a project to use for testing (or use the WordWrapper example from
PHPHOOLIGANS/workshop-unit-testing)
- Basic Configuration
- Commandline options
- Local configuration file (phpunit.xml)
--
<testsuites>
- Project configuration file (
phpunit.xml.dist)
- Where do the tests go? (Directory structure, Namespaces and Autoloading)
- Creating an empty automated check
- Pick (or create) a class to test
- Creating a Test class
- Creating an automated check
- Running automated checks
- Creating an actual automated check
- Using Asserts to validate assumptions
Once the basics are under control, developers might want to learn more features
that PHPUnit offers. There is a workshop aimed at intermediate knowledge., (*5)
- Configuring the IDE or text-editor. Supported options are:
a. PhpStorm
b. Atom
c. Vim
d. Sublime
e. Other editor (an external tools is used)
- Providing data to tests using DataProviders
- Using test doubles
- Setting up test dependencies
- More configuration
- Strictness
forceCoversAnnotation="true"
-
<logging>
- TestDox
- Coverage Text
- Coverage Clover XML
<filter>
- Code Coverage
- Adding annotation
@coversDefaultClass and @covers
Follow-up Advanced workshops
There more advanced or topic-specific workshops beyond the knowledge the
intermediate workshop offers:, (*6)
/EOF/, (*7)