Skip to content

Commit

Permalink
Tests/importer (#14)
Browse files Browse the repository at this point in the history
* Added test for importer class
  • Loading branch information
mak001 authored Jul 22, 2019
1 parent f2a5899 commit f7ab316
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions tests/Model/ImporterTest.php
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'));
}
}

0 comments on commit f7ab316

Please sign in to comment.