Fix the failing unit tests

refactor the codestyle for the tests we wanted to keep
This commit is contained in:
2017-10-17 06:41:19 -04:00
parent 8ae78ef047
commit 0cc8361929
40 changed files with 1395 additions and 5439 deletions

View File

@@ -1,158 +1,100 @@
<?php
namespace Tests\Unit\Memory;
/**
* @group Lib
* @group Unit
*/
use App\Libraries\abcParse\AbcParser;
use XaiCorp\AbcParser\Models\Memory\Abc;
use XaiCorp\AbcParser\Models\Memory\Person;
use XaiCorp\AbcParser\Parser as AbcParser;
class AbcParserTest extends \Codeception\TestCase\Test
{
private $_facade;
private $valid_abc_1 = "
//blank first line means this isn't a file header anymore!
A: trad
B: Traditional English tunes
C: trad.
X:3
M:4/4
K:C
gaab babc :|
";
private $valid_abc_2 = "
X:40
T:Abbotts Bromley Horn Dance
A: trad
C: trad.
D: None
G:lute
H: Thousand year old tradition
The Horns live in the church and are removed for the dance once a year
R:Jig
F:none.abc
B: Traditional English tunes
W:None
Q:1/8=80
L:1/8
M:6/8
N:Traditional English
O:England
Z:Andy Hornby
%%TUNEURL: http://www.leeds.ac.uk/music/Info/RRTuneBk/gettune/00000dab.html
%%ID:00000dab
S:http://www.leeds.ac.uk/music/Info/RRTuneBk/gettune/00000dab.html
P:ABC
K:G
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|]
";
private $valid_abc_3 = "A: trad
B: Traditional English tunes
C: trad.
D: None
F:none.abc
H: Thousand year old tradition
The Horns live in the church and are removed for the dance once a year
L:1/8
M:6/8
N:Traditional English
O:England
R:Jig
S:http://www.leeds.ac.uk/music/Info/RRTuneBk/gettune/00000dab.html
Z:Andy Hornby
X:3
M:4/4
K:C
gaab babc :|
";
private $facade;
public function setUp()
{
parent::setup();
$this->_facade = new AbcParser();
$this->facade = new AbcParser(new Abc());
}
public function test_not_header_data_no_crash()
private function getValidAbc($filename = '/abc/valid_abc_1.abc')
{
$result = $this->_facade->parseABC($this->valid_abc_1);
$this->assertTrue(is_a($result, 'App\Libraries\abcParse\TuneCollection'));
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 test_all_parameters_for_tune()
public function testAllParametersForTune()
{
$result = $this->_facade->parseABC($this->valid_abc_2);
$this->assertTrue(is_a($result, 'App\Libraries\abcParse\TuneCollection'));
$result = $this->facade->parseABC($this->getValidAbc('/abc/valid_abc_2.abc'));
// Tune details
// Tune details
$tune = $result[0];
// var_dump($tune); die();
$this->assertEquals('40', $result[0]->get('X'));
$this->assertEquals('Abbotts Bromley Horn Dance', array_shift($tune->get('T')) );
$this->assertEquals('England', array_shift($tune->get('O')) );
$this->assertEquals(new App\Libraries\abcParse\Person(array('name'=>'trad')), array_shift($tune->get('A')) );
$this->assertEquals(new App\Libraries\abcParse\Person(array('name'=>'trad.')), array_shift($tune->get('C')) );
$this->assertEquals('England', array_shift($tune->get('O')) );
$this->assertEquals('lute', array_shift($tune->get('G')) );
$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', array_shift($tune->get('R')) );
$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];
// var_dump($setting);die;
$this->assertEquals('Traditional English', array_shift($setting->get('N')) );
$this->assertEquals('1/8', $setting->get('L') );
$this->assertEquals('6/8', $setting->get('M') );
$this->assertEquals('G', $setting->get('K') );
$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" );
$this->assertEquals(trim($expectedMusic), $setting->get('music'), "music strings should match");
$Z = new App\Libraries\abcParse\Person(array('name'=>'Andy Hornby'));
$this->assertEquals($Z, array_shift($setting->get('Z')) );
$Z = new Person(['name' => 'Andy Hornby']);
$this->assertEquals($Z, current($setting->get('Z')));
$this->assertEquals('None', array_shift($setting->get('D')) );
$this->assertEquals('http://www.leeds.ac.uk/music/Info/RRTuneBk/gettune/00000dab.html', array_shift($setting->get('S')) );
$this->assertEquals('None', array_shift($setting->get('W')) );
$this->assertEquals('Traditional English tunes', array_shift($setting->get('B')) );
$this->assertEquals('none.abc', array_shift($setting->get('F')) );
$this->assertEquals('ABC', $setting->get('P') );
$this->assertEquals('1/8=80', $setting->get('Q') );
$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 test_all_parameters_for_collection()
public function testAllParametersForCollection()
{
$collection = $this->_facade->parseABC($this->valid_abc_3);
$this->assertTrue(is_a($collection, 'App\Libraries\abcParse\TuneCollection'));
$collection = $this->facade->parseABC($this->getValidAbc('/abc/valid_abc_3.abc'));
$this->assertEquals(new App\Libraries\abcParse\Person(array('name'=>'trad')), array_shift($collection->get('A')) );
$this->assertEquals('Traditional English tunes', array_shift($collection->get('B')) );
$this->assertEquals(new App\Libraries\abcParse\Person(array('name'=>'trad.')), array_shift($collection->get('C')) );
$this->assertEquals('None', array_shift($collection->get('D')) );
$this->assertEquals('none.abc', array_shift($collection->get('F')) );
$this->assertEquals('Thousand year old tradition', array_shift($collection->get('H')) );
$this->assertEquals('1/8', $collection->get('L') );
$this->assertEquals('6/8', $collection->get('M') );
$this->assertEquals('Traditional English', array_shift($collection->get('N')) );
$this->assertEquals('England', array_shift($collection->get('O')) );
$this->assertEquals('Jig', $collection->get('R') );
$this->assertEquals('http://www.leeds.ac.uk/music/Info/RRTuneBk/gettune/00000dab.html', array_shift($collection->get('S')) );
$this->assertEquals(new App\Libraries\abcParse\Person(array('name'=>'Andy Hornby')), array_shift($collection->get('Z')) );
$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')));
}
}