add ExtractTune use case

This commit is contained in:
2018-04-30 17:24:02 -04:00
parent 3817394951
commit e8c8709976
42 changed files with 1388 additions and 5047 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,12 +1,5 @@
<?php
/**
* Created by PhpStorm.
* User: richard
* Date: 11/19/17
* Time: 4:49 PM
*/
namespace Tests\Unit\Application;
namespace Tests\Unit\AbcParser\Application;
use Enzyme\Axiom\Atoms\StringAtom;
use XaiCorp\AbcParser\Application\PersonFactory;

View File

@@ -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);
}
}

View File

@@ -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());
}
}

View File

@@ -1,81 +0,0 @@
<?php
namespace Tests\Unit;
use \UnitTester;
use \Codeception\Util\Stub;
use \XaiCorp\AbcParser\Parser;
use \XaiCorp\AbcParser\Interfaces\Builder;
class ParserCest
{
/**
* @var \XaiCorp\AbcParser\Interfaces\Builder
*/
protected $builder;
/**
* @var Parser;
*/
protected $parser;
public function _before(UnitTester $I)
{
}
public function _after(UnitTester $I)
{
unset($builder);
}
// tests: trying to...
public function createParser(UnitTester $I)
{
$builder = \Mockery::mock(Builder::Class)
->shouldReceive('newCollection')->once()
->shouldreceive('getCollection')->once()->andreturn(true)
->mock();
$parser = new Parser($builder);
$I->assertInstanceOf(Parser::class, $parser);
}
public function seeParseABCCallNewCollection(UnitTester $I)
{
$abc = '';
$builder = \Mockery::mock(Builder::Class)
->shouldReceive('newCollection')->once()
->shouldreceive('getCollection')->once()->andreturn(true)
->mock();
$parser = new Parser($builder);
$result = $parser->parseABC($abc);
$I->assertTrue($result);
}
public function seeParseABCExample1(UnitTester $I)
{
$abc = file_get_contents(__DIR__.'/../_data/abc/valid_abc_1.abc');
$builder = \Mockery::mock(Builder::Class)
->shouldReceive('newCollection')->once()
->shouldReceive('newPerson')->once()
->shouldReceive('newTune')->once()
->shouldReceive('newSetting')->once()
->shouldReceive('appendToSetting')->once()
->shouldReceive('setOnSetting')->once()
->shouldReceive('storeTune')->once()
->shouldreceive('getCollection')->once()->andreturn(true);
$builder->shouldReceive('setOnTune')
->with('X', '3')
->atMost()->times(4);
$builder = $builder->mock();
$parser = new Parser($builder);
$result = $parser->parseABC($abc);
$I->assertTrue($result);
}
}

View File

