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->assertInternalType('integer', $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->assertEquals($expected, $result); } }