I have write a router.test.php
file:
class RouterTest extends PHPUnit_Framework_TestCase
{
public function setUp()
{
require_once '../router.class.php';
}
public function testUnit()
{
$this->assertEquals(true, true);
}
}
... for simply test if my PHPUnit library is working correctly. But when I type phpunit router.test.php
in my console I get this error message: Fatal error: Trait 'Core' not found in C:\xampp\htdocs\_Framework\ver_3\libraries\router\router.class.php on line 23
... my Router class is working correctly and my Autoloader automatically include trait (named Core) inside my Router class.
Where is the problem?
My Autoloader register method looks like:
public static function register()
{
return spl_autoload_register(
__CLASS__ . '::load'
);
}
... I use this method in my index.php file, should I write another autoloader for PHPUnits?
I have include necessary files in the setUp method, now the class looks like that:
<?php
use Framework\Libraries\Configuration\Configuration;
use Framework\Libraries\Autoload\Autoloader;
class RouterTest extends PHPUnit_Framework_TestCase
{
public function setUp()
{
require '../../core.trait.php';
require '../../configuration/configuration.class.php';
require '../../autoload/autoloader.class.php';
Configuration::set('files', [
require '../../../configuration/framework.configuration.php',
require '../../../configuration/autoloader.configuration.php',
require '../../../configuration/router.configuration.php',
]);
Autoloader::set('prefixes', ['Framework']);
Autoloader::set('extensions', ['.class.php', '.trait.php']);
Autoloader::register();
require_once '../router.class.php';
}
public function testUnit()
{
$this->assertEquals(true, true);
}
}
... an I get a new error message: E Time: 109 ms, Memory: 1.75Mb There was 1 error
, but I can't get the error message. I think it's because Autoloader can't load files because of wrong path.
include_once('AutoLoader.php');
or you can createbootstrap.php
file for phpunit & include your all required class in that file. – Rikesh