vendredi 2 janvier 2015

PHPUnitTest: Autoload not working,crashes the test probably

Okay, I am trying to add unit testing capabilities in one of old legacy code. This is also my first time with unit test so please guide accordingly.


I just download and run sample test it works fine. Then I create first test on my project. It is simple shopping cart and I have class for handling Order data. my bootstrap script aka configuration script for project has



  1. a Global variable for all common variable like database connection object (for my custom db class).

  2. We have a class for some common function named as "Utility", this class also hold a static function for spl_autoload to autoload all classes that we need, like consumer, products etc.

  3. Then in configuration we create Database object and connect this DB class is autoload from our spl_autoload


Everything works fine on web, but when I run my test, it gives me warning and fatal error on some of variable and function which are global but I was accessing them with $GLOBALS. So i change those variable. Now, it give error in my autoload function where I try to "redirect user" in case a Class fail to load. i.e. some class is failing to load with my AutoLoad function.


How I know which class it is failing?


Next, I try to change my spl_autoload_register as spl_autoload_register('function',true, true) and now test doesn't show anything when run. No message whatsoever, I think it is crashing. How I debug it?


Error with spl_('functionname',true) call



Time: 60 ms, Memory: 5.00Mb

There was 1 failure:

1) Warning
PHP Warning: Cannot modify header information - headers already sent by (output started at phar:///usr/local/bin/phpunit.phar/phpunit/Util/Printer.php:172) in /opt/htdocs/projectpath/include/incfunctions.php on line 247


OrderTest Class



<?php
require_once "../../configure.php";

class OrderTest extends PHPUnit_Framework_TestCase
{
public function LoadOrder_O275()
{
$o = new Order(275);
$this->assertEquals(275, $o->OrderID);
}

public function LoadOrder_O1_Fail(){
$o = new Order(1);
$this->assertEquals(1, $o->OrderID);
}
}

Aucun commentaire:

Enregistrer un commentaire