gpt4 book ai didi

php - Symfony2 : Functional testing is failing during Fixtures load

转载 作者:行者123 更新时间:2023-11-28 21:31:00 25 4
gpt4 key购买 nike

我正在为一个包进行一些功能测试,但遇到了一些问题。这是 LoadFeeData.php 的内容:

public function load(ObjectManager $manager) {
for ($i = 0; $i < 10; $i++) {
$fee = new Fee();
$fee->setName("Comision-" . uniqid());
$fee->setDescription($this->generateRandomString());
$fee->setHoldback(1);
$manager->persist($fee);
$manager->flush();
}
}

这就是我在测试中所做的:

public function setUp() {
static::$kernel = static::createKernel();
static::$kernel->boot();
$this->em = static::$kernel->getContainer()->get('doctrine')->getManager();

$loader = new Loader();
$loader->addFixture(new LoadFeeData());

$purger = new ORMPurger();
$executor = new ORMExecutor($this->em, $purger);
$executor->execute($loader->getFixtures());
}

但是任何时候我尝试命令:

 phpunit -c app/ src/Company/ApprovalBundle/Tests/Controller/CommissionCompanyControllerTest.php

我收到这个错误:

1) Company\ApprovalBundle\Tests\Controller\CommissionCompanyControllerTest::testmodifyCommissionAction Doctrine\DBAL\DBALException: An exception occurred while executing 'DELETE FROM ext_translations':

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'kraken.ext_translations' doesn't exist

哪里出错了?

最佳答案

感谢@tomas-tibensky 的建议,我对我的代码进行了一些更改,现在可以根据需要加载固定装置(我现在需要学习如何在测试运行后删除它)但无论如何这是解决方案,因为 DB' t updated 然后你需要运行命令 doctrine:schema:update --force 来更新 DB schema 然后加载 fixtures:

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase,
Doctrine\Common\DataFixtures\Loader,
Doctrine\Common\DataFixtures\Executor\ORMExecutor,
Doctrine\Common\DataFixtures\Purger\ORMPurger,
Symfony\Bundle\FrameworkBundle\Console\Application,
Symfony\Component\Console\Input\StringInput
Company\ApprovalBundle\Entity\CompanyHasWtax,
Company\RegisterCompanyBundle\Entity\Company,
Company\ApprovalBundle\DataFixtures\ORM\LoadFeeData;

class CommissionCompanyControllerTest extends WebTestCase {

private $em;
protected static $application;

public function setUp() {
static::$kernel = static::createKernel();
static::$kernel->boot();
$this->em = static::$kernel->getContainer()->get('doctrine')->getManager();

self::runCommand('doctrine:schema:update --force');

$loader = new Loader();
$loader->addFixture(new LoadFeeData());

$purger = new ORMPurger();
$executor = new ORMExecutor($this->em, $purger);
$executor->execute($loader->getFixtures());
}

protected static function runCommand($command) {
$command = sprintf('%s --quiet', $command);

return self::getApplication()->run(new StringInput($command));
}

protected static function getApplication() {
if (null === self::$application) {
$client = static::createClient();

self::$application = new Application($client->getKernel());
self::$application->setAutoExit(false);
}

return self::$application;
}
}

关于php - Symfony2 : Functional testing is failing during Fixtures load,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22580290/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com