function setUp() { if (!self::$root) { $aragorn = new Entity\Person(); $aragorn->setFirstName('Viggo'); $aragorn->setLastName('Mortensen'); $legolas = new Entity\Person(); $legolas->setFirstName('Orlando'); $legolas->setLastName('Bloom'); $root = new Entity\Movie(); $root->setTitle('Return of the king'); $root->addActor($aragorn); $root->addActor($legolas); self::$root = $root; self::$aragorn = $aragorn; self::$legolas = $legolas; $em = $this->getEntityManager(); $em->persist($root); $em->flush(); } }
function testAutostoreDates() { $date = new \DateTime(); $aragorn = new Entity\Person(); $aragorn->setFirstName('Viggo'); $aragorn->setLastName('Mortensen'); $entity = new Entity\Movie(); $entity->setTitle('Return of the king'); $entity->addActor($aragorn); $em = $this->getEntityManager(); $em->setDateGenerator(function () { return 'foobar'; }); $em->persist($entity); $em->flush(); $result = $em->createGremlinQuery('g.v(:movie).map')->set('movie', $entity)->getMap(); $this->assertEquals('foobar', $result['creationDate']); $this->assertEquals('foobar', $result['updateDate']); $result = $em->createGremlinQuery('g.v(:movie).outE.map')->set('movie', $entity)->getMap(); $this->assertEquals('foobar', $result['creationDate']); $em->setDateGenerator(function () { return 'baz'; }); $em->persist($entity); $em->flush(); $result = $em->createGremlinQuery('g.v(:movie).map')->set('movie', $entity)->getMap(); $this->assertEquals('foobar', $result['creationDate']); $this->assertEquals('baz', $result['updateDate']); }