Exemplo n.º 1
0
 /**
  * @param Contact $contact
  * @param EntityManager $entityManager
  */
 protected function setCreatedProperties(Contact $contact, EntityManager $entityManager)
 {
     if (!$contact->getCreatedAt()) {
         $contact->setCreatedAt(new \DateTime('now', new \DateTimeZone('UTC')));
     }
     if (!$contact->getCreatedBy()) {
         $contact->setCreatedBy($this->getUser($entityManager));
     }
 }
Exemplo n.º 2
0
 public function testPrePersistWithAlreadySetCreatedAtAndCreatedBy()
 {
     $entity = new Contact();
     $createdAt = new \DateTime();
     $createdBy = new User();
     $entity->setCreatedAt($createdAt)->setCreatedBy($createdBy);
     $this->mockSecurityContext();
     $em = $this->getEntityManagerMock();
     $args = new LifecycleEventArgs($entity, $em);
     $this->contactListener->prePersist($args);
     $this->assertSame($createdAt, $entity->getCreatedAt());
     $this->assertSame($createdBy, $entity->getCreatedBy());
 }