首页 文章

Symfony 2上的功能测试 - 使用默认的autoload.php.dist问题

提问于
浏览
1

我一直在尝试运行FunctionalTest,它扩展了Symfony \ Bundle \ FrameworkBundle \ Tests \ Functional \ WebTestCase并没有那么成功 .

问题是:

  • FrameworkBundle \ Tests \ Functional \ app \ AppKernel.php中的代码尝试在框架包中加载autoload.php.dist(不是app /中的那个) .

  • 然后autoload.php.dist尝试加载此路径中不存在的vendor \ autoload.php .

如果我删除了FrameworkBundle中的autoload.php.dist,那么一切都很好,但我想避免这样做,因为每次我做作曲家更新时,我都必须删除那个特定的罚款 .

我不知道我做错了什么 .

控制台的确切错误发布在下面,以供您参考:

从D:\ xampp \ htdocs \ demo \ app \ phpunit.xml读取配置 . dist require_once()调用[D:\ xampp \ htdocs \ demo \ vendor \ sym fony \ symfony \ src \ Symfony \ Bundle \ FrameworkBundle \ Tests \ Functional \ app \ AppKernel.p hp:26] require_once(D:\ xampp)在[D:\ xampp \ htdocs \ demo \ vendor \ symfony \ symfony \ src \ Symfony中调用的\ htdocs \ demo \ vendor \ symfony \ symfony \ src \ Symfony \ Bundle \ FrameworkBundle \ Tests \ Functional \ app \ AppKernel.php) \ bun dle \ FrameworkBundle \ Tests \ Functional \ WebTestCase.php:47]致命错误:main():无法打开所需的'D:\ xampp \ htdocs \ demo \ vendor \ symfony \ symfony / vendor / autoload.php'(include_path第9行的D:\ xampp \ htdocs \ demo \ vendor \ symfony \ sym fony \ autoload.php.dist中的=' . ; D:\ xampp \ php \ PEAR')

测试类只是使用setUp扩展WebTestCase,如下所示:

static::$kernel = static::createKernel(array('test_case'));
static::$kernel->boot();
$this->containter = static::$kernel->getContainer();

1 回答

  • 4

    好的 . 我看到了问题 . 您正在从Tests \ Functional \ WebTestCase扩展 . 这实际上是测试WebTestCase的测试 . 您想要从Test \ WebTestCase扩展 .

    use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
    
    class PersonRepositoryTest extends WebTestCase
    {
        public function testProject()
        {
            $client = static::createClient();
    
            $manager = $client->getContainer()->get('cerad_person.manager');
    

    并且您可能希望使用上面显示的$ client行进行一两个工作 . 所有的设置都可能有点棘手 .

相关问题