setUsername('foo'); $user->setPassword( $container->get('security.user_password_hasher')->hashPassword($user, '$3CR3T') ); $access->setPerson($user); $organization->addAccess($access); $manager = $container->get('doctrine')->getManager(); $manager->persist($organization); $manager->flush(); // retrieve a token $response = $client->request('POST', '/login_check', [ 'headers' => ['Content-Type' => 'application/json'], 'json' => [ 'username' => 'foo', 'password' => '$3CR3T', ], ]); $json = $response->toArray(); self::assertResponseIsSuccessful(); $this->assertArrayHasKey('token', $json); // test not authorized $client->request('GET', '/my_profile/1'); self::assertResponseStatusCodeSame(401); // test authorized $client->request('GET', '/my_profile/1', [ 'Content-Type' => 'application/ld+json', 'authorization' => sprintf('BEARER %s', $json['token']), 'x-accessid' => 1 ]); self::assertResponseIsSuccessful(); } }