PagerDutyNotificationTypeTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 1
cbo 6
dl 0
loc 101
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 14 1
A testNotifyCreate() 0 52 1
A testNotifyUpdate() 0 3 1
1
<?php
2
3
namespace TonicHealthCheck\Test\Incident\Siren\NotificationType;
4
5
use PHPUnit_Framework_MockObject_MockObject;
6
use PHPUnit_Framework_TestCase;
7
use TonicForHealth\PagerDutyClient\Client\EventClient;
8
use TonicForHealth\PagerDutyClient\Entity\Event\Event;
9
use TonicHealthCheck\Incident\IncidentInterface;
10
use TonicHealthCheck\Incident\Siren\NotificationType\PagerDutyNotificationType;
11
use TonicHealthCheck\Test\Incident\IncidentCreateTrait;
12
use TonicHealthCheck\Test\Incident\Subject\SubjectCreateTrait;
13
14
/**
15
 * Class RequestNotificationTypeTest.
16
 */
17
class PagerDutyNotificationTypeTest extends PHPUnit_Framework_TestCase
18
{
19
    use SubjectCreateTrait;
20
    use IncidentCreateTrait;
21
22
    /**
23
     * @var PHPUnit_Framework_MockObject_MockObject|EventClient
24
     */
25
    protected $eventClientMock;
26
27
    /**
28
     * @var PagerDutyNotificationType;
29
     */
30
    protected $pagerDutyNType;
31
32
    /**
33
     * @var string
34
     */
35
    protected $serviceKey;
36
37
    /**
38
     * set up base env Request type test.
39
     */
40
    public function setUp()
41
    {
42
        $this->serviceKey = '5b2fb01f1f2257dbbde64469977261de';
43
44
        $this->eventClientMock = $this
45
            ->getMockBuilder(EventClient::class)
46
            ->disableOriginalConstructor()
47
            ->getMock();
48
49
        $this->pagerDutyNType = new PagerDutyNotificationType(
50
            $this->eventClientMock,
51
            $this->serviceKey
52
        );
53
    }
54
55
    /**
56
     * Test request notify create.
57
     */
58
    public function testNotifyCreate()
59
    {
60
        self::assertEquals($this->serviceKey, $this->pagerDutyNType->getServiceKey());
61
62
        $incident = $this->createIncidentMock();
63
64
        $incident
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in TonicHealthCheck\Incident\IncidentInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
65
            ->expects(self::any())
66
            ->method('getStatus')
67
            ->willReturn(IncidentInterface::STATUS_OK + 1);
68
69
        $incidentOk = $this->createIncidentMock();
70
71
        $incidentOk
72
            ->expects(self::any())
73
            ->method('getStatus')
74
            ->willReturn(IncidentInterface::STATUS_OK);
75
76
        $subject = $this->createSubject('target', '* * * * *');
77
78
        $event = new Event();
79
        $event->serviceKey = $this->serviceKey;
80
        $event->description = $incident->getIdent();
0 ignored issues
show
Bug introduced by
The method getIdent does only exist in TonicHealthCheck\Incident\IncidentInterface, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
81
        $event->incidentKey = 'hci_0';
82
        $event->details = [
83
            'log' => $incident->getMessage(),
0 ignored issues
show
Bug introduced by
The method getMessage does only exist in TonicHealthCheck\Incident\IncidentInterface, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
84
            'status' => $incident->getStatus(),
0 ignored issues
show
Bug introduced by
The method getStatus does only exist in TonicHealthCheck\Incident\IncidentInterface, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
85
            'type' => $incident->getType(),
0 ignored issues
show
Bug introduced by
The method getType does only exist in TonicHealthCheck\Incident\IncidentInterface, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
86
            'id' => $incident->getId(),
0 ignored issues
show
Bug introduced by
The method getId does only exist in TonicHealthCheck\Incident\IncidentInterface, but not in PHPUnit_Framework_MockObject_MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
87
        ];
88
89
        $this->eventClientMock
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in TonicForHealth\PagerDutyClient\Client\EventClient.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
90
            ->expects(self::at(0))
91
            ->method('post')
92
            ->with($event);
93
94
        $event2 = clone $event;
95
        $event2->details = null;
96
        $event2->description = null;
97
        $event2->eventType = Event::EVENT_TYPE_RESOLVE;
98
99
        $this->eventClientMock
100
            ->expects(self::at(1))
101
            ->method('post')
102
            ->with($event2);
103
104
105
106
        $this->pagerDutyNType->notify($subject, $incident);
0 ignored issues
show
Bug introduced by
It seems like $incident defined by $this->createIncidentMock() on line 62 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, TonicHealthCheck\Inciden...ificationType::notify() does only seem to accept object<TonicHealthCheck\...dent\IncidentInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
107
        $this->pagerDutyNType->notify($subject, $incidentOk);
0 ignored issues
show
Bug introduced by
It seems like $incidentOk defined by $this->createIncidentMock() on line 69 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, TonicHealthCheck\Inciden...ificationType::notify() does only seem to accept object<TonicHealthCheck\...dent\IncidentInterface>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
108
109
    }
110
111
    /**
112
     * Test request notify update.
113
     */
114
    public function testNotifyUpdate()
115
    {
116
    }
117
}
118