FetcherTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 46
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testConstructor() 0 7 1
A setUp() 0 4 1
A testConstructorFailsWithoutChannel() 0 5 1
A testConstructorFailsWithoutAPIKey() 0 4 1
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