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

时间:2013-08-20 11:18:37

标签: symfony phpunit

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

问题是:

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

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

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

    我想知道我做错了什么。

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

      

    从D:\ xampp \ htdocs \ demo \ app \ phpunit.xml读取配置。   DIST

         
        
    1. 在[D:\ xampp \ htdocs \ demo \ vendor \ sym中调用的require_once()   fony \ symfony中的\ src \的Symfony \包\ FrameworkBundle \测试\功能\程序\ AppKernel.p   马力:26]

    2.   
    3. require_once(d:\ XAMPP \ htdocs中\演示\厂商\ symfony的\ symfony的\   SRC \的Symfony \包\ FrameworkBundle \测试\功能\程序\ AppKernel.php)   叫来   [d:\ XAMPP \ htdocs中\演示\厂商\ symfony的\ symfony的\ SRC \ Symfony的\面包   DLE \ FrameworkBundle \测试\功能\ WebTestCase.php:47]

    4.         

      致命错误:main():需要打开失败   'd:\ XAMPP \ htdocs中\演示\厂商\ symfony的\ symfony的/供应商/ autoload.php'   (include_path ='。; D:\ xampp \ php \ PEAR')in   d:\ XAMPP \ htdocs中\演示\供应商\ symfony的\符号   第9行的fony \ autoload.php.dist

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

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

1 个答案:

答案 0 :(得分: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行进行一两个工作。所有的设置都可能有点棘手。