Defining unit tests
A unit test is a program that specifically tests a unit of your solution code. Just think of it as a program that tests a function and does not depend on other objects in your project.
For example, if you have a function called calculateTotal($a, $b, $c)
, then you can write a unit test function for it called testCanCalculateTotal()
. This unit test’s job is to verify whether the calculateTotal($a, $b, $c)
function is returning the expected result based on the business rules defined by your project’s specification.
In this example, let’s assume that the expected behavior of the calculateTotal
function is to get the summation of the three parameters, $a
, $b
, and $c
.
Let’s create an example unit test and solution codes. Create the following file inside our development container:
codebase/symfony/tests/Unit/CalculationTest.php
<?php namespace App\Tests\Unit; use App\Example\Calculator; use PHPUnit\Framework\TestCase; class...