Unit Testing a PHP Script -
i have php scripts run cronjobs. no classes , few functions.
id test script phpunit make sure working appears need rewrite php class, dont want (or know how to).
for example if had script , function add 1 , 2 together,
<?php $a=1; $b=2 $c=$a+$b; ?>
how test $c==3 phpunit?
thanks, don
for example, don't test $c = 3.
but because example little simplistic. variable $c
stops existing after script executes. fact exists doesn't matter. want test code does, not how things.
i modify example little bit:
job.php
<?php $a=1; $b=2 echo $a + $b; ?>
now have output , behavior. test like:
public function testjob() { require('job.php'); $this->expectoutputstring('3'); }
phpunit has ability assert against stdout. make sure code outputs expect. tests these types of files check did correct. since php's require
statement execute file @ point, can run script , check output.
if file has functions, include , check each function in own individual test.
Comments
Post a Comment