Calculator (PHPUnit)

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_SkeletonGenerator

Requirements

Follow these before you run the sample:

What is included?

  • NetBeans PHP Application Project

Before the start

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

Getting Started

  1. Firstly, create a unit test for Calculator class - open it in the editor and select Tools > Create Tests.
  2. Secondly, add

    require_once __DIR__ . '/../src/Calculator.php';

    line to the top of the file, just after <? php.
  3. Finally, 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. Play futher with the sample :)

Debugging

These steps should enable you the debugging option at the sample project, if you already have PHP debugger 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.