Completed
Push — master ( f323bf...0da584 )
by Byron
02:55
created

AuthTest::testInvalidClient()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 25
rs 8.8571
cc 1
eloc 15
nc 1
nop 0
1
<?php
2
3
use GuzzleHttp\Client;
4
use GuzzleHttp\Subscriber\Mock;
5
use GuzzleHttp\Message\Response;
6
use badams\MicrosoftTranslator\MicrosoftTranslator;
7
8
class AuthTest extends \PHPUnit_Framework_TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
9
{
10
    public function testSetClient()
11
    {
12
        $client = new Client();
13
        $content = GuzzleHttp\Stream\Stream::factory('{"access_token":"valid"}');
14
        $mock = new Mock([new Response(200, [], $content)]);
15
        $client->getEmitter()->attach($mock);
16
17
        $translator = new MicrosoftTranslator($client);
18
19
        $reflection = new ReflectionClass($translator);
20
21
        $translator->setClient('client_id', 'client_secret');
22
23
        $clientId = $reflection->getProperty('clientId');
24
        $clientId->setAccessible(true);
25
        $this->assertEquals('client_id', $clientId->getValue($translator));
26
27
        $clientSecret = $reflection->getProperty('clientSecret');
28
        $clientSecret->setAccessible(true);
29
        $this->assertEquals('client_secret', $clientSecret->getValue($translator));
30
31
    }
32
33
    public function testInvalidClient()
34
    {
35
        $client = new Client();
36
37
        $content = GuzzleHttp\Stream\Stream::factory('{"error" : "invalid_client", "error_description" : "ACS50012: Authentication failed."}');
38
39
        $mock = new Mock([
40
            new Response(400, [], $content),
41
        ]);
42
43
        $client->getEmitter()->attach($mock);
44
45
        $translator = new MicrosoftTranslator($client);
46
        $translator->setClient('client_id', 'client_secret');
47
48
        $this->setExpectedException(
49
            '\badams\MicrosoftTranslator\Exceptions\AuthException',
50
            'ACS50012: Authentication failed.'
51
        );
52
53
        $reflection = new ReflectionClass($translator);
54
        $updateAccessToken = $reflection->getMethod('updateAccessToken');
55
        $updateAccessToken->setAccessible(true);
56
        $updateAccessToken->invoke($translator);
57
    }
58
59
60
}