Chapter 14 Review:

• What is Xdebug? What useful features does it provide? (See pages 457 through 459.)

Xdebug is a debugging library for PHP that displays greater depth about error conditions than the stock error parser.

• What is unit testing? What are the benefits of unit testing? (See page 460.)

Unit testing is a means of determining what absolutely should happen and what should not happen. It should get beyond the code to determine the effects of real-world usage.

• What are some of the properties that unit tests should exhibit? (See page 460.)

Unit tests should have the following traits:

  • Be easy to read, write and execute
  • Be specific and small
  • Confirm code works as intended.
  • NOT be used to validate input.
  • NOT be used for error handling.

• What is TDD? (See page 461.)

TDD is Test Driven Development. It describes a methodology where tests are written FIRST, then code is created to survive the test.

• What are assertions? How do you invoke the assertion methods within the test class? (See page 462.)

Assertions are the core of unit testing and where you compare the codes output to what is sought or predicted as outcomes. To create assertions, in a test class, the basic format is $this->assertEquals(72, $this->r->getArea()); where getArea() is a method in the class being tested.

• How do you create a test case (a suite of tests) using PHPUnit? How do you create an individual test? (See pages 463– 464.)

One method is to extend the PHPUnit_Framework_TestCase class to test a given created class. Then the methods to be tested are grouped in this class extension.

• What is profiling? What is webgrind? (See page 471.)

Profiling is another name for performance checking code. Measures speed on a given host/server. Xdebug can profile, and Webgrind uses Xdebug's profiling capabilties to render a GUI of performance info.

• What kinds of things should you be watching for in profile data? (See pages 473 and 474.)

In profiling, look for functions and code that take a high percentage of the total cost. Look for items with high cost, but high invocations with lower costs are possibly better. Low invocation with high self cost could be problems.