EDIT:原标题" Text environment: "Function "year"不支持平台"sqlite"
在测试环境中加入beberlei'DoctrineExtensions将产生
未捕获的PHP异常原则'ORM'Query'QueryException: "[语法函数"year"不支持平台"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
配置。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;
}
编辑:如果在配置中配置了dql,则不会发生错误。Yml(如上所示)被注释掉了!
编辑# 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
我希望我有一个合理的解释为什么错误已经消失了。我尝试了顺序和标记DQL,但没有效果。我删除并重新输入条目,现在没有错误。最好的猜测是条目中至少有一个非显示字符。现在所有的测试都在SQLite中通过!