I trying the use namespaces in my yii application. This works fine.
When unit testing models using fixtures, PHPUnit makes PHP throw a fatal error because the model class is redeclared. It seems that the autoloading mechanism tries to declare/require a class twice, once in de test setup (loading the fixtures) and once during the execution.
The class, in this case ColorLib, is defined like:
namespace application\modules\colors\models;
class ColorLib extends \CActiveRecord
{
...
}
and the test file:
namespace application\modules\colors\models;
class AltColorSetCalcTest extends \CDbTestCase
{
public $fixtures = array(
'colorlib'=>'ColorLib',
'projects'=>'Projects'
);
public function setUp()
{
$this->getFixtureManager()->basePath = \Yii::getPathOfAlias(
'colors.tests.fixtures');
parent::setUp();
}
Running the test gives:
PHP Fatal error: Cannot redeclare class application\modules\colors\models\ColorLib
in /var/www/html/legen/protected/modules/colors/models/ColorLib.php on line 25
When the setUp() is commented out, the problem disappears (and is replaced by others of course because the fixtures are not set.)
Any help is appreciated.