I am writing a unit test for my code with phpunit. Code class has following:
<?
// Dependencies
//
require_once($_SERVER['DOCUMENT_ROOT']."/includes/configs.php");
class xyz{
..
...
..
}
?>
Test Class is as follows:
<?php
require_once("xyz.php");
class testxyz extends PHPUnit_Framework_TestCase{
public function setUp(){
$this->xyz= new xyz();
}
public function testEmail(){
$this->xyz->SetEmail('abc');
$name = $this->xyz->GetEmail();
$this->assertEquals($name == 'abc');
}
}
When i run php unit on my test class, I get following error:
Fatal Error: Class xyz not found
This error got resolved by giving <?php instead of <?
at the top of my code class.
Secondly, I get following error after first error was resolved:
Fatal error: require_once(): Failed opening required '/includes/configs.php'.
Which means $_SERVER['DOCUMENT_ROOT'] was not recognised by php unit.
Since code class can't be changed, how can I successfully run php unit without changing my code class. Please suggest any work around such that <?
and $_SERVER['DOCUMENT_ROOT']
start working with php unit.