Completed
Pull Request — master (#21)
by Harry
03:41
created

testInvalidBody()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 14
Ratio 100 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 14
loc 14
rs 9.4285
c 1
b 1
f 0
cc 1
eloc 8
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
use Mockery as m;
24
25
class ValidGigyaResponseMiddlewareTest extends TestCase
26
{
27
    public function testValidResponse()
28
    {
29
        $h = new MockHandler([
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $h. Configured minimum length is 2.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
30
            new Response(200, [], TestFixtures::getFixture('accounts.search_simple')),
31
        ]);
32
33
        $m = ValidGigyaResponseMiddleware::middleware();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $m. Configured minimum length is 2.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
34
35
        $f = $m($h);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $f. Configured minimum length is 2.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
36
        $f(new Request('GET', 'https://foo.com'), [])->wait();
37
    }
38
39 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...
40
    {
41
        $h = new MockHandler([
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $h. Configured minimum length is 2.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
42
            new Response(200, [], TestFixtures::getFixture('missing_field')),
43
        ]);
44
45
        $this->expectException(UnknownResponseException::class);
46
        $this->expectExceptionMessage("The contents of the response could not be determined. Missing required field: 'statusReason'");
47
48
        $m = ValidGigyaResponseMiddleware::middleware();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $m. Configured minimum length is 2.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
49
50
        $f = $m($h);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $f. Configured minimum length is 2.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
51
        $f(new Request('GET', 'https://foo.com'), [])->wait();
52
    }
53
54 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...
55
    {
56
        $h = new MockHandler([
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $h. Configured minimum length is 2.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
57
            new Response(200),
58
        ]);
59
60
        $this->expectException(UnknownResponseException::class);
61
        $this->expectExceptionMessage('The contents of the response could not be determined');
62
63
        $m = ValidGigyaResponseMiddleware::middleware();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $m. Configured minimum length is 2.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
64
65
        $f = $m($h);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $f. Configured minimum length is 2.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
66
        $f(new Request('GET', 'https://foo.com'), [])->wait();
67
    }
68
69 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...
70
    {
71
        $h = new MockHandler([
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $h. Configured minimum length is 2.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
72
            new Response(200, [], TestFixtures::getFixture('invalid_json')),
73
        ]);
74
75
        $this->expectException(UnknownResponseException::class);
76
        $this->expectExceptionMessage('The contents of the response could not be determined. Could not decode the body');
77
78
        $m = ValidGigyaResponseMiddleware::middleware();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $m. Configured minimum length is 2.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
79
80
        $f = $m($h);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $f. Configured minimum length is 2.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
81
        $f(new Request('GET', 'https://foo.com'), [])->wait();
82
    }
83
84
    public function testUnknownResponseContainsTheOriginalResponse()
85
    {
86
        $response = new Response(200, [], TestFixtures::getFixture('invalid_json'));
87
        $h = new MockHandler([$response]);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $h. Configured minimum length is 2.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
88
89
        $m = ValidGigyaResponseMiddleware::middleware();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $m. Configured minimum length is 2.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
90
91
        $f = $m($h);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $f. Configured minimum length is 2.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
92
        try {
93
            $f(new Request('GET', 'https://foo.com'), [])->wait();
94
        } catch (UnknownResponseException $e) {
95
            $this->assertSame($response, $e->getResponse());
96
        }
97
    }
98
}
99