Completed
Push — master ( 020c5c...9dbce5 )
by Julián
08:49
created

ServiceTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testAccesorsMutators() 0 18 1
A setUp() 0 7 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->getMock(Notification::class, [], [], '', false)
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

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

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

Loading history...
32
        );
33
    }
34
35
    public function testAccesorsMutators()
36
    {
37
        $service = new Service;
38
39
        self::assertEmpty($service->getNotifications());
40
        $service->addNotification($this->getMock(Notification::class, [], [], '', false));
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

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

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

Loading history...
41
        self::assertCount(1, $service->getNotifications());
42
43
        $service->clearNotifications();
44
        self::assertCount(0, $service->getNotifications());
45
46
        self::assertEmpty($service->getAdapters());
47
        $service->addAdapter($this->getMock(GcmAdapter::class, [], [], '', false));
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

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

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

Loading history...
48
        self::assertCount(1, $service->getAdapters());
49
50
        $service->clearAdapters();
51
        self::assertCount(0, $service->getAdapters());
52
    }
53
54
    public function testSend()
55
    {
56
        $result = new Result('aaa', new \DateTime('now', new \DateTimeZone('UTC')));
57
58
        $adapter = $this->getMock(GcmAdapter::class, [], [], '', false);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

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

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

Loading history...
59
        $adapter->expects(self::once())->method('push')->will(self::returnValue([$result]));
60
        $this->service->addAdapter($adapter);
61
62
        $message = $this->getMock(Message::class, [], [], '', false);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

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

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

Loading history...
63
        $notification = $this->getMock(Notification::class, [], [$message, []]);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

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

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

Loading history...
64
        $this->service->clearNotifications();
65
        $this->service->addNotification($notification);
66
67
        $results = $this->service->push();
68
        self::assertCount(1, $results);
69
        self::assertEquals($result, $results[0]);
70
    }
71
72
    public function testFeedback()
73
    {
74
        $result = new Result('aaa', new \DateTime('now', new \DateTimeZone('UTC')));
75
76
        $adapter = $this->getMock(ApnsAdapter::class, [], [], '', false);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

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

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

Loading history...
77
        $adapter->expects(self::once())->method('feedback')->will(self::returnValue([$result]));
78
        $this->service->addAdapter($adapter);
79
80
        $results = $this->service->feedback();
81
        self::assertCount(1, $results);
82
        self::assertEquals($result, $results[0]);
83
    }
84
}
85