OneSignalServiceTest::testMissingEnv2()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
namespace Level51\OneSignal;
4
5
use SilverStripe\Core\Config\Config;
6
use SilverStripe\Core\Environment;
7
use SilverStripe\Dev\SapphireTest;
8
9
class OneSignalServiceTest extends SapphireTest
10
{
11
12
    protected function setUp()
13
    {
14
        parent::setUp();
15
16
        Environment::setEnv('ONESIGNAL_APP_AUTH_KEY', 'foo');
17
        Environment::setEnv('ONESIGNAL_AUTH_KEY', 'bar');
18
        Config::forClass(OneSignalService::class)->set('app_id', 'xyz');
19
    }
20
21
    public function testMissingEnv1()
22
    {
23
        $this->expectException(OneSignalException::class);
24
25
        Environment::setEnv('ONESIGNAL_APP_AUTH_KEY', null);
26
        OneSignalService::create();
27
    }
28
29
    public function testMissingEnv2()
30
    {
31
        $this->expectException(OneSignalException::class);
32
33
        Environment::setEnv('ONESIGNAL_AUTH_KEY', null);
34
        OneSignalService::create();
35
    }
36
37
    public function testMissingConfig()
38
    {
39
        $this->expectException(OneSignalException::class);
40
41
        Config::forClass(OneSignalService::class)->remove('app_id');
42
        OneSignalService::create();
43
    }
44
45
    public function testCreateNotificationError()
46
    {
47
        $response = OneSignalService::singleton()->createNotification(Notification::create());
48
49
        $this->assertTrue($response->isError());
50
    }
51
}
52