gpt4 book ai didi

php - config.yml 中的 DQL 未在 config_test.yml 中覆盖

转载 作者:行者123 更新时间:2023-12-02 01:33:03 27 4
gpt4 key购买 nike

编辑:原始标题“文本环境:”平台“sqlite”不支持函数“year””

将 beberlei\DoctrineExtensions 合并到测试环境中会产生

Uncaught PHP Exception Doctrine\ORM\Query\QueryException: "[Syntax Error] Function "year" does not supported for platform "sqlite""...

composer show -i 包括

beberlei/DoctrineExtensions          v1.0.5

扩展已安装:它们位于“...vendor\beberlei\DoctrineExtensions”。

month() 函数不会抛出错误。

config_test.yml

doctrine:
dbal:
default_connection: test
connections:
test:
driver: pdo_sqlite
path: %kernel.cache_dir%/test.sqlite
orm:
dql:
string_functions:
Soundex: Truckee\VolunteerBundle\DQL\Soundex
month: DoctrineExtensions\Query\Sqlite\Month
datetime_functions:
year: DoctrineExtensions\Query\Sqlite\Year

config.yml DQL

    dql:
string_functions:
Soundex: Truckee\VolunteerBundle\DQL\Soundex
numeric_functions:
month: Oro\ORM\Query\AST\Functions\SimpleFunction
year: Oro\ORM\Query\AST\Functions\SimpleFunction

函数调用

public function expiringOppsNotSent()
{
$nextMonth = date_add(new \DateTime(), new \DateInterval('P1M'));
$expiryMonth = date_format($nextMonth, 'm');
$expiryYear = date_format($nextMonth, 'Y');
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->select('o')
->from('TruckeeVolunteerBundle:Opportunity', 'o')
->leftJoin('TruckeeVolunteerBundle:AdminOutbox', 'a', 'WITH', $qb->expr()->eq('a.oppId', 'o'))
->andWhere($qb->expr()->eq('month(o.expireDate)', ':month'))
->andWhere($qb->expr()->eq('year(o.expireDate)', ':year'))
->andWhere('a.id is NULL')
->setParameter(':month', $expiryMonth)
->setParameter(':year', $expiryYear)
;
$notSent = $qb->getQuery()->getResult();

return $notSent;
}

编辑:

如果将config.yml中的dql(如上所示)注释掉,则不会出现该错误!

编辑#2:

创建 app_dev.php 后,功能测试中仍然存在错误。功能测试使用 Liip\FunctionalTestBundle\Test\WebTestCase

最佳答案

Sqlite 插件的正确命名空间是:

DoctrineExtensions\Query\Sqlite\Year

更新您的 config.yml 以包含:

doctrine:
orm:
dql:
datetime_functions:
year: DoctrineExtensions\Query\Sqlite\Year

关于php - config.yml 中的 DQL 未在 config_test.yml 中覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31922783/

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