getContainer()->get(UserRepository::class); $this->assertCount(0, $userRepository->findByAuthName($userName)); static::createClientWithToken($userName)->request('POST', '/api/dojos', [ 'json' => [ 'name' => $dojoName ] ]); $this->assertResponseStatusCodeSame(201); $user = $userRepository->findOneByAuthName($userName); $this->assertJsonContains([ 'name' => $dojoName, 'owner' => $this->getIri($user) ]); } /** * Requirement: A user should NOT be able to create more than one dojos! */ public function testDojoUserCannotCreateMultipleDojos(): void { $userName = "FooBarFigher"; $dojoName = "BigFightDojo"; DojoFactory::createOne([ 'name' => $dojoName, 'owner' => UserFactory::createOne([ 'authName' => $userName ]) ]); static::createClientWithToken($userName)->request('POST', '/api/dojos', [ 'json' => [ 'name' => $dojoName ] ]); $this->assertResponseStatusCodeSame(409); // 409 Conflict } /** * Requirement: A user should be able to change the dojos name! * FIXME: Add limitation so users will not do this frequently. */ public function testDojoChangeDojoName(): void { $userName = "FooBarFigher"; $dojoName = "BigFightDojo"; $newDojoName = "BigFightDojo"; $dojo = DojoFactory::createOne( [ 'name' => $dojoName, 'owner' => UserFactory::createOne([ 'authName' => $userName ]) ]); static::createClientWithToken($userName)->request('PATCH', '/api/dojos/' . $dojo->id, [ 'headers' => [ 'content-type' => 'application/merge-patch+json' ], 'json' => [ 'name' => $newDojoName ] ]); $this->assertResponseStatusCodeSame(200); } public function testDojoRetrieve(): void { $userName = "FooBarFigher"; $dojoName = "SmallFightDojo"; $dojo = DojoFactory::createOne( [ 'name' => $dojoName, 'owner' => UserFactory::createOne([ 'authName' => $userName ]) ]); static::createClientWithToken($userName)->request('GET', '/api/dojos/' . $dojo->getId()); $this->assertJsonContains([ 'name' => $dojoName ]); } }