loginUser($user); SubjectFactory::createMany(5, [ 'createdBy' => $user, ]); static::getContainer() ->get(SubjectRepository::class) ->findOneBy(['name' => 'Riviera']); $client->request( 'GET', '/api/subjects', server: ['CONTENT_TYPE' => 'application/json'], content: json_encode(['name' => 'Riviera']), ); $data = json_decode($client->getResponse()->getContent(), true); $this->assertResponseIsSuccessful(); $this->assertCount(5, $data['payload']['subjects']); } public function testAddingNewSubjectViaApi(): void { $client = static::createClient(); $repo = static::getContainer()->get(SubjectRepository::class); $user = UserFactory::createOne(); $client->loginUser($user); $this->assertEmpty($repo->findAll()); $client->request( 'POST', '/api/subjects', server: ['CONTENT_TYPE' => 'application/json'], content: json_encode(['name' => 'Riviera']), ); $this->assertResponseIsSuccessful(); $this->assertResponseStatusCodeSame(201); $this->assertCount(1, $repo->findAll()); $subject = static::getContainer() ->get(SubjectRepository::class) ->findOneBy(['name' => 'Riviera']); $this->assertNotNull($subject); $this->assertInstanceOf(Restaurant::class, $subject); $this->assertNotNull($subject->getCreatedBy()); $this->assertSame($user->getId(), $subject->getCreatedBy()->getId()); } }