Completed
Pull Request — master (#27)
by Harry
06:09
created

testInvalidBody()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 6

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
dl 13
loc 13
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
/**
3
 * This file is part of graze/gigya-client
4
 *
5
 * Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/gigya-client/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/gigya-client
12
 */
13
14
namespace Graze\Gigya\Test\Unit\Validation;
15
16
use Graze\Gigya\Exception\UnknownResponseException;
17
use Graze\Gigya\Test\TestCase;
18
use Graze\Gigya\Test\TestFixtures;
19
use Graze\Gigya\Validation\ValidGigyaResponseMiddleware;
20
use GuzzleHttp\Handler\MockHandler;
21
use GuzzleHttp\Psr7\Request;
22
use GuzzleHttp\Psr7\Response;
23
24
class ValidGigyaResponseMiddlewareTest extends TestCase
25
{
26 View Code Duplication
    public function testValidResponse()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
    {
28
        $handler = new MockHandler(
29
            [
30
                new Response(200, [], TestFixtures::getFixture('accounts.search_simple')),
31
            ]
32
        );
33
34
        $middleware = ValidGigyaResponseMiddleware::middleware();
35
36
        $func = $middleware($handler);
37
        $func(new Request('GET', 'https://foo.com'), [])->wait();
38
    }
39
40
    /**
41
     * @expectedException \Graze\Gigya\Exception\UnknownResponseException
42
     * @expectedExceptionMessage The contents of the response could not be determined. Missing required field:
43
     *                           'statusReason'
44
     */
45 View Code Duplication
    public function testMissingFieldWillThrowAnException()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
    {
47
        $handler = new MockHandler(
48
            [
49
                new Response(200, [], TestFixtures::getFixture('missing_field')),
50
            ]
51
        );
52
53
        $middleware = ValidGigyaResponseMiddleware::middleware();
54
55
        $func = $middleware($handler);
56
        $func(new Request('GET', 'https://foo.com'), [])->wait();
57
    }
58
59
    /**
60
     * @expectedException \Graze\Gigya\Exception\UnknownResponseException
61
     * @expectedExceptionMessage The contents of the response could not be determined
62
     */
63 View Code Duplication
    public function testNoBodyWillFail()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
    {
65
        $handler = new MockHandler(
66
            [
67
                new Response(200),
68
            ]
69
        );
70
71
        $middleware = ValidGigyaResponseMiddleware::middleware();
72
73
        $func = $middleware($handler);
74
        $func(new Request('GET', 'https://foo.com'), [])->wait();
75
    }
76
77
    /**
78
     * @expectedException \Graze\Gigya\Exception\UnknownResponseException
79
     * @expectedExceptionMessage The contents of the response could not be determined. Could not decode the body
80
     */
81 View Code Duplication
    public function testInvalidBody()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
82
    {
83
        $handler = new MockHandler(
84
            [
85
                new Response(200, [], TestFixtures::getFixture('invalid_json')),
86
            ]
87
        );
88
89
        $middleware = ValidGigyaResponseMiddleware::middleware();
90
91
        $func = $middleware($handler);
92
        $func(new Request('GET', 'https://foo.com'), [])->wait();
93
    }
94
95
    public function testUnknownResponseContainsTheOriginalResponse()
96
    {
97
        $response = new Response(200, [], TestFixtures::getFixture('invalid_json'));
98
        $handler = new MockHandler([$response]);
99
100
        $middleware = ValidGigyaResponseMiddleware::middleware();
101
102
        $func = $middleware($handler);
103
        try {
104
            $func(new Request('GET', 'https://foo.com'), [])->wait();
105
        } catch (UnknownResponseException $e) {
106
            $this->assertSame($response, $e->getResponse());
107
        }
108
    }
109
}
110