O'Reilly logo

PHP Application Development with NetBeans Beginner's Guide by M A Hossain Tonu

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action — testing with PHPUnit

In this tutorial, we will create a new NetBeans project to test our PHP classes from the IDE using PHPUnit. In order to do this, follow the steps below:

  1. Create a new project named Calculator, add a PHP class named Calculator in the project (right-click on project node and select New | PHP Class, then insert the class name), and type the following code for the Calculator class:
    <?php
    class Calculator {
    public function add($a, $b) {
    return $a + $b;
    }
    }
    ?>
    

    You can see that the add() method simply performs the addition of two numbers and returns the sum. We will test this method unit, to see whether it is returning the correct sum or not.

  2. Add a comment block with the @assert annotations and some sample input ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required