Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Symfony 加载带有liip TestFixturesBundle的固定装置时,排除带有SetExcludedToctrineTables的表_Symfony_Doctrine Orm_Liipfunctionaltestbundle - Fatal编程技术网

Symfony 加载带有liip TestFixturesBundle的固定装置时,排除带有SetExcludedToctrineTables的表

Symfony 加载带有liip TestFixturesBundle的固定装置时,排除带有SetExcludedToctrineTables的表,symfony,doctrine-orm,liipfunctionaltestbundle,Symfony,Doctrine Orm,Liipfunctionaltestbundle,我正在尝试使用Liip测试包从代码中加载fixtures,使用fixtures中的loadFixtures()方法 但是,我需要排除我不希望在进程中删除的资源表。如果我理解正确,根据文档使用setExcludedToctrineTables方法应该很容易 不幸的是,当我运行这段代码时,表资源与所有其他资源一起被删除 有人知道为什么吗 不确定这是否相关,但我在一个单独的docker容器中使用mysql db <?php namespace App\Tests\Controller

我正在尝试使用Liip测试包从代码中加载fixtures,使用fixtures中的loadFixtures()方法 但是,我需要排除我不希望在进程中删除的资源表。如果我理解正确,根据文档使用setExcludedToctrineTables方法应该很容易

不幸的是,当我运行这段代码时,表资源与所有其他资源一起被删除

有人知道为什么吗

  • 不确定这是否相关,但我在一个单独的docker容器中使用mysql db

      <?php
    
      namespace App\Tests\Controller;
    
      use Symfony\Component\Panther\PantherTestCase;
      use Symfony\Component\Panther\Client;
      use Facebook\WebDriver\WebDriverBy as By;
      use Facebook\WebDriver\Exception\TimeoutException;
      use Liip\FunctionalTestBundle\Test\WebTestCase;
      use Symfony\Component\Panther\PantherTestCaseTrait;
      use Liip\TestFixturesBundle\Test\FixturesTrait;
    
      use App\Repository\UserRepository;
      use App\DataFixtures\UserFixtures;
      use App\DataFixtures\AccountFixtures;
    
      abstract class AbstractPantherTest extends WebTestCase{    
          // use trait so we can combine Liip and Panther features
          use PantherTestCaseTrait; // this is the magic. Panther is now available.
    
          // provide fixtures loading feature
          use FixturesTrait;
    
          // @var Symfony\Component\Panther\Client
          protected static $client;
    
          //Initialize the test case
          function setUp():void
          {
              static::bootKernel();
              if(self::$client === null){    
                  self::$client = self::createPantherClient(['browser' => PantherTestCase::FIREFOX]);
    
                  $this->setExcludedDoctrineTables(["RESOURCES"]);
                  $this->loadFixtures([
                      UserFixtures::class,
                  ]);
                  // retrieve the test user
                  $userRepository = static::$container->get(UserRepository::class);
    
                  // retrieve the test user
                  $testUser = $userRepository->findOneByUsername('Administrator');
    
                  // simulate $testUser being logged in
                  self::doLogin($testUser->getUsername(), 'xxx');
              }
          }
    

    回答我自己的问题,因为我刚刚发现了这个问题。有时候,你只需要睡个好觉:)

    所以这个代码实际上是有效的。表资源被删除,因为在实现测试的具体类中重新定义了setUp方法,并且重新定义包括对LoadFixture的另一个调用,但针对不同的数据类,并且没有排除:

    <?php
    
    namespace App\Tests\Controller;
    
    use App\DataFixtures\DiscountFixtures;
    
    class DiscountControllerWebTest extends AbstractPantherTest
    {
    
        function setUp():void
        {
            parent::setUp();
    
            $this->loadFixtures([
                DiscountFixtures::class,
            ]);
    
        }
    

    您是否确认该表确实被命名为
    “RESOURCES”
    ?是的,绝对确定表名,三重检查:)