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
![]() |
|||
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 |