FetcherTest::testConstructorFailsWithoutChannel()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Dynamic\Salsify\Tests\Model\Mapper;
4
5
use Exception;
6
use Dynamic\Salsify\Model\Fetcher;
7
use SilverStripe\Core\Config\Config;
8
use SilverStripe\Dev\SapphireTest;
9
10
/**
11
 * Class FetcherTest
12
 * @package Dynamic\Salsify\Tests\Model\Mapper
13
 */
14
class FetcherTest extends SapphireTest
15
{
16
17
    /**
18
     * @var string
19
     */
20
    private $importerKey = 'test';
21
22
    /**
23
     *
24
     */
25
    public function setUp()
26
    {
27
        Config::modify()->remove(Fetcher::class, 'apiKey');
28
        return parent::setUp();
29
    }
30
31
    /**
32
     * @throws Exception
33
     */
34
    public function testConstructorFailsWithoutAPIKey()
35
    {
36
        $this->expectException(Exception::class);
37
        new Fetcher($this->importerKey);
38
    }
39
40
    /**
41
     * @throws Exception
42
     */
43
    public function testConstructorFailsWithoutChannel()
44
    {
45
        Config::modify()->set(Fetcher::class, 'apiKey', 'API_KEY');
46
        $this->expectException(Exception::class);
47
        new Fetcher($this->importerKey);
48
    }
49
50
    /**
51
     * @throws Exception
52
     */
53
    public function testConstructor()
54
    {
55
        Config::modify()->set(Fetcher::class . '.' . $this->importerKey, 'apiKey', 'API_KEY');
56
        Config::modify()->set(Fetcher::class . '.' . $this->importerKey, 'channel', 'CHANNEL');
57
58
        $fetcher = new Fetcher($this->importerKey);
59
        $this->assertInstanceOf(Fetcher::class, $fetcher);
60
    }
61
}
62