-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added test for importer class
- Loading branch information
Showing
1 changed file
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
namespace Dynamic\Salsify\Tests\Model\Mapper; | ||
|
||
use Dynamic\Salsify\Model\Fetcher; | ||
use Dynamic\Salsify\Model\Importer; | ||
use Dynamic\Salsify\Model\Mapper; | ||
use InvalidArgumentException; | ||
use SilverStripe\Core\Injector\Injector; | ||
use SilverStripe\Dev\SapphireTest; | ||
|
||
/** | ||
* Class ImporterTest | ||
* @package Dynamic\Salsify\Tests\Model\Mapper | ||
*/ | ||
class ImporterTest extends SapphireTest | ||
{ | ||
|
||
/** | ||
* | ||
*/ | ||
public function testCanConstruct() | ||
{ | ||
$importer = new Importer('test'); | ||
$this->assertInstanceOf(Importer::class, $importer); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public function testGetImporterKey() | ||
{ | ||
$importer = new Importer('test'); | ||
$this->assertEquals('test', $importer->getImporterKey()); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public function testImportKeyNotString() | ||
{ | ||
$importer = new Importer('test'); | ||
$this->expectException(InvalidArgumentException::class); | ||
/** @noinspection PhpParamsInspection */ | ||
$importer->setImporterKey(array()); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public function testImportKeyNotEmpty() | ||
{ | ||
$importer = new Importer('test'); | ||
$this->expectException(InvalidArgumentException::class); | ||
$importer->setImporterKey(''); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public function testImportKeyContainsInvalidCharacters() | ||
{ | ||
$importer = new Importer('test'); | ||
$this->expectException(InvalidArgumentException::class); | ||
$importer->setImporterKey('test@'); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public function testCreateServicesFetcher() | ||
{ | ||
$this->assertFalse(Injector::inst()->has(Fetcher::class . '.test')); | ||
|
||
$importer = new Importer('test'); | ||
$importer->createServices(); | ||
$this->assertTrue(Injector::inst()->has(Fetcher::class . '.test')); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public function testCreateServicesMapper() | ||
{ | ||
$this->assertFalse(Injector::inst()->has(Mapper::class . '.test')); | ||
|
||
$importer = new Importer('test'); | ||
$importer->createServices(); | ||
$this->assertTrue(Injector::inst()->has(Mapper::class . '.test')); | ||
} | ||
} |