Completed
Push — master ( e46808...b698dc )
by Julián
02:11
created

Pusher/Controller/NotificationControllerTest.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Push notification server example (http://github.com/juliangut/tify_example)
4
 *
5
 * @link https://github.com/juliangut/tify_example for the canonical source repository
6
 *
7
 * @license https://github.com/juliangut/tify_example/blob/master/LICENSE
8
 */
9
10
namespace Jgut\Pusher\Tests\Entity;
11
12
use Jgut\Pusher\Controller\NotificationController;
13
use Jgut\Pusher\Entity\DeviceEntity;
14
use Jgut\Pusher\Repository\DeviceRepository;
15
use Jgut\Tify\Service;
16
use Psr\Http\Message\ServerRequestInterface;
17
use Slim\Http\Response;
18
19
/**
20
 * Class NotificationControllerTest
21
 */
22
class NotificationControllerTest extends \PHPUnit_Framework_TestCase
23
{
24
    public function testNoDevices()
25
    {
26
        $repository = $this->getMock(DeviceRepository::class, [], [], '', false);
27
        $repository->expects(self::once())->method('findAll')->will(self::returnValue(null));
28
29
        $service = $this->getMock(Service::class, [], [], '', null);
0 ignored issues
show
null is of type null, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
30
        $service->expects(self::once())->method('push')->will(self::returnValue([]));
31
32
        $controller = new NotificationController($repository, $service);
33
34
        $parameters = [
35
            'title' => 'Title',
36
            'body' => 'Body',
37
            'data' => [
38
                'param1' => 'value1',
39
            ],
40
        ];
41
        $request = $this->getMock(ServerRequestInterface::class, [], [], '', false);
42
        $request->expects(self::once())->method('getParsedBody')->will(self::returnValue($parameters));
43
44
        /** @var Response $response */
45
        $response = $controller->send($request, new Response());
46
47
        self::assertEquals(
48
            json_encode([]),
49
            (string) $response->getBody()
50
        );
51
    }
52
53
    public function testSend()
54
    {
55
        $devices = [
56
            (new DeviceEntity())->setToken('aaaa')->setPlatform('android'),
57
            (new DeviceEntity())
58
                ->setToken('0000000000000000000000000000000000000000000000000000000000000000')
59
                ->setPlatform('ios'),
60
            new DeviceEntity(),
61
        ];
62
63
        $repository = $this->getMock(DeviceRepository::class, [], [], '', false);
64
        $repository->expects(self::once())->method('findBy')->will(self::returnValue($devices));
65
66
        $service = $this->getMock(Service::class, [], [], '', null);
0 ignored issues
show
null is of type null, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
67
        $service->expects(self::once())->method('push')->will(self::returnValue([]));
68
69
        $controller = new NotificationController($repository, $service);
70
71
        $parameters = [
72
            'title' => 'Title',
73
            'body' => 'Body',
74
            'platform' => 'android',
75
            'data' => [
76
                'param1' => 'value1',
77
            ],
78
        ];
79
        $request = $this->getMock(ServerRequestInterface::class, [], [], '', false);
80
        $request->expects(self::once())->method('getParsedBody')->will(self::returnValue($parameters));
81
82
        /** @var Response $response */
83
        $response = $controller->send($request, new Response());
84
85
        self::assertEquals(
86
            json_encode([]),
87
            (string) $response->getBody()
88
        );
89
    }
90
}
91