ImporterTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 74
rs 10
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testCreateServicesFetcher() 0 7 1
A testCreateServicesMapper() 0 7 1
A testImportKeyNotString() 0 6 1
A testImportKeyContainsInvalidCharacters() 0 5 1
A testGetImporterKey() 0 4 1
A testImportKeyNotEmpty() 0 5 1
A testCanConstruct() 0 4 1
1
<?php
2
3
namespace Dynamic\Salsify\Tests\Model\Mapper;
4
5
use Dynamic\Salsify\Model\Fetcher;
6
use Dynamic\Salsify\Model\Importer;
7
use Dynamic\Salsify\Model\Mapper;
8
use InvalidArgumentException;
9
use SilverStripe\Core\Injector\Injector;
10
use SilverStripe\Dev\SapphireTest;
11
12
/**
13
 * Class ImporterTest
14
 * @package Dynamic\Salsify\Tests\Model\Mapper
15
 */
16
class ImporterTest extends SapphireTest
17
{
18
19
    /**
20
     *
21
     */
22
    public function testCanConstruct()
23
    {
24
        $importer = new Importer('test');
25
        $this->assertInstanceOf(Importer::class, $importer);
26
    }
27
28
    /**
29
     *
30
     */
31
    public function testGetImporterKey()
32
    {
33
        $importer = new Importer('test');
34
        $this->assertEquals('test', $importer->getImporterKey());
35
    }
36
37
    /**
38
     *
39
     */
40
    public function testImportKeyNotString()
41
    {
42
        $importer = new Importer('test');
43
        $this->expectException(InvalidArgumentException::class);
44
        /** @noinspection PhpParamsInspection */
45
        $importer->setImporterKey(array());
0 ignored issues
show
Bug introduced by
array() of type array is incompatible with the type string expected by parameter $importerKey of Dynamic\Salsify\Model\Importer::setImporterKey(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

45
        $importer->setImporterKey(/** @scrutinizer ignore-type */ array());
Loading history...
46
    }
47
48
    /**
49
     *
50
     */
51
    public function testImportKeyNotEmpty()
52
    {
53
        $importer = new Importer('test');
54
        $this->expectException(InvalidArgumentException::class);
55
        $importer->setImporterKey('');
56
    }
57
58
    /**
59
     *
60
     */
61
    public function testImportKeyContainsInvalidCharacters()
62
    {
63
        $importer = new Importer('test');
64
        $this->expectException(InvalidArgumentException::class);
65
        $importer->setImporterKey('test@');
66
    }
67
68
    /**
69
     *
70
     */
71
    public function testCreateServicesFetcher()
72
    {
73
        $this->assertFalse(Injector::inst()->has(Fetcher::class . '.test'));
74
75
        $importer = new Importer('test');
76
        $importer->createServices();
77
        $this->assertTrue(Injector::inst()->has(Fetcher::class . '.test'));
78
    }
79
80
    /**
81
     *
82
     */
83
    public function testCreateServicesMapper()
84
    {
85
        $this->assertFalse(Injector::inst()->has(Mapper::class . '.test'));
86
87
        $importer = new Importer('test');
88
        $importer->createServices();
89
        $this->assertTrue(Injector::inst()->has(Mapper::class . '.test'));
90
    }
91
}
92