我正在使用mysql 的函数DAY
(MONTH
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_year )和. 当我运行测试时,我得到:YEAR
LiipFunctionalTestBundle
SQLSTATE[HY000]: General error: 1 no such function: YEAR
最后,测试失败了。我想是因为这个。
这是我的config_test
文件:
imports:
- { resource: config_dev.yml }
framework:
test: ~
session:
storage_id: session.storage.filesystem
name: MOCKSESSID
web_profiler:
toolbar: false
intercept_redirects: false
swiftmailer:
disable_delivery: true
liip_functional_test:
cache_sqlite_db: true
authentication:
username: "root"
password: "admin"
doctrine:
dbal:
default_connection: default
connections:
default:
driver: pdo_sqlite
path: %kernel.cache_dir%/test.db
orm:
dql:
datetime_functions:
YEAR: DoctrineExtensions\Query\Mysql\Year
MONTH: DoctrineExtensions\Query\Mysql\Month
DAY: DoctrineExtensions\Query\Mysql\Day
在我的代码中,我将它们用作:
$em = $this->getDoctrine()->getManager();
$emConfig = $em->getConfiguration();
$emConfig->addCustomDatetimeFunction('YEAR', 'DoctrineExtensions\Query\Mysql\Year');
$emConfig->addCustomDatetimeFunction('MONTH', 'DoctrineExtensions\Query\Mysql\Month');
$emConfig->addCustomDatetimeFunction('DAY', 'DoctrineExtensions\Query\Mysql\Day');
....
$em = $this->get('doctrine.orm.entity_manager');
$dql = $em->createQuery('SELECT um FROM Acme\AcmeBundle\Entity\Menu um WHERE
um.user = :id and
YEAR(um.day) = :year and
MONTH(um.day) = :month and
DAY(um.day) = :day');
$dql->setParameter('id', $id);
$dql->setParameter('year', $now->format("Y"));
$dql->setParameter('month', $now->format("m"));
$dql->setParameter('day', $now->format("d"));
如果我运行应用程序,我没有问题。