Unit testing symfony2 AppKernel查找内核类时出现致命错误
我正在使用symfony2。我的AppKernel中的代码如下所示:Unit testing symfony2 AppKernel查找内核类时出现致命错误,unit-testing,symfony,phpunit,Unit Testing,Symfony,Phpunit,我正在使用symfony2。我的AppKernel中的代码如下所示: use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\Config\Loader\LoaderInterface; class AppKernel extends Kernel { public function registerBundles() { $bundles = array( new S
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new JMS\AopBundle\JMSAopBundle(),
new JMS\DiExtraBundle\JMSDiExtraBundle($this),
new JMS\SecurityExtraBundle\JMSSecurityExtraBundle()
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new My\BookBundle\MyBookBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
}
return $bundles;
}
现在,我在Bookbundle下的一个单元测试的代码如下所示:
namespace My\BookBundle\Tests\Controller;
use My\BookBundle\Services\TestHelper;
use My\BookBundle\Tests\BaseTest;
class WriterControllerTest extends BaseTest
{
/**
* @var TestHelper
*/
protected $testHelper;
public function __construct()
{
parent::__construct();
$this->testHelper = $this->get('test_helper');
}
public function setUp()
{
$this->testHelper->setupTestData();
}
以前它运行应用程序和测试非常顺利。然后我添加了很多功能代码(比如控制器、存储库功能等等)。现在,当我试图通过编写测试来备份代码时,命令提示符中出现以下错误:
PHP Fatal error: Class 'Symfony\Component\HttpKernel\Kernel' not found in /var/www/Symfony/app/AppKernel.php on line 7
其中第7行引用了AppKernel类的声明,正如您在上述代码中看到的
我很困惑,我无法找到突然破译代码背后的原因
你能帮忙吗?至@ONe:我已在应用程序文件夹中定义了自动加载 对@Wouter J:单元测试没有使用appkernel-只显示了错误 致@Ramon Kleiss:我已经安装并卸载了供应商,然后重新安装。没有什么变化 我不知道背后的原因是什么,但我能够解决这个问题。这与测试和供应商文件夹的权限更改有关。正如我之前提到的,它是在运行的——由于一些未知的原因,我的bundles测试文件夹和vendor文件夹的权限被更改,因此它无法访问正确的文件。我删除了我的安装,从存储库中获取了新的克隆,并按照规则安装了项目,一切正常。我找出了旧项目文件系统和最新项目文件系统的区别,发现只有权限不同
谢谢您的回答。您在哪里定义了自动加载?您在哪里加载它?使用appkernel的单元测试…?您可能忘记安装供应商了吗?