Files
abcParser/tests/unit/memory/AbcParserTest.php
richard 4ac9707184 add enzyme/axiom interfaces
use axiom/RepositoryInterface in tests and store music
add axiom/Models/ModelInterface to TuneCollection
2017-10-17 21:56:05 -04:00

107 lines
4.5 KiB
PHP

<?php
namespace Tests\Unit\Memory;
use XaiCorp\AbcParser\Interfaces\Repository;
use XaiCorp\AbcParser\Models\Memory\Abc;
use XaiCorp\AbcParser\Models\Memory\Person;
use XaiCorp\AbcParser\Parser as AbcParser;
use Enzyme\Axiom\Repositories\RepositoryInterface;
class AbcParserTest extends \Codeception\TestCase\Test
{
private $facade;
public function setUp()
{
parent::setup();
$repository = \Mockery::mock(RepositoryInterface::class)
->shouldReceive('add')->once()
->getMock();
$this->facade = new AbcParser(new Abc($repository));
}
private function getValidAbc($filename = '/abc/valid_abc_1.abc')
{
return file_get_contents(codecept_data_dir($filename));
}
public function testNotHeaderDataNoCrash()
{
$result = $this->facade->parseABC($this->getValidAbc());
$this->assertInstanceOf(\XaiCorp\AbcParser\Models\Memory\TuneCollection::class, $result);
}
public function testAllParametersForTune()
{
$result = $this->facade->parseABC($this->getValidAbc('/abc/valid_abc_2.abc'));
// Tune details
$tune = $result[0];
$this->assertEquals('40', $result[0]->get('X'));
$this->assertEquals('Abbotts Bromley Horn Dance', current($tune->get('T')));
$this->assertEquals('England', current($tune->get('O')));
$this->assertEquals(new Person(['name' => 'trad']), current($tune->get('A')));
$this->assertEquals(new Person(['name' => 'trad.']), current($tune->get('C')));
$this->assertEquals('England', current($tune->get('O')));
$this->assertEquals('lute', current($tune->get('G')));
$history = $tune->get('H');
$this->assertEquals(2, count($history));
$this->assertEquals('Thousand year old tradition', $history[0]);
$this->assertEquals('The Horns live in the church and are removed for the dance once a year', $history[1]);
$this->assertEquals('Jig', current($tune->get('R')));
// setting details
$setting = $tune[0];
$this->assertEquals('Traditional English', current($setting->get('N')));
$this->assertEquals('1/8', $setting->get('L'));
$this->assertEquals('6/8', $setting->get('M'));
$this->assertEquals('G', $setting->get('K'));
$expectedMusic = "
e|B2e G2e|B2e E2G|FGA GAB|1AGF G2:|2AGF E2|
|e|c2e cde|A2c ABc|FGA GFE|_E=EF B,2g|
e2g efg|c2e cde|dcB AGF|E3E2
|:A|BcB e3|BcB f3|BcB AGF|1G2F G2:|2E3-E2|]
";
$this->assertEquals(trim($expectedMusic), $setting->get('music'), "music strings should match");
$Z = new Person(['name' => 'Andy Hornby']);
$this->assertEquals($Z, current($setting->get('Z')));
$this->assertEquals('None', current($setting->get('D')));
$this->assertEquals(
'http://www.leeds.ac.uk/music/Info/RRTuneBk/gettune/00000dab.html',
current($setting->get('S'))
);
$this->assertEquals('None', current($setting->get('W')));
$this->assertEquals('Traditional English tunes', current($setting->get('B')));
$this->assertEquals('none.abc', current($setting->get('F')));
$this->assertEquals('ABC', $setting->get('P'));
$this->assertEquals('1/8=80', $setting->get('Q'));
}
public function testAllParametersForCollection()
{
$collection = $this->facade->parseABC($this->getValidAbc('/abc/valid_abc_3.abc'));
$this->assertEquals(new Person(['name' => 'trad']), current($collection->get('A')));
$this->assertEquals('Traditional English tunes', current($collection->get('B')));
$this->assertEquals(new Person(['name' => 'trad.']), current($collection->get('C')));
$this->assertEquals('None', current($collection->get('D')));
$this->assertEquals('none.abc', current($collection->get('F')));
$this->assertEquals('Thousand year old tradition', current($collection->get('H')));
$this->assertEquals('1/8', $collection->get('L'));
$this->assertEquals('6/8', $collection->get('M'));
$this->assertEquals('Traditional English', current($collection->get('N')));
$this->assertEquals('England', current($collection->get('O')));
$this->assertEquals('Jig', $collection->get('R'));
$this->assertEquals(
'http://www.leeds.ac.uk/music/Info/RRTuneBk/gettune/00000dab.html',
current($collection->get('S'))
);
$this->assertEquals(new Person(['name' => 'Andy Hornby']), current($collection->get('Z')));
}
}