【问题标题】:Fatal error in symfony2 AppKernel finding kernel classsymfony2 AppKernel 查找内核类中的致命错误
【发布时间】:2013-04-03 02:02:37
【问题描述】:

我正在使用 symfony2。我的 AppKernel 中的代码如下所示:

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 类的声明,如您在上述代码中所见。

我很困惑,无法找到代码突然中断的原因。

你能帮忙吗?

【问题讨论】:

  • 您在哪里定义了自动加载?你在哪里加载它?
  • 使用 appkernel 的单元测试...?
  • 您是否忘记安装供应商?

标签: unit-testing symfony phpunit


【解决方案1】:

致@ONEe:我在应用文件夹中定义了我的自动加载

致@Wouter J:单元测试没有使用appkernel - 它只是显示错误

致@Ramon Kleiss:我安装并卸载了供应商,然后重新安装。没有任何改变。

我无法弄清楚背后的原因,但我能够解决问题。它与Test和Vendor文件夹的权限更改有关。正如我所提到的,它之前运行过——由于某些未知原因,我的 bundles 测试文件夹和供应商文件夹的权限已更改,因此它无法访问正确的文件。我删除了我的安装并从存储库中获取了新的克隆并按照规则安装了项目,一切都很好。我弄清楚了旧项目文件系统和最新项目文件系统的区别,发现只有权限是不同的。

感谢您的回答。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-17
    • 2012-07-31
    • 2014-10-03
    相关资源
    最近更新 更多