Passed
Pull Request — master (#14)
by Matthew
01:37
created

testImportKeyContainsInvalidCharacters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Dynamic\Salsify\Tests\Model\Mapper;
4
5
use Dynamic\Salsify\Model\Fetcher;
6
use Dynamic\Salsify\Model\Mapper;
7
use \InvalidArgumentException;
8
use Dynamic\Salsify\Model\Importer;
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
        $importer = new Importer('test');
24
        $this->assertInstanceOf(Importer::class, $importer);
25
    }
26
27
    /**
28
     *
29
     */
30
    public function testGetImporterKey() {
31
        $importer = new Importer('test');
32
        $this->assertEquals('test', $importer->getImporterKey());
33
    }
34
35
    /**
36
     *
37
     */
38
    public function testImportKeyNotString() {
39
        $importer = new Importer('test');
40
        $this->expectException(InvalidArgumentException::class);
41
        /** @noinspection PhpParamsInspection */
42
        $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

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