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

ServiceTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
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