ResponseFactoryTest::testError403()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 10
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 14
rs 9.9332
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\Response;
15
16
use DateTimeImmutable;
17
use Graze\Gigya\Gigya;
18
use Graze\Gigya\Response\ResponseCollectionInterface;
19
use Graze\Gigya\Response\ResponseFactory;
20
use Graze\Gigya\Test\TestCase;
21
use Graze\Gigya\Test\TestFixtures;
22
use Mockery as m;
23
use Psr\Http\Message\ResponseInterface as GuzzleResponseInterface;
24
25
class ResponseFactoryTest extends TestCase
26
{
27
    /**
28
     * @var ResponseFactory
29
     */
30
    private $factory;
31
32
    public static function setUpBeforeClass()
33
    {
34
        date_default_timezone_set('UTC');
35
    }
36
37
    public function setUp()
38
    {
39
        $this->factory = new ResponseFactory();
40
    }
41
42
    public function tearDown()
43
    {
44
        $this->factory = null;
45
    }
46
47
    public function testAccountModel()
48
    {
49
        $response = m::mock(GuzzleResponseInterface::class);
50
        $response->shouldReceive('getBody')
0 ignored issues
show
Unused Code introduced by
The call to Mockery\MockInterface::shouldReceive() has too many arguments starting with 'getBody'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

50
        $response->/** @scrutinizer ignore-call */ 
51
                   shouldReceive('getBody')

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
51
                 ->andReturn($this->tostream(TestFixtures::getFixture('accounts.getAccountInfo')));
52
53
        $gigyaResponse = $this->factory->getResponse($response);
0 ignored issues
show
Bug introduced by
$response of type Mockery\MockInterface is incompatible with the type Psr\Http\Message\ResponseInterface expected by parameter $response of Graze\Gigya\Response\Res...eFactory::getResponse(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

53
        $gigyaResponse = $this->factory->getResponse(/** @scrutinizer ignore-type */ $response);
Loading history...
54
55
        static::assertInstanceOf('Graze\Gigya\Response\Response', $gigyaResponse);
56
        static::assertEquals(200, $gigyaResponse->getStatusCode());
57
        static::assertEquals(0, $gigyaResponse->getErrorCode());
58
        static::assertEquals('OK', $gigyaResponse->getStatusReason());
59
        static::assertEquals('e6f891ac17f24810bee6eb533524a152', $gigyaResponse->getCallId());
60
        static::assertInstanceOf('DateTimeInterface', $gigyaResponse->getTime());
61
        static::assertEquals(
62
            DateTimeImmutable::createFromFormat(Gigya::DATE_TIME_FORMAT, '2015-03-22T11:42:25.943Z'),
63
            $gigyaResponse->getTime()
64
        );
65
        $data = $gigyaResponse->getData();
66
        static::assertEquals('_gid_30A3XVJciH95WEEnoRmfZS7ee3MY+lUAtpVxvUWNseU=', $data->get('UID'));
67
        static::assertSame($response, $gigyaResponse->getOriginalResponse());
68
    }
69
70
    public function testCollectionModel()
71
    {
72
        $response = m::mock(GuzzleResponseInterface::class);
73
        $response->shouldReceive('getBody')
0 ignored issues
show
Unused Code introduced by
The call to Mockery\MockInterface::shouldReceive() has too many arguments starting with 'getBody'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

73
        $response->/** @scrutinizer ignore-call */ 
74
                   shouldReceive('getBody')

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
74
                 ->andReturn($this->tostream(TestFixtures::getFixture('accounts.search_simple')));
75
76
        /** @var ResponseCollectionInterface $gigyaResponse */
77
        $gigyaResponse = $this->factory->getResponse($response);
0 ignored issues
show
Bug introduced by
$response of type Mockery\MockInterface is incompatible with the type Psr\Http\Message\ResponseInterface expected by parameter $response of Graze\Gigya\Response\Res...eFactory::getResponse(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

77
        $gigyaResponse = $this->factory->getResponse(/** @scrutinizer ignore-type */ $response);
Loading history...
78
79
        static::assertInstanceOf('Graze\Gigya\Response\ResponseCollection', $gigyaResponse);
80
        static::assertEquals(200, $gigyaResponse->getStatusCode());
81
        static::assertEquals(1840, $gigyaResponse->getTotal());
82
        static::assertEquals(5, $gigyaResponse->getCount());
83
        static::assertNull($gigyaResponse->getNextCursor());
84
85
        $results = $gigyaResponse->getData();
86
87
        static::assertEquals(5, $results->count());
88
        static::assertEquals('[email protected]', $results[0]->profile->email);
89
    }
90
91
    public function testError403()
92
    {
93
        $response = m::mock(GuzzleResponseInterface::class);
94
        $response->shouldReceive('getBody')
0 ignored issues
show
Unused Code introduced by
The call to Mockery\MockInterface::shouldReceive() has too many arguments starting with 'getBody'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

94
        $response->/** @scrutinizer ignore-call */ 
95
                   shouldReceive('getBody')

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
95
                 ->andReturn($this->tostream(TestFixtures::getFixture('failure_403')));
96
97
        $gigyaResponse = $this->factory->getResponse($response);
0 ignored issues
show
Bug introduced by
$response of type Mockery\MockInterface is incompatible with the type Psr\Http\Message\ResponseInterface expected by parameter $response of Graze\Gigya\Response\Res...eFactory::getResponse(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

97
        $gigyaResponse = $this->factory->getResponse(/** @scrutinizer ignore-type */ $response);
Loading history...
98
99
        static::assertInstanceOf('Graze\Gigya\Response\Response', $gigyaResponse);
100
        static::assertEquals(403, $gigyaResponse->getStatusCode());
101
        static::assertEquals(403005, $gigyaResponse->getErrorCode());
102
        static::assertEquals('Forbidden', $gigyaResponse->getStatusReason());
103
        static::assertEquals('Unauthorized user', $gigyaResponse->getErrorMessage());
104
        static::assertEquals('The user billyBob cannot login', $gigyaResponse->getErrorDetails());
105
    }
106
}
107