【问题标题】:Symfony 1.4 Doctrine reset data before testsSymfony 1.4 Doctrine 在测试前重置数据
【发布时间】:2010-11-24 14:01:03
【问题描述】:

我试图通过BDD symfony plugin 测试 symfony 应用程序的行为并且我卡住了,因为我意识到我不知道如何在我的 BDD 引导文件中直接通过 PHP 重置数据库:-/。

有人知道如何在不加载固定装置的情况下重置它吗? (结果必须是空数据库)

【问题讨论】:

    标签: symfony1 doctrine


    【解决方案1】:

    如果您的意思是每次测试都重置(例如运行test:all),我将它放在test/bootstrap/db.php 文件中,并将其包含在unit.phpfunctional.php 的末尾

    new sfDatabaseManager($configuration);
    
    $doctrine = new sfDoctrineDropDbTask($configuration->getEventDispatcher(), new sfAnsiColorFormatter());
    $doctrine->run(array(), array("--no-confirmation","--env=test"));
    
    $doctrine = new sfDoctrineBuildDbTask($configuration->getEventDispatcher(), new sfAnsiColorFormatter());
    $doctrine->run(array(), array("--env=test"));
    
    $doctrine = new sfDoctrineInsertSqlTask($configuration->getEventDispatcher(), new sfAnsiColorFormatter());
    $doctrine->run(array(), array("--env=test"));
    

    这假定$configuration 是在您的unit.phpfunctional.php 文件中定义的,因为它通常是默认的。

    以上内容与内置的石灰测试套件一起使用,但我相信您可以在 BDD 引导程序中适当地扩展/实现它。

    【讨论】:

      【解决方案2】:

      我可能有误会,但你不能直接运行构建吗?

      symfony doctrine:build --all
      

      【讨论】:

      • 是的,但是在测试引导中以编程方式进行,所以richsage 有一个线索。也谢谢你。
      猜你喜欢
      • 1970-01-01
      • 2013-11-04
      • 2018-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-12
      • 1970-01-01
      相关资源
      最近更新 更多