@@ -1,156 +0,0 @@
<?php
namespace Tests\Unit\Arr;
use UnitTester;
use XaiCorp\AbcParser\Models\Arr\Abc;
use XaiCorp\AbcParser\Parser;
class AbcCest
{
/**
* @var string
*/
protected $dataDir;
/**
* @var \XaiCorp\AbcParser\Interfaces\Builder
*/
protected $builder;
/**
* @var Parser;
*/
protected $parser;
public function __construct()
{
$this->dataDir = codecept_data_dir();
}
public function _before(UnitTester $I)
{
$this->builder = new Abc();
}
public function _after(UnitTester $I)
{
unset($builder);
}
// tests: trying to...
public function createParser(UnitTester $I)
{
$parser = new Parser($this->builder);
$I->assertInstanceOf(Parser::class, $parser);
}
public function seeParseEmptyAbcWithoutErrors(UnitTester $I)
{
$abc = '';
$parser = new Parser($this->builder);
$result = $parser->parseABC($abc);
$I->assertEmpty($result);
}
public function seeParseABCExample1(UnitTester $I)
{
$abc = file_get_contents($this->dataDir . '/abc/valid_abc_1.abc');
$parser = new Parser($this->builder);
$expected = [
1 => [
'X' => '3',
'M' => '4/4',
'K' => 'C',
'music' => 'gaab babc :|',
],
];
$result = $parser->parseABC($abc);
$I->assertNotEmpty($result);
$I->assertEquals($expected, $result);
}
public function seeParseABCExample2(UnitTester $I)
{
$abc = file_get_contents($this->dataDir . '/abc/valid_abc_2.abc');
$parser = new Parser($this->builder);
$expected = [
1 => [
'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'],
'S' => ['http://www.leeds.ac.uk/music/Info/RRTuneBk/gettune/00000dab.html'],
'P' => 'ABC',
'K' => 'G',
'music' => '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|]',
],
];
$result = $parser->parseABC($abc);
$I->assertNotEmpty($result);
$I->assertEquals($expected, $result);
}
public function seeParseABCExample3(UnitTester $I)
{
$abc = file_get_contents($this->dataDir . '/abc/valid_abc_3.abc');
$parser = new Parser($this->builder);
$expected = [
'A' => ['trad'],
'C' => ['trad.'],
'D' => ['None'],
'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'],
'L' => '1/8',
'M' => '6/8',
'N' => ['Traditional English'],
'O' => ['England'],
'S' => ['http://www.leeds.ac.uk/music/Info/RRTuneBk/gettune/00000dab.html'],
'Z' => ['Andy Hornby'],
1 => [
'X' => '3',
'M' => '4/4',
'K' => 'C',
'music' => 'gaab babc :|',
'T' => ['Short and Sweet']
],
];
$result = $parser->parseABC($abc);
$I->assertNotEmpty($result);
$I->assertEquals($expected, $result);
}
}

View File

@@ -1,106 +0,0 @@
<?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')));
}
}

View File

@@ -1,176 +0,0 @@
<?php
namespace Tests\Unit\Memory;
use Codeception\TestCase\Test;
use XaiCorp\AbcParser\Models\Memory\Person;
class PersonTest extends Test
{
private $person;
public function setUp()
{
$this->person = new Person();
}
/**
* test the model contains the correct attributes
*/
public function testModelDefinition()
{
$this->assertClassHasAttribute('person_id', Person::class);
$this->assertClassHasAttribute('name', Person::class);
$this->assertClassHasAttribute('email', Person::class);
}
public function testConstruct()
{
$params = ['person_id' => 5];
$this->person = new Person($params);
$this->assertEquals(5, $this->person->get('person_id'));
}
/**
* @dataProvider providerSet
*/
public function testMagicSet($property, $value, $expected)
{
$this->testSet($property, $value, $expected);
}
/**
* test the set property method
*
* @param (string) $property, the name of the property to set
* @param (mixed) value to set
* @param (Boolean) expected value for return value of set method
*
* @dataProvider providerSet
*/
public function testSet($property, $value, $expected)
{
$success = $this->person->set($property, $value);
$this->assertEquals($expected, $success);
if ($success) {
$this->assertEquals($value, $this->person->get($property));
}
}
public function providerSet()
{
return [
['Y', 'anything', false],
['person_id', 'not', false],
['person_id', 11, true],
['person_id', '11', true],
['name', null, false],
['name', 1, false],
['name', 'anything', true],
['email', 'anything', false],
['email', 1, false],
['email', 'mail@example.com', true],
];
}
/**
* @dataProvider providerPersonGet
*/
public function testPersonGet($key, $expected)
{
$result = $this->person->set($key, $expected);
$result = $this->person->get($key);
$this->assertEquals($expected, $result);
}
public function providerPersonGet()
{
return [
['', false],
['me', false],
[['of', 'me'], false],
[new Person(), false],
['name', 'Richard Morgan'],
['email', 'r_morgan@sympatico.ca'],
['person_id', 0],
];
}
public function testIsChanged()
{
$person = new Person(['name' => 'Richard Morgan']);
$this->assertInstanceOf(Person::class, $person);
$this->assertFalse($person->is_changed(), 'after load should be no changes');
$person->set('name', 'Richard Armitage');
$this->assertTrue($person->is_changed(), 'updating the name changes the data');
}
/**
* test the static function equals
* returns true if the data properties of 2 Person objects
* are identical
*
* @param (array) $params list of properties to set on the objects
* @param (boolean) $expected result of running equals
*
* @dataProvider providerEquals
*/
public function testEquals($params)
{
$ob1 = new Person();
$ob2 = new Person();
foreach ($params as $key => $val) {
if (is_array($ob1->get($key))) {
$ob1->append($key, $val);
$ob2->append($key, $val);
} else {
$ob1->set($key, $val);
$ob2->set($key, $val);
}
}
$this->assertTrue(Person::equals($ob1, $ob2));
}
/**
* test the static function equals
* returns true if the data properties of 2 Person objects
* are identical
*
* @param (array) $params list of properties to set on the objects
* @param (boolean) $expected result of running equals
*
* @dataProvider providerEquals
*/
public function testEqualsFails($params)
{
$ob1 = new Person();
$ob2 = new Person();
foreach ($params as $key => $val) {
if (is_array($ob1->get($key))) {
$ob1->append($key, $val);
$ob2->append($key, $val . " hello");
} else {
$ob1->set($key, $val);
$ob2->set($key, $val + 1);
}
}
// print_r($ob1); print_r($ob2); die;
$this->assertFalse(Person::equals($ob1, $ob2));
}
public function providerEquals()
{
return [
// array( array('person_id'=>'2') ),
[['name' => 'a title']],
[['email' => 'mail@example.com']],
];
}
}

