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
|
|||
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 |
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.