AuthorizationTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 33
c 1
b 0
f 0
dl 0
loc 71
rs 10
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testUnsupportedProtocol() 0 7 1
A getPingHandlerMock() 0 13 1
A testAccessDenied() 0 7 1
A testApiFailedToRespond() 0 5 1
A testUnsupportedHttpMethod() 0 7 1
A testNoAuthorization() 0 7 1
A testActionNotFound() 0 7 1
1
<?php
2
/**
3
 * File: AuthorizationTest.php
4
 *
5
 * @author      Maciej Sławik <[email protected]>
6
 * Github:      https://github.com/maciejslawik
7
 */
8
9
namespace MSlwk\FreshMail\Test\Base;
10
11
use MSlwk\FreshMail\Exception\Authorization\FreshMailAuthorizationException;
12
use MSlwk\FreshMail\Exception\Connection\FreshMailConnectionException;
13
use PHPUnit\Framework\TestCase;
14
use MSlwk\FreshMail\Error\ErrorHandler;
15
16
/**
17
 * Class AuthorizationTest
18
 *
19
 * @package MSlwk\FreshMail\Test\Base
20
 */
21
class AuthorizationTest extends TestCase
22
{
23
    /**
24
     * @param $sendRequestReturnValue
25
     * @return \PHPUnit_Framework_MockObject_MockObject
0 ignored issues
show
Bug introduced by
The type PHPUnit_Framework_MockObject_MockObject was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
26
     */
27
    private function getPingHandlerMock($sendRequestReturnValue)
28
    {
29
        $pingHandler = $this->getMockBuilder('\MSlwk\FreshMail\Handler\Ping\PingHandler')
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\MockOb...ckBuilder::setMethods() has been deprecated: https://github.com/sebastianbergmann/phpunit/pull/3687 ( Ignorable by Annotation )

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

29
        $pingHandler = /** @scrutinizer ignore-deprecated */ $this->getMockBuilder('\MSlwk\FreshMail\Handler\Ping\PingHandler')

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
30
            ->setConstructorArgs([new ErrorHandler(), '', ''])
31
            ->setMethods(['sendRequest'])
32
            ->getMock();
33
34
        $pingHandler->expects($this->once())
35
            ->method('sendRequest')
36
            ->with('', '')
37
            ->will($this->returnValue($sendRequestReturnValue));
38
39
        return $pingHandler;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $pingHandler returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the documented return type PHPUnit_Framework_MockObject_MockObject.
Loading history...
40
    }
41
42
    public function testNoAuthorization()
43
    {
44
        $pingHandler = $this->getPingHandlerMock(
45
            '{"errors":[{ "message":"No authorization", "code":"1000" }], "status":"errors"}'
46
        );
47
        $this->expectException(FreshMailAuthorizationException::class);
48
        $pingHandler->ping();
49
    }
50
51
    public function testActionNotFound()
52
    {
53
        $pingHandler = $this->getPingHandlerMock(
54
            '{"errors":[{ "message":"Method not found", "code":"1001" }], "status":"errors"}'
55
        );
56
        $this->expectException(FreshMailAuthorizationException::class);
57
        $pingHandler->ping();
58
    }
59
60
    public function testUnsupportedProtocol()
61
    {
62
        $pingHandler = $this->getPingHandlerMock(
63
            '{"errors":[{ "message":"Protocol not supported", "code":"1002" }], "status":"errors"}'
64
        );
65
        $this->expectException(FreshMailAuthorizationException::class);
66
        $pingHandler->ping();
67
    }
68
69
    public function testUnsupportedHttpMethod()
70
    {
71
        $pingHandler = $this->getPingHandlerMock(
72
            '{"errors":[{ "message":"Unsupported request type", "code":"1003" }], "status":"errors"}'
73
        );
74
        $this->expectException(FreshMailAuthorizationException::class);
75
        $pingHandler->ping();
76
    }
77
78
    public function testAccessDenied()
79
    {
80
        $pingHandler = $this->getPingHandlerMock(
81
            '{"errors":[{ "message":"Access denied", "code":"1004" }], "status":"errors"}'
82
        );
83
        $this->expectException(FreshMailAuthorizationException::class);
84
        $pingHandler->ping();
85
    }
86
87
    public function testApiFailedToRespond()
88
    {
89
        $pingHandler = $this->getPingHandlerMock('');
90
        $this->expectException(FreshMailConnectionException::class);
91
        $pingHandler->ping();
92
    }
93
}
94