PwaTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 34
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A testPushSubscription() 0 25 1
1
<?php
2
3
namespace LeKoala\SsPwa\Test;
4
5
use LeKoala\SsPwa\PushSubscription;
6
use Minishlink\WebPush\Subscription;
7
use SilverStripe\Dev\SapphireTest;
8
9
class PwaTest extends SapphireTest
10
{
11
12
    /**
13
     * Defines the fixture file to use for this test class
14
     * @var string
15
     */
16
    protected static $fixture_file = 'PwaTest.yml';
17
18
    public function testPushSubscription()
19
    {
20
        $data = [
21
            "endpoint" => "https://fcm.googleapis.com/fcm/send/dOG8e0uSfnA:APA91bHpydJQ-3nE0tk....",
22
            "expirationTime" => null,
23
            "keys" => [
24
                "auth" => "w6_GuDO7Jf-qEKV...",
25
                "p256dh" => "BK1xht_jA4BFaIpOFyfGCuMLbCtdY8G7v4uZ5jUzsLO_ZgAwI....",
26
            ]
27
        ];
28
        $sub = PushSubscription::createNew($data);
29
30
        $this->assertInstanceOf(PushSubscription::class, $sub);
31
        $this->assertEquals($data['endpoint'], $sub->Endpoint);
32
33
        $payload = ['data' => 'demo'];
34
35
        $pushSub = $sub->createSubscription($payload);
0 ignored issues
show
Unused Code introduced by
The call to LeKoala\SsPwa\PushSubscr...n::createSubscription() has too many arguments starting with $payload. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

35
        /** @scrutinizer ignore-call */ 
36
        $pushSub = $sub->createSubscription($payload);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
36
        $this->assertInstanceOf(Subscription::class, $pushSub);
37
38
        $byEndpoint = PushSubscription::getByEndpoint($sub->Endpoint);
39
        $this->assertEquals($byEndpoint->ID, $sub->ID);
40
41
        PushSubscription::deleteEndpoint($sub->Endpoint);
42
        $this->assertTrue(PushSubscription::get()->count() === 0);
43
    }
44
}
45