Calculator (Codeception)

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 intended to be used in a production environment without any changes.

This sample demonstrates the following features:

  • unit testing using Codeception
  • creating unit tests using codecept generate:test command
  • 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: Codeception can also be installed globally as PHAR file
  • 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, Codeception must be installed via Composer globally (see Requirements).
  2. To initialize Codeception, Right-click the project node and select Codeception > Bootstrap.
  3. Now, create a unit test for CalculatorEx class - open it in the editor and select Tools > Create/Update Tests. Then, select test command and unit suite in the Create Test dialog.
  4. Add test cases for CalculatorEx class to the test class like CalculatorTest class.
  5. To enable coverage put the below code in the unit suite configuration file tests/unit.suite.yml.
    
    coverage:
        enabled: true
        include:
            - src/*
                                    
  6. 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).
  7. 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.
  8. 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 CalculatorTest.php in the editor.
  2. Put breakpoint on some line with PHP code.
  3. To debug, right-click CalculatorTest.php and select Debug.