PHP: Testing and Debugging

Derek Bridge

Department of Computer Science,
University College Cork

PHP: Testing and Debugging

Aims:

Class exercise

Incomplete version of tax.php

$salary = (int) $_GET['salary'];

$tax_paid_at_lower_rate = 0.0;
$tax_paid_at_higher_rate = 0.0;

if 

    



    
    


echo "<table>";
echo "<tr><th>Tax paid at lower rate</td><td>{$tax_paid_at_lower_rate}</td></tr>";
echo "<tr><td>Tax paid at higher rate</td><td>{$tax_paid_at_higher_rate}</td></tr>";
echo "</table>";

Testing

Testing

Debugging

Class exercise

Buggy version of tax.php

$salary = (int) $_GET['salary'];

$tax_paid_at_lower_rate = 0.0;
$tax_paid_at_higher_rate = 0.0;

// Determine amount of income over 20000 and tax it at the higher rate
if ( $salary > 20000 )
{
    $salary_taxable_at_higher_rate = $salary - 20000;
    $tax_paid_at_higher_rate = $salary_taxable_at_higher_rate * 0.2;
}

// Tax the rest at the lower rate
$tax_paid_at_lower_rate = $salary * 0.05;
    
echo "<table>";
echo "<tr><th>Tax paid at lower rate</td><td>{$tax_paid_at_lower_rate}</td></tr>";
echo "<tr><td>Tax paid at higher rate</td><td>{$tax_paid_at_higher_rate}</td></tr>";
echo "</table>";