createUser(['ROLE_USER']); $body = $this->authJson('POST', '/api/v1/clinic', $user); $this->assertSame(422, $this->responseCode()); $this->assertFalse($body['success']); $this->assertSame('name', $body['errors'][0]['field'] ?? null); } public function testBlankNameIsRejected(): void { $user = $this->createUser(['ROLE_USER']); $this->authJson('POST', '/api/v1/clinic', $user, ['name' => ' ']); $this->assertSame(422, $this->responseCode()); } public function testNamedClinicIsCreatedAndGrantsClinicRole(): void { $user = $this->createUser(['ROLE_USER']); $this->authJson('POST', '/api/v1/clinic', $user, ['name' => 'کلینیک شفا']); $this->assertSame(201, $this->responseCode()); $this->em->refresh($user); $this->assertContains('ROLE_CLINIC', $user->getRoles()); $clinic = $this->em->getRepository(Clinic::class)->findOneBy(['user' => $user]); $this->assertNotNull($clinic); $this->assertSame('کلینیک شفا', $clinic->getName()); } public function testSecondClinicForTheSameUserIsRejected(): void { $user = $this->createUser(['ROLE_USER']); $this->authJson('POST', '/api/v1/clinic', $user, ['name' => 'کلینیک اول']); $this->assertSame(201, $this->responseCode()); $body = $this->authJson('POST', '/api/v1/clinic', $user, ['name' => 'کلینیک دوم']); $this->assertSame(409, $this->responseCode()); $this->assertSame('ERR_CONFLICT_001', $body['errors'][0]['code'] ?? null); $count = $this->em->getRepository(Clinic::class)->count(['user' => $user]); $this->assertSame(1, $count, 'a user must never end up owning more than one clinic'); } }