add ExtractTune use case
This commit is contained in:
29
tests/unit/AbcParser/Application/PersonFactoryTest.php
Normal file
29
tests/unit/AbcParser/Application/PersonFactoryTest.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
namespace Tests\Unit\AbcParser\Application;
|
||||
|
||||
use Enzyme\Axiom\Atoms\StringAtom;
|
||||
use XaiCorp\AbcParser\Application\PersonFactory;
|
||||
use XaiCorp\AbcParser\Domain\Atoms\EmailAtom;
|
||||
use XaiCorp\AbcParser\Domain\Core\Person;
|
||||
|
||||
class PersonFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$factory = new PersonFactory();
|
||||
|
||||
$this->assertInstanceOf(PersonFactory::class, $factory);
|
||||
}
|
||||
|
||||
public function testCreatePerson()
|
||||
{
|
||||
$factory = new PersonFactory();
|
||||
$name = new StringAtom('Roger');
|
||||
$email = new EmailAtom('');
|
||||
|
||||
$result = $factory->create($name, $email);
|
||||
|
||||
$this->assertInstanceOf(Person::class, $result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
use XaiCorp\AbcParser\Application\UseCases\ExtractTuneFromCollection;
|
||||
use XaiCorp\AbcParser\Application\UseCases\ImportAbcFile;
|
||||
|
||||
class ExtractTuneFromCollectionTest extends \Codeception\Test\Unit
|
||||
{
|
||||
/**
|
||||
* @param string $filename
|
||||
* @return bool|string
|
||||
*/
|
||||
private function getAbc($filename = '/abc/valid_abc_1.abc')
|
||||
{
|
||||
return file_get_contents(codecept_data_dir($filename));
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$abc = $this->getAbc();
|
||||
$tunes = ImportAbcFile::create()->import($abc);
|
||||
|
||||
$extractor = ExtractTuneFromCollection::create($tunes);
|
||||
|
||||
$this->assertInstanceOf(ExtractTuneFromCollection::class, $extractor);
|
||||
}
|
||||
|
||||
public function testExtractTuneByTitle()
|
||||
{
|
||||
$title = "Emmett's Hedgehog";
|
||||
|
||||
$abc = $this->getAbc('/abc/jigs.abc');
|
||||
$tunes = ImportAbcFile::create()->import($abc);
|
||||
|
||||
$extractor = ExtractTuneFromCollection::create($tunes);
|
||||
|
||||
$result = $extractor->extractTuneByTitle($title);
|
||||
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertNotEquals($tunes, $result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\AbcParser\Application\UseCases;
|
||||
|
||||
use XaiCorp\AbcParser\Application\UseCases\ImportAbcFile;
|
||||
use XaiCorp\AbcParser\Domain\Core\TuneCollection;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Builder;
|
||||
|
||||
class ImportAbcFileTest extends \Codeception\Test\Unit
|
||||
{
|
||||
|
||||
/**
|
||||
* @param string $filename
|
||||
* @return bool|string
|
||||
*/
|
||||
private function getAbc($filename = '/abc/valid_abc_1.abc')
|
||||
{
|
||||
return file_get_contents(codecept_data_dir($filename));
|
||||
}
|
||||
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$importer = ImportAbcFile::create();
|
||||
|
||||
$this->assertInstanceOf(ImportAbcFile::class, $importer);
|
||||
}
|
||||
|
||||
public function testCreateInjectingBuilder()
|
||||
{
|
||||
$builder = new Builder();
|
||||
$importer = ImportAbcFile::create($builder);
|
||||
|
||||
$this->assertInstanceOf(ImportAbcFile::class, $importer);
|
||||
}
|
||||
|
||||
public function testImport()
|
||||
{
|
||||
$abc = $this->getAbc('/abc/jigs.abc');
|
||||
$importer = ImportAbcFile::create();
|
||||
|
||||
$result = $importer->import($abc);
|
||||
|
||||
$this->assertInstanceOf(TuneCollection::class, $result);
|
||||
$this->assertGreaterThan(1, $result->count());
|
||||
}
|
||||
|
||||
public function testImport2FilesConsecutively()
|
||||
{
|
||||
$abc2 = $this->getAbc('/abc/valid_abc_2.abc');
|
||||
$abc3 = $this->getAbc('/abc/valid_abc_3.abc');
|
||||
$importer = ImportAbcFile::create();
|
||||
|
||||
$result1 = $importer->import($abc2);
|
||||
$result2 = $importer->import($abc3);
|
||||
|
||||
$this->assertNotEquals($result1, $result2);
|
||||
}
|
||||
|
||||
public function testImportMultiple()
|
||||
{
|
||||
$abc1 = $this->getAbc('/abc/valid_abc_1.abc');
|
||||
$abc2 = $this->getAbc('/abc/valid_abc_2.abc');
|
||||
$abc3 = $this->getAbc('/abc/valid_abc_3.abc');
|
||||
$importer = ImportAbcFile::create();
|
||||
|
||||
$result = $importer->importMultiple([$abc1, $abc2, $abc3]);
|
||||
|
||||
$this->assertInstanceOf(TuneCollection::class, $result);
|
||||
$this->assertGreaterThan(1, $result->count());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user