container = $app->getContainer(); $this->episodeActionWriter = $this->container->get(EpisodeActionWriter::class); $this->episodeActionRepository = $this->container->get(EpisodeActionRepository::class); } /** * @before */ public function before() { $this->startTransaction(); } public function testCreateSameEpisodeActionTriggersUniqueConstraintViolationException() { self::expectExceptionMessageMatches("/duplicate key value violates unique constraint/"); $episodeActionEntity = new EpisodeActionEntity(); $episodeActionEntity->setPodcast("https://podcast_01.url"); $episodeActionEntity->setEpisode("https://episode_01.url"); $episodeActionEntity->setAction("PLAY"); $episodeActionEntity->setPosition(5); $episodeActionEntity->setStarted(0); $episodeActionEntity->setTotal(123); $episodeActionEntity->setTimestamp("Mon Aug 23 01:58:56 GMT+02:00 2021"); $episodeActionEntity->setUserId(self::USER_ID_0); $this->episodeActionWriter->save($episodeActionEntity); //and save again $this->episodeActionWriter->save($episodeActionEntity); } public function testFindEpisodeActionByEpisodeUrlAndThenGuid() { $episodeActionEntity = new EpisodeActionEntity(); $episodeActionEntity->setPodcast("https://podcast_01.url"); $episodeActionEntity->setEpisode("https://episode_01.url"); $episodeActionEntity->setAction("PLAY"); $episodeActionEntity->setPosition(5); $episodeActionEntity->setStarted(0); $episodeActionEntity->setTotal(123); $episodeActionEntity->setTimestamp("Mon Aug 23 01:58:56 GMT+02:00 2021"); $episodeActionEntity->setUserId(self::USER_ID_0); $savedEpisodeActionEntity = $this->episodeActionWriter->save($episodeActionEntity); self::assertSame( $savedEpisodeActionEntity->getId(), $this->episodeActionRepository->findByEpisodeIdentifier($episodeActionEntity->getEpisode(), self::USER_ID_0)->getId() ); //update same episode action again this time with guid $episodeActionEntityWithGuid = clone $episodeActionEntity; $episodeActionEntityWithGuid->setGuid("guid:dadsaf4f4v"); $savedEpisodeActionEntityWithGuid = $this->episodeActionWriter->update($episodeActionEntityWithGuid); self::assertSame( $savedEpisodeActionEntityWithGuid->getId(), $this->episodeActionRepository->findByEpisodeIdentifier($episodeActionEntityWithGuid->getEpisode(), self::USER_ID_0)->getId() ); self::assertSame( $savedEpisodeActionEntityWithGuid->getId(), $this->episodeActionRepository->findByEpisodeIdentifier($episodeActionEntityWithGuid->getGuid(), self::USER_ID_0)->getId() ); } /** * @after */ public function after() { $this->rollbackTransation(); } }