/** * @param bool|null $andFlush * @dataProvider provideAddFlushValues */ public function testSave($andFlush = null) { $entity = $this->subject->create(); $this->objectManager->expects($this->once())->method('persist')->with($entity); $what = $andFlush || is_null($andFlush) ? $this->once() : $this->never(); $this->objectManager->expects($what)->method('flush'); is_null($andFlush) ? $this->subject->save($entity) : $this->subject->save($entity, $andFlush); }
public function testCRUD() { $log = $this->subject->create(); $log->setChannel('Channel'); $log->setLevel(200); $log->setLevelName('info'); $log->setMessage('Message'); $log->setDatetime(new \DateTime()); $log->setContext(['context' => 'Context']); $log->setExtra(['extra' => 'Extra']); $this->subject->save($log); $this->getEntityManager()->clear(); /** @var Log[] $logs */ $logs = $this->subject->findAll(); /** @var Log $log */ $log = $logs[0]; $this->assertCount(1, $logs); $this->assertEquals($log, $logs[0]); $this->subject->delete($log); $this->getEntityManager()->clear(); $this->assertEmpty($this->subject->findAll()); }
/** * {@inheritdoc} */ public function save(LogInterface $log, $andFlush = true) { if (!$log instanceof $this->class) { throw new InvalidArgumentException('1st argument must be an instanceof ' . $this->getClass()); } $extra = $log->getExtra(); if (is_array($extra) && isset($extra['job_ticket'])) { /** @var \Abc\Bundle\JobBundle\Entity\Log $log */ $log->setJobTicket($extra['job_ticket']); unset($extra['job_ticket']); $log->setExtra($extra); } parent::save($log, $andFlush); }