PartKeepr\AuthBundle\Tests\UserTest::testUserProtect PHP Method

testUserProtect() public method

public testUserProtect ( )
    public function testUserProtect()
    {
        /**
         * @var FOSUser
         */
        $fosUser = $this->fixtures->getReference('user.admin');
        $userService = $this->getContainer()->get('partkeepr.userservice');
        $user = $userService->getProxyUser($fosUser->getUsername(), $userService->getBuiltinProvider(), true);
        /*
         * @var User $user
         */
        $userService->protect($user);
        $this->assertTrue($user->isProtected());
        $client = static::makeClient(true);
        $iriConverter = $this->getContainer()->get('api.iri_converter');
        $iri = $iriConverter->getIriFromItem($user);
        $data = ['username' => 'foo'];
        $client->request('PUT', $iri, [], [], [], json_encode($data));
        $response = json_decode($client->getResponse()->getContent());
        $exception = new UserProtectedException();
        $this->assertEquals(500, $client->getResponse()->getStatusCode());
        $this->assertObjectHasAttribute('hydra:description', $response);
        $this->assertEquals($exception->getMessageKey(), $response->{'hydra:description'});
        $client->request('DELETE', $iri);
        $response = json_decode($client->getResponse()->getContent());
        $this->assertEquals(500, $client->getResponse()->getStatusCode());
        $this->assertObjectHasAttribute('hydra:description', $response);
        $this->assertEquals($exception->getMessageKey(), $response->{'hydra:description'});
    }