View File

@@ -1,354 +0,0 @@
<?php
namespace Tests\Unit\Memory;
use Codeception\TestCase\Test as TestCase;
use XaiCorp\AbcParser\Models\Memory\Person;
use XaiCorp\AbcParser\Models\Memory\Setting;
/**
* @group Lib
*/
class SettingTest extends TestCase
{
private $setting;
public function setUp()
{
$this->setting = new Setting();
}
/**
* test the model contains the correct attributes
*/
public function testModelDefinition()
{
$this->assertClassHasAttribute('settingID', Setting::class);
$this->assertClassHasAttribute('tuneID', Setting::class);
$this->assertClassHasAttribute('Z', Setting::class);
$this->assertClassHasAttribute('N', Setting::class);
$this->assertClassHasAttribute('D', Setting::class);
$this->assertClassHasAttribute('S', Setting::class);
$this->assertClassHasAttribute('W', Setting::class);
$this->assertClassHasAttribute('B', Setting::class);
$this->assertClassHasAttribute('F', Setting::class);
$this->assertClassHasAttribute('P', Setting::class);
$this->assertClassHasAttribute('Q', Setting::class);
$this->assertClassHasAttribute('L', Setting::class);
$this->assertClassHasAttribute('M', Setting::class);
$this->assertClassHasAttribute('K', Setting::class);
$this->assertClassHasAttribute('music', Setting::class);
// $this->assertClassHasAttribute('music_hash', Setting::class);
$this->assertClassHasAttribute('propertyNames', Setting::class);
}
/**
* test the set property method
*
* also tests the validate_line protected method
*
* @param (string) $property, the name of the property to set
* @param (mixed) value to set
* @param (Boolean) expected value for return value of set method
*
* @dataProvider providerSet
*/
public function testSet($property, $value, $expected_success, $expected_value = false)
{
$success = $this->setting->set($property, $value);
$this->assertEquals($expected_success, $success);
if ($success) {
if (!$expected_value) {
$expected_value = $value;
}
$this->assertEquals($expected_value, $this->setting->get($property));
}
}
/**
* @dataProvider providerSet
*/
public function testMagicSet($property, $value, $expected_success, $expected_value = false)
{
$this->setting->$property = $value;
if ($expected_success) {
$this->assertEquals($value, $this->setting->get($property));
}
}
public function providerSet()
{
return [
['Y', 'anything', false],
['settingID', 1, true],
['tuneID', ['alpha'], false],
['tuneID', 'alpha', false],
['tuneID', '1', true],
['tuneID', 1, true],
['f', 1, false],
['F', 1, false],
['F', '1', false],
['F', ['aplha'], true],
['P', ['string'], false],
['P', 10, false],
['P', 'string', true],
['Q', ['string'], false],
['Q', 10, false],
['Q', 'string', false],
['Q', '1/8=200', true],
['L', ['string'], false],
['L', 10, false],
['L', 'string', false],
['L', '1/8', true],
['M', ['string'], false],
['M', 10, false],
['M', 'string', false],
['M', '6/8', true],
['M', 'C', true],
['M', 'c', true],
['M', 'C|', true],
['K', ['string'], false],
['K', 10, false],
['K', 'C', true],
['K', 'Am', true],
['K', 'A minor', true],
['K', 'E dorian', true],
['music', 'GABc:|\\', true],
['Z', new Person(), false],
['Z', [new Person(), 'not a person'], false],
['Z', [new Person()], true],
['Z', 111, false],
['N', ['a string'], true],
['D', ['a string'], true],
['S', ['a string'], true],
['W', ['a string'], true],
['B', ['a string'], true],
];
}
/**
* the settingID can only be set if it's value is currently 0
* this ensures that we can't change a setting's id once it's set.
* the default, unset value for settingID is 0
*/
public function testSetSettingID()
{
$success = $this->setting->set('settingID', 1);
$this->assertTrue($success, 'first attempt should succeed');
$success = $this->setting->set('settingID', 2);
$this->assertFalse($success, 'second attempt should fail');
}
/**
* test the append value method
*
* @param (string) $property, the name of the property to set
* @param (mixed) value to append
* @param (Boolean) expected value for return value of append method
*
* @dataProvider providerAppend
*/
public function testAppend($property, $value, $expected)
{
$success = $this->setting->append($property, $value);
$this->assertEquals($expected, $success);
if ($success) {
$this->assertContains($value, $this->setting->get($property));
}
}
public function providerAppend()
{
return [
['Y', 'anything', false],
['settingID', 1, false],
['tuneID', ['alpha'], false],
['tuneID', 'alpha', false],
['tuneID', '1', false],
['tuneID', 1, false],
['f', 1, false],
['F', 1, true],
['F', '1', true],
['F', ['aplha'], false],
['P', ['string'], false],
['P', 10, false],
['P', 'string', false],
['Q', ['string'], false],
['Q', 10, false],
['Q', 'string', false],
['Q', '1/8=200', false],
['L', ['string'], false],
['L', 10, false],
['L', 'string', false],
['L', '1/8', false],
['M', ['string'], false],
['M', 10, false],
['M', 'string', false],
['M', '6/8', false],
['M', 'C', false],
['M', 'c', false],
['M', 'C|', false],
['K', ['string'], false],
['K', 10, false],
['K', 'C', false],
['K', 'Am', false],
['K', 'A minor', false],
['K', 'E dorian', false],
['music', 'GABc:|\\', false],
['Z', new Person(), true],
['Z', [new Person()], false],
['Z', 111, false],
['N', ['a string'], false],
['D', ['a string'], false],
['S', ['a string'], false],
['W', ['a string'], false],
['B', ['a string'], false],
['N', 'more notes', true],
['D', 'another record', true],
['S', 'another source', true],
['W', 'words', true],
['B', 'another book', true],
];
}
/**
* @dataProvider providerGet
*/
public function testGet($key, $expected)
{
$result = $this->setting->set($key, $expected);
$result = $this->setting->get($key);
$this->assertEquals($expected, $result);
}
public function providerGet()
{
return [
['', false],
['me', false],
['settingID', 1],
['tuneID', 2],
['Q', '1/8=100'],
['L', '1/8'],
['M', '6/8'],
['K', 'Am'],
['music', 'GABc:|\\'],
['Z', [new Person()]],
['N', ['a string']],
['D', ['a string']],
['S', ['a string']],
['W', ['a string']],
['B', ['a string']],
];
}
/**
* test the static function equals
* returns true if the data properties of 2 Setting Objects
* are identical
*
* @param (array) $params list of properties to set on the objects
* @param (boolean) $expected result of running equals
*
* @dataProvider providerEquals
*/
public function testEquals($params)
{
$ob1 = new Setting();
$ob2 = new Setting();
foreach ($params as $key => $val) {
if (is_array($ob1->get($key))) {
$ob1->append($key, $val);
$ob2->append($key, $val);
} else {
$ob1->set($key, $val);
$ob2->set($key, $val);
}
}
$this->assertTrue(Setting::equals($ob1, $ob2));
}
/**
* test the static function equals
* returns true if the data properties of 2 Abc_Tunes
* are identical
*
* @param (array) $params list of properties to set on the objects
* @param (boolean) $expected result of running equals
*
* @dataProvider providerEquals
*/
public function testEqualsFails($params)
{
$ob1 = new Setting();
$ob2 = new Setting();
foreach ($params as $key => $val) {
if (is_array($ob1->get($key))) {
$ob1->append($key, $val);
// $ob2->append($key, $val);
} else {
$ob1->set($key, $val);
$ob2->set($key, $val + 1);
}
}
$this->assertFalse(Setting::equals($ob1, $ob2));
}
public function providerEquals()
{
return [
[['settingID' => '2']],
[['tuneID' => '2']],
[['Z' => new Person()]],
[['N' => 'an author']],
[['D' => 'a composer']],
[['S' => 'a group']],
[['W' => 'some history']],
[['B' => 'Plymouth']],
[['F' => 'Jig']],
[['P' => 'ABB']],
[['Q' => '1/8=100']],
[['L' => '1/4']],
[['M' => '2/4']],
[['K' => 'G']],
[['music' => 'a|cab|']],
];
}
public function testIsChanged()
{
$setting = new Setting();
$this->assertInstanceOf(Setting::class, $setting);
$this->assertFalse($setting->is_changed(), 'after load should be no changes');
$setting->set('K', 'G');
$this->assertTrue($setting->is_changed(), 'updating the name changes the data');
}
public function testConstruct()
{
$params = [
'settingID' => 3,
'Z' => [new Person()],
'P' => 'ABC',
];
$this->setting = new Setting($params);
foreach ($params as $key => $val) {
$this->assertEquals($val, $this->setting->get($key));
}
}
}

