ResponseExceptionTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 37
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testInstanceOfRuntimeException() 0 8 1
A testExceptionIncludeResponseStringAndCode() 0 10 1
A testGetResponse() 0 8 1
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\Exception;
15
16
use Graze\Gigya\Exception\ResponseException;
17
use Graze\Gigya\Response\ResponseInterface;
18
use Graze\Gigya\Test\TestCase;
19
use Mockery as m;
20
21
class ResponseExceptionTest extends TestCase
22
{
23
    public function testInstanceOfRuntimeException()
24
    {
25
        $response = m::mock(ResponseInterface::class);
26
        $response->shouldReceive('getErrorCode')
0 ignored issues
show
Unused Code introduced by
The call to Mockery\MockInterface::shouldReceive() has too many arguments starting with 'getErrorCode'. ( Ignorable by Annotation )

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

26
        $response->/** @scrutinizer ignore-call */ 
27
                   shouldReceive('getErrorCode')

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...
27
                 ->andReturn(0);
28
        $exception = new ResponseException($response);
0 ignored issues
show
Bug introduced by
$response of type Mockery\MockInterface is incompatible with the type Graze\Gigya\Response\ResponseInterface expected by parameter $response of Graze\Gigya\Exception\Re...xception::__construct(). ( Ignorable by Annotation )

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

28
        $exception = new ResponseException(/** @scrutinizer ignore-type */ $response);
Loading history...
29
30
        static::assertInstanceOf('RuntimeException', $exception);
31
    }
32
33
    /**
34
     * @expectedException \Graze\Gigya\Exception\ResponseException
35
     * @expectedExceptionCode    100001
36
     * @expectedExceptionMessage some description from the response
37
     */
38
    public function testExceptionIncludeResponseStringAndCode()
39
    {
40
        $response = m::mock(ResponseInterface::class);
41
        $response->shouldReceive('getErrorCode')
0 ignored issues
show
Unused Code introduced by
The call to Mockery\MockInterface::shouldReceive() has too many arguments starting with 'getErrorCode'. ( Ignorable by Annotation )

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

41
        $response->/** @scrutinizer ignore-call */ 
42
                   shouldReceive('getErrorCode')

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...
42
                 ->andReturn(100001);
43
        $response->shouldReceive('__toString')
44
                 ->andReturn('some description from the response');
45
        $exception = new ResponseException($response);
0 ignored issues
show
Bug introduced by
$response of type Mockery\MockInterface is incompatible with the type Graze\Gigya\Response\ResponseInterface expected by parameter $response of Graze\Gigya\Exception\Re...xception::__construct(). ( Ignorable by Annotation )

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

45
        $exception = new ResponseException(/** @scrutinizer ignore-type */ $response);
Loading history...
46
47
        throw $exception;
48
    }
49
50
    public function testGetResponse()
51
    {
52
        $response = m::mock(ResponseInterface::class);
53
        $response->shouldReceive('getErrorCode')
0 ignored issues
show
Unused Code introduced by
The call to Mockery\MockInterface::shouldReceive() has too many arguments starting with 'getErrorCode'. ( Ignorable by Annotation )

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

53
        $response->/** @scrutinizer ignore-call */ 
54
                   shouldReceive('getErrorCode')

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...
54
                 ->andReturn(100001);
55
        $exception = new ResponseException($response);
0 ignored issues
show
Bug introduced by
$response of type Mockery\MockInterface is incompatible with the type Graze\Gigya\Response\ResponseInterface expected by parameter $response of Graze\Gigya\Exception\Re...xception::__construct(). ( Ignorable by Annotation )

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

55
        $exception = new ResponseException(/** @scrutinizer ignore-type */ $response);
Loading history...
56
57
        static::assertSame($response, $exception->getResponse());
58
    }
59
}
60