AuthorizationControllersTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 0
loc 31
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testTokenCreation() 0 12 1
1
<?php
2
3
namespace OpenOrchestra\FunctionalTests\BaseApiBundle\Controller;
4
5
use OpenOrchestra\BaseBundle\Tests\AbstractTest\AbstractWebTestCase;
6
use Symfony\Bundle\FrameworkBundle\Client;
7
8
/**
9
 * Class AuthorizationControllersTest
10
 *
11
 * @group apiFunctional
12
 */
13
class AuthorizationControllersTest extends AbstractWebTestCase
14
{
15
    /**
16
     * @var Client
17
     */
18
    protected $client;
19
20
    /**
21
     * Set up the test
22
     */
23
    public function setUp()
24
    {
25
        $this->client = static::createClient();
26
    }
27
28
    /**
29
     * Test token creation and usage
30
     */
31
    public function testTokenCreation()
32
    {
33
        $this->client->request('GET', '/oauth/access_token?grant_type=client_credentials', array(), array(), array('PHP_AUTH_USER' => 'test_key', 'PHP_AUTH_PW' => 'test_secret'));
34
        $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
35
        $this->assertSame('application/json', $this->client->getResponse()->headers->get('content-type'));
36
        $tokenReponse = json_decode($this->client->getResponse()->getContent(), true);
37
        $refreshToken = $tokenReponse['refresh_token'];
38
39
        $this->client->request('GET', '/oauth/access_token?grant_type=refresh_token&refresh_token=' . $refreshToken, array(), array(), array('PHP_AUTH_USER' => 'test_key', 'PHP_AUTH_PW' => 'test_secret'));
40
        $this->assertEquals(200, $this->client->getResponse()->getStatusCode());
41
        $this->assertSame('application/json', $this->client->getResponse()->headers->get('content-type'));
42
    }
43
}
44