View File

@@ -1,203 +0,0 @@
<?php
namespace Tests\Unit\Memory;
use XaiCorp\AbcParser\Models\Memory\Person;
use XaiCorp\AbcParser\Models\Memory\Tune;
use XaiCorp\AbcParser\Models\Memory\TuneCollection;
use Codeception\TestCase\Test as TestCase;
//use App\Libraries\memory\Setting;
class TuneCollectionTest extends TestCase
{
private $tunes;
public function setUp()
{
$this->tunes = new TuneCollection();
}
/**
* test the implementation of the Iterator interface
* 100% coverage! ;)
*/
public function testIterator()
{
$t = new Tune();
$this->assertEquals(0, count($this->tunes));
$this->tunes[] = $t;
$this->tunes->push($t);
$this->assertEquals(2, count($this->tunes));
$this->assertInstanceOf(Tune::class, $this->tunes[0], 'first tune');
$this->assertInstanceOf(Tune::class, $this->tunes[1], 'second tune');
foreach ($this->tunes as $key => $val) {
$this->assertInternalType('scalar', $key);
$this->assertInstanceOf(Tune::class, $val);
$this->assertTrue(isset($this->tunes[$key]), 'key is set');
unset($this->tunes[$key]);
$this->assertFalse(isset($this->tunes[$key]), 'key should have been unset');
}
}
/**
* test the ability to remove the last tune from collection
*
* tests the implementation of the Countable interface
*/
public function testPop()
{
$this->assertEquals(0, count($this->tunes), 'no tunes in collection to begin with');
$t = new Tune();
$this->tunes->push($t);
$this->assertEquals(1, count($this->tunes), '1 tune added to collection');
$result = $this->tunes->pop();
$this->assertEquals(0, count($this->tunes), 'no tunes left in collection');
$this->assertInstanceOf(Tune::class, $result);
}
// public function test_construct()
// {
// $params = array(
// 'tc_id' => 5,
// 'cOwner' => 'me',
// 'B' => array('my tune book'),
// 'R' => 'reel'
// );
//
// $this->_tunes = new TuneCollection($params);
//
// foreach($params as $key => $val)
// {
// $this->assertEquals($val, $this->_tunes->get($key));
// }
// }
/**
* test the set property method
*
* @param (string) $property, the name of the property to set
* @param (mixed) value to set
* @param (Boolean) expected value for return value of set method
*
* @dataProvider providerSet
*/
public function testSet($property, $value, $expected)
{
$success = $this->tunes->set($property, $value);
$this->assertEquals($expected, $success);
if ($success) {
$this->assertEquals($value, $this->tunes->get($property));
}
}
/**
* test the set property method
*
* @param (string) $property, the name of the property to set
* @param (mixed) value to set
* @param (Boolean) expected value for return value of set method
*
* @dataProvider providerSet
*/
public function testMagicSetter($property, $value, $expected)
{
$this->tunes->$property = $value;
if ($expected) {
$this->assertEquals($value, $this->tunes->get($property));
}
}
public function providerSet()
{
return [
['Y', 'anything', false],
['A', 10, false],
['A', ['1', '2'], false],
['A', [new Person(), new Person()], true],
['C', 10, false],
['C', ['1', '2'], false],
['C', [new Person(), new Person()], true],
['H', 10, false],
['H', ['1', '2'], true],
['O', 10, false],
['O', ['1', '2'], true],
['R', 10, false],
['R', 'reel', true],
['collection', 10, false],
['collection', '10', false],
['collection', [], false],
['collection', ['1', '2'], false],
['collection', [new Tune(), 'not a tune'], false],
['collection', [new Tune()], true],
['tc_id', 'abc', false],
['tc_id', '11', true],
['tc_id', 15, true],
['cOwner', 'me', true],
];
}
public function testSetTcId()
{
//we should start with tc_id = 0
$this->assertEquals(0, $this->tunes->get('tc_id'), 'should start at 0');
//because tc_id == 0 we can change value
$this->tunes->set('tc_id', 4);
$this->assertEquals(4, $this->tunes->get('tc_id'), 'should have changed to 4');
//tc_id is not 0 so we cannot change value
$this->tunes->set('tc_id', 11);
$this->assertEquals(4, $this->tunes->get('tc_id'), 'should not have changed from 4');
}
/**
* test the append value method
*
* @param (string) $property, the name of the property to set
* @param (mixed) value to append
* @param (Boolean) expected value for return value of append method
*
* @dataProvider providerAppend
*/
public function testAppend($property, $value, $expected)
{
$success = $this->tunes->append($property, $value);
$this->assertEquals($expected, $success);
if ($success) {
$this->assertContains($value, $this->tunes->get($property));
}
}
public function providerAppend()
{
return [
['Y', 1, false],
['H', 'history', true],
['R', 'reel', true],
['r', 'reel', false],
['collection', 'setting', false],
['collection', new Tune(), true],
['collection', [new Tune()], false],
];
}
public function testGet()
{
//R is a valid property so we should get it's value
$this->tunes->set('R', 'reel');
$this->assertEquals('reel', $this->tunes->get('R'));
//X is not a property, so we should get FALSE
$this->assertFalse($this->tunes->get('X'));
}
}

