mercredi 4 mars 2015

Error when using YEAR, MONTH, DAY mysql functions in LiipFunctionalTest bundle

I'm using DAY, MONTH, YEAR mysql's functions (http://ift.tt/1B6tPkG) with LiipFunctionalTestBundle. When I run the test I'm getting:


SQLSTATE[HY000]: General error: 1 no such function: YEAR


At the end, the test failed. I guess it's because of that.


This is my config_test file:



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: DoctrinceExtensions\Query\Mysql\Year
MONTH: DoctrinceExtensions\Query\Mysql\Month
DAY: DoctrinceExtensions\Query\Mysql\Day


In my code I use them as:



$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"));


If I run the application I don't have problems.


Aucun commentaire:

Enregistrer un commentaire