ServiceTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 69
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A testAccesorsMutators() 0 22 1
A testSend() 0 17 1
A testFeedback() 0 12 1
1
<?php
2
/**
3
 * Push notification services abstraction (http://github.com/juliangut/tify)
4
 *
5
 * @link https://github.com/juliangut/tify for the canonical source repository
6
 *
7
 * @license https://github.com/juliangut/tify/blob/master/LICENSE
8
 */
9
10
namespace Jgut\Tify\Tests;
11
12
use Jgut\Tify\Adapter\AbstractAdapter;
13
use Jgut\Tify\Adapter\Apns\ApnsAdapter;
14
use Jgut\Tify\Adapter\Gcm\GcmAdapter;
15
use Jgut\Tify\Message;
16
use Jgut\Tify\Notification;
17
use Jgut\Tify\Result;
18
use Jgut\Tify\Service;
19
20
class ServiceTest extends \PHPUnit_Framework_TestCase
21
{
22
    /**
23
     * @var \Jgut\Tify\Service
24
     */
25
    protected $service;
26
27
    public function setUp()
28
    {
29
        $this->service = new Service(
30
            $this->getMockForAbstractClass(AbstractAdapter::class, [], '', false),
31
            $this->getMockBuilder(Notification::class)->disableOriginalConstructor()->getMock()
32
        );
33
    }
34
35
    public function testAccesorsMutators()
36
    {
37
        $service = new Service;
38
39
        self::assertEmpty($service->getNotifications());
40
        $service->addNotification(
41
            $this->getMockBuilder(Notification::class)->disableOriginalConstructor()->getMock()
42
        );
43
        self::assertCount(1, $service->getNotifications());
44
45
        $service->clearNotifications();
46
        self::assertCount(0, $service->getNotifications());
47
48
        self::assertEmpty($service->getAdapters());
49
        $service->addAdapter(
50
            $this->getMockBuilder(GcmAdapter::class)->disableOriginalConstructor()->getMock()
51
        );
52
        self::assertCount(1, $service->getAdapters());
53
54
        $service->clearAdapters();
55
        self::assertCount(0, $service->getAdapters());
56
    }
57
58
    public function testSend()
59
    {
60
        $result = new Result('aaa', new \DateTime('now', new \DateTimeZone('UTC')));
61
62
        $adapter = $this->getMockBuilder(GcmAdapter::class)->disableOriginalConstructor()->getMock();
63
        $adapter->expects(self::once())->method('push')->will(self::returnValue([$result]));
64
        $this->service->addAdapter($adapter);
65
66
        $message = $this->getMockBuilder(Message::class)->disableOriginalConstructor()->getMock();
0 ignored issues
show
Unused Code introduced by
$message is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
67
        $notification = $this->getMockBuilder(Notification::class)->disableOriginalConstructor()->getMock();
68
        $this->service->clearNotifications();
69
        $this->service->addNotification($notification);
70
71
        $results = $this->service->push();
72
        self::assertCount(1, $results);
73
        self::assertEquals($result, $results[0]);
74
    }
75
76
    public function testFeedback()
77
    {
78
        $result = new Result('aaa', new \DateTime('now', new \DateTimeZone('UTC')));
79
80
        $adapter = $this->getMockBuilder(ApnsAdapter::class)->disableOriginalConstructor()->getMock();
81
        $adapter->expects(self::once())->method('feedback')->will(self::returnValue([$result]));
82
        $this->service->addAdapter($adapter);
83
84
        $results = $this->service->feedback();
85
        self::assertCount(1, $results);
86
        self::assertEquals($result, $results[0]);
87
    }
88
}
89