getClientAuthenticated(); $currentVersion = $work->getVersion(); $client->request( 'PUT', "/api/1.0/person/accompanying-course/work/{$work->getid()}.json?entity_version={$currentVersion}", content: json_encode([ 'type' => 'accompanying_period_work', 'id' => $work->getId(), 'startDate' => [ 'datetime' => '2023-12-15T00:00:00+01:00', ], 'endDate' => null, 'note' => 'This is a note', 'accompanyingPeriodWorkEvaluations' => [], 'goals' => [], 'handlingThirdParty' => null, 'persons' => [[ 'type' => 'person', 'id' => $personId, ], ], 'privateComment' => '', 'refferers' => [], 'results' => [], 'thirdParties' => [], ], JSON_THROW_ON_ERROR) ); self::assertResponseIsSuccessful(); $w = json_decode($client->getResponse()->getContent(), true, 512, JSON_THROW_ON_ERROR); self::assertEquals($work->getVersion() + 1, $w['version']); } /** * @dataProvider generateAccompanyingPeriodWork */ public function testWhenEditingAccompanyingPeriodWorkWithPreviousVersionAnHttpConflictResponseOccurs(AccompanyingPeriod\AccompanyingPeriodWork $work, int $personId): void { $client = $this->getClientAuthenticated(); $previous = $work->getVersion() - 1; $client->request( 'PUT', "/api/1.0/person/accompanying-course/work/{$work->getid()}.json?entity_version={$previous}", content: json_encode([ 'type' => 'accompanying_period_work', 'id' => $work->getId(), 'startDate' => [ 'datetime' => '2023-12-15T00:00:00+01:00', ], 'endDate' => null, 'note' => 'This is a note', 'accompanyingPeriodWorkEvaluations' => [], 'goals' => [], 'handlingThirdParty' => null, 'persons' => [[ 'type' => 'person', 'id' => $personId, ], ], 'privateComment' => '', 'refferers' => [], 'results' => [], 'thirdParties' => [], ], JSON_THROW_ON_ERROR) ); self::assertResponseStatusCodeSame(409); } public static function generateAccompanyingPeriodWork(): iterable { self::bootKernel(); $em = self::getContainer()->get(EntityManagerInterface::class); $userRepository = self::getContainer()->get(UserRepositoryInterface::class); $user = $userRepository->findOneByUsernameOrEmail('center a_social'); $period = new AccompanyingPeriod(); $em->persist($period); $gender = new Gender(); $gender->setGenderTranslation(GenderEnum::MALE); $gender->setLabel(['fr' => 'homme']); $gender->setIcon(GenderIconEnum::MALE); $em->persist($gender); $period->addPerson(($p = new Person())->setFirstName('test')->setLastName('test') ->setBirthdate(new \DateTime('1980-01-01'))->setGender($gender)); $em->persist($p); $issue = (new SocialIssue())->setTitle(['fr' => 'test']); $em->persist($issue); $action = (new SocialAction())->setIssue($issue); $em->persist($action); $work = new AccompanyingPeriod\AccompanyingPeriodWork(); $work ->setAccompanyingPeriod($period) ->setStartDate(new \DateTimeImmutable()) ->addPerson($p) ->setSocialAction($action) ->setCreatedBy($user) ->setUpdatedBy($user) ; $em->persist($work); $em->flush(); self::ensureKernelShutdown(); yield [$work, $p->getId()]; } }