View File

@@ -1,301 +0,0 @@
<?php
namespace Tests\Unit\Memory;
use XaiCorp\AbcParser\Models\Memory\Person;
use XaiCorp\AbcParser\Models\Memory\Setting;
use XaiCorp\AbcParser\Models\Memory\Tune;
use Codeception\TestCase\Test as TestCase;
/**
* @group Lib
* @group Unit
*/
class TuneTest extends TestCase
{
private $tune;
public function setUp()
{
$this->tune = new Tune();
}
/**
* test the model contains the correct attributes
*/
public function testModelDefinition()
{
//Private attributes, probably shouldn't be tested
$this->assertClassHasAttribute('tuneID', Tune::class);
$this->assertClassHasAttribute('A', Tune::class);
$this->assertClassHasAttribute('C', Tune::class);
$this->assertClassHasAttribute('T', Tune::class);
$this->assertClassHasAttribute('G', Tune::class);
$this->assertClassHasAttribute('O', Tune::class);
$this->assertClassHasAttribute('R', Tune::class);
$this->assertClassHasAttribute('H', Tune::class);
$this->assertClassHasAttribute('X', Tune::class);
$this->assertClassHasAttribute('propertyNames', Tune::class);
}
/**
* test the set property method
*
* @param (string) $property, the name of the property to set
* @param (mixed) value to set
* @param (Boolean) expected value for return value of set method
*
* @dataProvider providerSet
*/
public function testSet($property, $value, $expected)
{
$success = $this->tune->set($property, $value);
$this->assertEquals($expected, $success);
if ($success) {
$this->assertEquals($value, $this->tune->get($property));
}
}
/**
* test the set property method
*
* @param (string) $property, the name of the property to set
* @param (mixed) value to set
* @param (Boolean) expected value for return value of set method
*
* @dataProvider providerSet
*/
public function testMagicSetter($property, $value, $expected)
{
$this->tune->$property = $value;
// $this->assertEquals($expected, $success);
if ($expected) {
$this->assertEquals($value, $this->tune->get($property));
}
}
/**
* @dataProvider providerSet
*/
public function testConstruct($property, $value, $expected)
{
$params = [$property => $value];
$this->tune = new Tune($params);
if ($expected) {
$this->assertEquals($value, $this->tune->get($property));
}
}
public function providerSet()
{
return [
['Y', 'anything', false],
['x', 1, false],
['X', 1, true],
['X', 'aplha', false],
['X', '2', true],
['T', 'string', false],
['T', 10, false],
['T', ['1', '2'], true],
['A', 10, false],
['A', ['1', '2'], false],
['A', [new Person(), new Person()], true],
['C', 10, false],
['C', ['1', '2'], false],
['C', [new Person(), new Person()], true],
['G', 10, false],
['G', ['1', '2'], true],
['H', 10, false],
['H', ['1', '2'], true],
['O', 10, false],
['O', ['1', '2'], true],
['R', 10, false],
['R', ['1', '2'], true],
['collection', 10, false],
['collection', '10', false],
['collection', [], false],
['collection', ['1', '2'], false],
['collection', [new Setting()], true],
['tuneHash', 10, false],
['tuneHash', '10', false],
['tuneHash', [], false],
['tuneHash', ['1', '2'], false],
['tuneID', 'abc', false],
['tuneID', '11', true],
['tuneID', 15, true],
];
}
public function testSetTuneID()
{
//we should start with tuneID = 0
$this->assertEquals(0, $this->tune->get('tuneID'), 'should start at 0');
//because tuneID == 0 we can change value
$this->tune->set('tuneID', 4);
$this->assertEquals(4, $this->tune->get('tuneID'), 'should have changed to 4');
//tuneID is not 0 so we cannot change value
$this->tune->set('tuneID', 11);
$this->assertEquals(4, $this->tune->get('tuneID'), 'should not have changed from 4');
}
/**
* test the append value method
*
* @param (string) $property, the name of the property to set
* @param (mixed) value to append
* @param (Boolean) expected value for return value of append method
*
* @dataProvider providerAppend
*/
public function testAppend($property, $value, $expected)
{
$success = $this->tune->append($property, $value);
$this->assertEquals($expected, $success);
if ($success) {
$this->assertContains($value, $this->tune->get($property));
}
}
public function providerAppend()
{
return [
['Y', 1, false],
['X', 1, false],
['T', 'title', true],
['T', ['of', 'titles'], false],
['A', 'author', true],
['C', 'composer', true],
['G', 'Group', true],
['H', 'history', true],
['O', 'Origin', true],
['R', 'Rhythm', true],
['collection', 'setting', false],
['collection', new Setting(), true],
['collection', [new Setting()], false],
['tuneHash', 'tuneHash', false],
['tuneHash', new Setting(), false],
['tuneHash', [new Setting()], false],
];
}
/**
* test the static function equals
* returns true if the data properties of 2 Abc_Tunes
* are identical
*
* @param (array) $params list of properties to set on the objects
* @param (boolean) $expected result of running equals
*
* @dataProvider providerEquals
*/
public function testEquals($params)
{
// $this->markTestIncomplete();
$ob1 = new Tune();
$ob2 = new Tune();
foreach ($params as $key => $val) {
if (is_array($ob1->get($key))) {
$ob1->append($key, $val);
$ob2->append($key, $val);
} else {
$ob1->set($key, $val);
$ob2->set($key, $val);
}
}
$this->assertTrue(Tune::equals($ob1, $ob2));
}
/**
* test the static function equals
* returns true if the data properties of 2 Abc_Tunes
* are identical
*
* @param (array) $params list of properties to set on the objects
* @param (boolean) $expected result of running equals
*
* @dataProvider providerEquals
*/
public function testEqualsFails($params)
{
$ob1 = new Tune();
$ob2 = new Tune();
foreach ($params as $key => $val) {
if ($key === 'collection') {
$ob1->set($key, $val);
} elseif (is_array($ob1->get($key))) {
$ob1->append($key, $val);
} else {
$ob1->set($key, $val);
}
}
$this->assertFalse(Tune::equals($ob1, $ob2));
}
public function providerEquals()
{
$setting1 = new Setting(['settingID' => 5, 'tuneID' => 444]);
$setting2 = new Setting(['settingID' => 3, 'tuneID' => 2244]);
return [
[['X' => '2']],
[['T' => 'a title']],
[['A' => 'an author']],
[['C' => 'a composer']],
[['G' => 'a group']],
[['H' => 'some history']],
[['O' => 'Plymouth']],
[['R' => 'Jig']],
[['collection' => [$setting1, $setting2]]],
];
}
public function testIsChanged()
{
$tune = new Tune();
$this->assertInstanceOf(Tune::class, $tune);
$this->assertFalse($tune->is_changed(), 'after load should be no changes');
$tune->set('X', '5');
$this->assertTrue($tune->is_changed(), 'updating the name changes the data');
}
/**
* @dataProvider providerGet
*/
public function testGet($key, $expected)
{
$result = $this->tune->set($key, $expected);
$result = $this->tune->get($key);
$this->assertEquals($expected, $result);
}
public function providerGet()
{
return [
['', false],
['me', false],
['tuneID', 2],
['X', '2'],
['T', ['1', '2']],
['A', [new Person(), new Person()]],
['C', [new Person(), new Person()]],
['G', ['1', '2']],
['H', ['1', '2']],
['O', ['1', '2']],
['R', ['1', '2']],
['collection', [new Setting()]],
];
}
}