Skip to content

Instantly share code, notes, and snippets.

@cakper
Created November 22, 2011 08:05
Show Gist options
  • Save cakper/1385152 to your computer and use it in GitHub Desktop.
Save cakper/1385152 to your computer and use it in GitHub Desktop.
Test CreatedAt and Updated At
public function testThatCreateAndUpdateDatesAreRegisteredAndIdGenerated()
{
$this->prepareEntityManager();
$now = new \DateTime('now');
$moneyTransaction = $this->moneyTransaction;
$validator = $this->validator;
$recipient = new \Jazzy\UserBundle\Entity\User();
$sender = new \Jazzy\UserBundle\Entity\User();
$this->entityManager->persist($recipient);
$this->entityManager->persist($sender);
$moneyTransaction->setRecipient($recipient);
$moneyTransaction->setSender($sender);
$moneyTransaction->setCurrencyId(Currency::_AED);
$moneyTransaction->setAmount(1000);
$errors = $validator->validate($moneyTransaction);
$this->assertEquals(0, count($errors));
$this->entityManager->persist($moneyTransaction);
$this->entityManager->flush();
$this->assertGreaterThanOrEqual($now, $moneyTransaction->getCreatedAt());
$this->assertGreaterThanOrEqual($now, $moneyTransaction->getUpdatedAt());
$this->assertGreaterThan(0, $moneyTransaction->getId());
while ((new \DateTime('now')) <= $now);
$now = new \DateTime('now');
$moneyTransaction->setAmount(100);
$this->entityManager->flush();
$this->assertGreaterThanOrEqual($now, $moneyTransaction->getUpdatedAt());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment