Passed
Branch master (c73d10)
by Stefan
02:51 queued 55s
created

PNSubscriptionTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 25
dl 0
loc 39
rs 10
c 1
b 0
f 1
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A test_getOrigin() 0 3 1
A test_set() 0 15 1
A test_isValid() 0 13 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace SKien\Test\PNServer;
5
6
use PHPUnit\Framework\TestCase;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use SKien\PNServer\PNSubscription;
8
9
/**
10
 * @author Stefanius <[email protected]>
11
 * @copyright MIT License - see the LICENSE file for details
12
 */
13
class PNSubscriptionTest extends TestCase
14
{
15
    use TestHelperTrait;
16
    
17
    public function test_isValid() : void
18
    {
19
        $sub = PNSubscription::fromJSON($this->loadSubscription('expired_subscription.json'));
20
        $this->assertFalse($sub->isValid());
21
        $this->assertTrue($sub->isExpired());
22
        $sub->setExpiration(time() + 3600);
23
        $this->assertTrue($sub->isValid());
24
        $this->assertFalse($sub->isExpired());
25
        
26
        $sub->setEncoding('aes128gcm');
27
        $this->assertTrue($sub->isValid());
28
        $sub->setEncoding('aes256gcm');
29
        $this->assertFalse($sub->isValid());
30
    }
31
    
32
    public function test_set() : void
33
    {
34
        $sub = new PNSubscription('', '', '');
35
36
        $sub->setEndpoint(VALID_ENDPOINT);
0 ignored issues
show
Bug introduced by
The constant SKien\Test\PNServer\VALID_ENDPOINT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
37
        $this->assertFalse($sub->isValid());
38
        $sub->setPublicKey(VALID_P256H);
0 ignored issues
show
Bug introduced by
The constant SKien\Test\PNServer\VALID_P256H was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
39
        $this->assertFalse($sub->isValid());
40
        $sub->setAuth(VALID_AUTH);
0 ignored issues
show
Bug introduced by
The constant SKien\Test\PNServer\VALID_AUTH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
41
        $this->assertTrue($sub->isValid());
42
        $this->assertFalse($sub->isExpired());
43
        $this->assertEquals(VALID_ENDPOINT, $sub->getEndpoint());
44
        $this->assertEquals(VALID_P256H, $sub->getPublicKey());
45
        $this->assertEquals(VALID_AUTH, $sub->getAuth());
46
        $this->assertEquals('aesgcm', $sub->getEncoding());
47
    }
48
    
49
    public function test_getOrigin() : void
50
    {
51
        $this->assertEquals('https://fcm.googleapis.com', PNSubscription::getOrigin(VALID_ENDPOINT));
0 ignored issues
show
Bug introduced by
The constant SKien\Test\PNServer\VALID_ENDPOINT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
52
    }
53
}
54
55