zvoanhkietz/phpunit_tutorial

Simple project using PHPUnit.

v1.0.2 2016-07-31 05:14 UTC

README

Software License Build Status Coverage Status Latest Stable Version

NetBeans PHP Sample Application

What is Calculator?

Calculator is a simple calculator that supports basic arithmetical operations. This PHP application is created to highlight PHP features supported by NetBeans IDE.

This sample is not intented to be used in a production environment without any changes.

This sample demonstrates the following features:

  • unit testing using PHPUnit
  • creating unit tests using PHPUnit Skeleton Generator
  • code coverage of project files

Requirements

Follow these before you run the sample:

  • Install NetBeans IDE with PHP support
  • Install and configure PHP Runtime
  • Install all dependencies using Composer (click on project and invoke Composer > Install (dev))
    Note: PHPUnit can also be installed globally as PHAR file
  • Install and configure PHPUnit Skeleton Generator
  • For debugging and code coverage, Xdebug PHP extension is required

What is included?

  • NetBeans PHP Application Project

Before the start

  • If you want to try the sample out, follow Getting Started guidelines.
  • In case if you want to try debugging features of the NetBeans IDE, follow the Debugging guidelines.

Getting Started

  1. For the very first run, PHPUnit must be installed via Composer and PHPUnit Skeleton Generator globally (see Requirements).
  2. Now, create a unit test for Calculator class - open it in the editor and select Tools > Create Tests.
  3. Simply test the project. Right-click the project node and select Test. IDE will inform you about the test results (window with test results can be opened manually).
  4. For code coverage, open its report (right-click the project node and select Code Coverage > Show Report...) and Run All Tests if there are no data available yet. Open Calculator.php file from the list of the files to see which lines are and which lines are not tested.
  5. Play futher with the sample :)

Debugging

These steps should enable you the debugging option at the sample project, if you already have PHP debugger (Xdebug) installed and configured.
For demonstrating the PHP debugger in NetBeans, try the following:

  1. Open source class Calculator.php or generated CalculatorTest.php in the editor.
  2. Put breakpoint on some line with PHP code.
  3. To debug, right-click CalculatorTest.php and select Debug.

NetBeans PHP team, 2013 © Copyright Oracle corp., All rights reserved