I have refactored some PHP code and putting it through a series of PHPUnit classes.
我重构了一些PHP代码并通过一系列PHPUnit类。
I get the above Fatal Error when running PHPUnit (3.7.28) on it (through console).
在运行PHPUnit(3.7.28)时(通过控制台)我得到上面的致命错误。
PHP version is 5.4.6-1ubuntu1.4 (cli).
PHP版本是5.4.6-1ubuntu1.4(cli)。
I know the Zip class is working and available as it works when running the code normally (also via console)
我知道Zip类正常工作,因为它在正常运行代码时也可用(也可通过控制台)
Thoughts / ideas appreciated.
思想/想法受到赞赏。
Thanks!
<?php
namespace phpUnit\Test;
Class MyTest extends \PHPUnit_Framework_TestCase
{
Public Function setUp()
{
$this->zip = new ZipArchive();
}
}
1 个解决方案
#1
1
Inside a namespace, you have to reference classes (other than functions) with their fully qualified class name or import them first:
在命名空间内,您必须使用其完全限定的类名引用类(函数除外)或首先导入它们:
$this->zip = new \ZipArchive();
or
namespace phpUnit\Test;
use ZipArchive;
Your "normal" code is probably not using namespaces if it works there.
如果它在那里工作,你的“普通”代码可能不使用命名空间。
#1
1
Inside a namespace, you have to reference classes (other than functions) with their fully qualified class name or import them first:
在命名空间内,您必须使用其完全限定的类名引用类(函数除外)或首先导入它们:
$this->zip = new \ZipArchive();
or
namespace phpUnit\Test;
use ZipArchive;
Your "normal" code is probably not using namespaces if it works there.
如果它在那里工作,你的“普通”代码可能不使用命名空间。