Some checks failed
abc-api/abcParser/pipeline/head There was a failure building this commit
219 lines
5.4 KiB
PHP
Executable File
219 lines
5.4 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: richard
|
|
* Date: 11/19/17
|
|
* Time: 10:09 PM
|
|
*/
|
|
|
|
namespace Tests\Unit\AbcParser\Domain\Core;
|
|
|
|
use Enzyme\Axiom\Atoms\StringAtom;
|
|
use PHPUnit_Framework_TestCase;
|
|
use Webpatser\Uuid\Uuid;
|
|
use XaiCorp\AbcParser\Domain\Atoms\EmailAtom;
|
|
use XaiCorp\AbcParser\Domain\Atoms\UnsignedIntegerAtom;
|
|
use XaiCorp\AbcParser\Domain\Core\Author;
|
|
use XaiCorp\AbcParser\Domain\Core\Composer;
|
|
use XaiCorp\AbcParser\Domain\Core\Setting;
|
|
use XaiCorp\AbcParser\Domain\Core\Tune;
|
|
use XaiCorp\AbcParser\Domain\Core\TuneAttributeArrayBuilder;
|
|
|
|
class TuneTest extends PHPUnit_Framework_TestCase
|
|
{
|
|
public function testCreate()
|
|
{
|
|
$params = [];
|
|
|
|
$tune = new Tune($params);
|
|
|
|
$this->assertInstanceOf(Tune::class, $tune);
|
|
}
|
|
|
|
public function testCanInitializeFromArray()
|
|
{
|
|
$titles = ['Title'];
|
|
$authors = ['Richard Morgan'];
|
|
|
|
$tune = TuneAttributeArrayBuilder::create()
|
|
->addTitle($titles[0])
|
|
->addAuthor($authors[0])
|
|
->getTune();
|
|
|
|
$this->assertInstanceOf(Tune::class, $tune);
|
|
$this->assertEquals($tune->getTitles(), $titles);
|
|
}
|
|
|
|
public function testNewTuneHasIdentitySet()
|
|
{
|
|
$params = [];
|
|
|
|
$tune = new Tune($params);
|
|
|
|
$result = $tune->identity();
|
|
|
|
$this->assertInstanceOf(Uuid::class, $result);
|
|
}
|
|
|
|
public function testGetIndexReturnsInteger1AsDefault()
|
|
{
|
|
$tune = new Tune([]);
|
|
|
|
$result = $tune->getIndex();
|
|
|
|
$this->assertIsInt($result);
|
|
$this->assertEquals(1, $result);
|
|
}
|
|
|
|
public function testSetIndex()
|
|
{
|
|
$value = 12;
|
|
$tune = new Tune([]);
|
|
$tune->setIndex(new UnsignedIntegerAtom($value));
|
|
|
|
$result = $tune->getIndex();
|
|
|
|
$this->assertEquals($value, $result);
|
|
}
|
|
|
|
public function testGetTitlesIsEmptyOnNewTune()
|
|
{
|
|
$tune = new Tune([]);
|
|
|
|
$result = $tune->getTitles();
|
|
|
|
$this->assertEmpty($result);
|
|
}
|
|
|
|
public function testAppendTitleAddsOneTitle()
|
|
{
|
|
$newTitle = 'New Title';
|
|
$tune = new Tune([]);
|
|
$tune->addTitle($newTitle);
|
|
|
|
$result = $tune->getTitles();
|
|
|
|
$this->assertNotEmpty($result);
|
|
$this->assertEquals($newTitle, $result[0]);
|
|
}
|
|
|
|
public function testAddAuthor()
|
|
{
|
|
$authorName = new StringAtom('Bob');
|
|
$authorEmail = new EmailAtom('me@example.com');
|
|
$author = new Author($authorName, $authorEmail);
|
|
$tune = new Tune([]);
|
|
$tune->addAuthor($author);
|
|
|
|
$result = $tune->getAuthors();
|
|
|
|
$this->assertNotEmpty($result);
|
|
$this->assertEquals($author, $result[0]);
|
|
}
|
|
|
|
public function testAddComposer()
|
|
{
|
|
$composerName = new StringAtom('Bob');
|
|
$authorEmail = new EmailAtom('me@example.com');
|
|
$composer = new Composer($composerName, $authorEmail);
|
|
$tune = new Tune([]);
|
|
$tune->addComposer($composer);
|
|
|
|
$result = $tune->getComposers();
|
|
|
|
$this->assertNotEmpty($result);
|
|
$this->assertEquals($composer, $result[0]);
|
|
}
|
|
|
|
public function testAddGroup()
|
|
{
|
|
$group = 'flutes';
|
|
$tune = new Tune([]);
|
|
$tune->addGroup($group);
|
|
|
|
$result = $tune->getGroups();
|
|
|
|
$this->assertNotEmpty($result);
|
|
$this->assertEquals($group, $result[0]);
|
|
}
|
|
|
|
public function testAddHistoryLine()
|
|
{
|
|
$historyLine = 'The works of Shakespeare';
|
|
$tune = new Tune([]);
|
|
$tune->addHistoryLine($historyLine);
|
|
|
|
$result = $tune->getHistory();
|
|
|
|
$this->assertNotEmpty($result);
|
|
$this->assertEquals($historyLine, $result[0]);
|
|
}
|
|
|
|
public function testAddOrigin()
|
|
{
|
|
$origin = 'Yorkshire';
|
|
$tune = new Tune([]);
|
|
$tune->addOrigin($origin);
|
|
|
|
$result = $tune->getOrigins();
|
|
|
|
$this->assertNotEmpty($result);
|
|
$this->assertEquals($origin, $result[0]);
|
|
}
|
|
|
|
public function testAddRhythm()
|
|
{
|
|
$rhythm = 'reel';
|
|
$tune = new Tune([]);
|
|
$tune->addRhythm($rhythm);
|
|
|
|
$result = $tune->getRhythms();
|
|
|
|
$this->assertNotEmpty($result);
|
|
$this->assertEquals($rhythm, $result[0]);
|
|
}
|
|
|
|
public function testSetting()
|
|
{
|
|
$setting = new Setting();
|
|
$tune = new Tune([]);
|
|
$tune->addSetting($setting);
|
|
|
|
$result = $tune->getSettings();
|
|
|
|
$this->assertNotEmpty($result);
|
|
$this->assertEquals($setting, $result[0]);
|
|
}
|
|
|
|
public function testMergeAddsExtraDataToTune()
|
|
{
|
|
$targetTune = TuneAttributeArrayBuilder::create()
|
|
->addTitle('target')
|
|
->appendMusic('|:BAG BAG|')
|
|
->getTune();
|
|
|
|
$sourceTune = TuneAttributeArrayBuilder::create()
|
|
->addTitle('source')
|
|
->appendMusic('|:GAB GAB|')
|
|
->addAuthor('a.non')
|
|
->addComposer('composer')
|
|
->addHistory('some story')
|
|
->getTune();
|
|
|
|
$expected = TuneAttributeArrayBuilder::create()
|
|
->addTitle('target')
|
|
->addTitle('source')
|
|
->appendMusic('|:BAG BAG|')
|
|
->handleEndOfMusic()
|
|
->appendMusic('|:GAB GAB|')
|
|
->addAuthor('a.non')
|
|
->addComposer('composer')
|
|
->addHistory('some story')
|
|
->getTune($targetTune->identity());
|
|
|
|
$result = $targetTune->merge($sourceTune);
|
|
|
|
$this->assertTrue($expected->equals($result));
|
|
}
|
|
}
|