initial commit
This commit is contained in:
158
tests/unit/memory/AbcParserTest.php
Normal file
158
tests/unit/memory/AbcParserTest.php
Normal file
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @group Lib
|
||||
* @group Unit
|
||||
*/
|
||||
|
||||
use App\Libraries\abcParse\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 :|
|
||||
";
|
||||
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setup();
|
||||
$this->_facade = new AbcParser();
|
||||
}
|
||||
|
||||
public function test_not_header_data_no_crash()
|
||||
{
|
||||
$result = $this->_facade->parseABC($this->valid_abc_1);
|
||||
$this->assertTrue(is_a($result, 'App\Libraries\abcParse\TuneCollection'));
|
||||
}
|
||||
|
||||
|
||||
public function test_all_parameters_for_tune()
|
||||
{
|
||||
$result = $this->_facade->parseABC($this->valid_abc_2);
|
||||
$this->assertTrue(is_a($result, 'App\Libraries\abcParse\TuneCollection'));
|
||||
|
||||
// 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')) );
|
||||
$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')) );
|
||||
|
||||
// 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') );
|
||||
$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 App\Libraries\abcParse\Person(array('name'=>'Andy Hornby'));
|
||||
$this->assertEquals($Z, array_shift($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') );
|
||||
}
|
||||
|
||||
|
||||
public function test_all_parameters_for_collection()
|
||||
{
|
||||
$collection = $this->_facade->parseABC($this->valid_abc_3);
|
||||
$this->assertTrue(is_a($collection, 'App\Libraries\abcParse\TuneCollection'));
|
||||
|
||||
$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')) );
|
||||
}
|
||||
}
|
||||
104
tests/unit/memory/PabcTest.php
Normal file
104
tests/unit/memory/PabcTest.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @group Lib
|
||||
* @group Unit
|
||||
*/
|
||||
|
||||
use App\Libraries\abcParse\Pabc;
|
||||
use App\Models\abcParse\Tune;
|
||||
use App\Models\abcParse\TuneSetting as Setting;
|
||||
use App\Models\abcParse\Person;
|
||||
use App\Libraries\abcParse\TuneCollection;
|
||||
|
||||
class PabcTest extends \Codeception\TestCase\Test
|
||||
{
|
||||
private $_facade;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->_facade = new Pabc();
|
||||
}
|
||||
|
||||
private $valid_abc_1 = "
|
||||
X:1
|
||||
M:C
|
||||
K:C
|
||||
gaab babc :|
|
||||
";
|
||||
|
||||
|
||||
/**
|
||||
* test the parse_abc function
|
||||
*
|
||||
* This method receives abc in a string
|
||||
* and converts it into a Tune object.
|
||||
* If the string is not valid abc no Tune object is created
|
||||
* and the method returns false.
|
||||
*
|
||||
* @dataProvider provider_parse_abc
|
||||
*/
|
||||
public function test_parse_abc($string, $isValid)
|
||||
{
|
||||
$result = $this->_facade->parse_abc($string);
|
||||
$this->assertEquals($isValid, is_a($result, TuneCollection::class));
|
||||
}
|
||||
|
||||
public function provider_parse_abc()
|
||||
{
|
||||
return array(
|
||||
array('not an abc', FALSE),
|
||||
array($this->valid_abc_1, TRUE),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function test_load_models()
|
||||
{
|
||||
$params = array(
|
||||
'tuneModel' => new Tune(),
|
||||
'settingModel' => new Setting(),
|
||||
'personModel' => new Person(),
|
||||
);
|
||||
|
||||
$this->_facade = new Pabc($params);
|
||||
|
||||
$this->assertInstanceOf(Tune::class, $this->_facade->tuneModel);
|
||||
$this->assertInstanceOf(Setting::class, $this->_facade->settingModel);
|
||||
$this->assertInstanceOf(Person::class, $this->_facade->personModel);
|
||||
}
|
||||
|
||||
|
||||
public function test_save_no_models()
|
||||
{
|
||||
$this->assertNull($this->_facade->tuneModel);
|
||||
|
||||
$result = $this->_facade->parse_abc($this->valid_abc_1);
|
||||
$this->assertInstanceOf(TuneCollection::class, $result);
|
||||
|
||||
$this->assertFalse($result->get('change_hash'));
|
||||
$saved = $this->_facade->save_collection($result);
|
||||
$this->assertFalse($saved);
|
||||
$this->assertFalse($result->get('change_hash'));
|
||||
}
|
||||
|
||||
public function test_save()
|
||||
{
|
||||
$params = array(
|
||||
'tuneModel' => Mockery::mock(Tune::Class, ['store'=>true]),
|
||||
'settingModel' => Mockery::mock(Setting::class, ['store'=>true]),
|
||||
'personModel' => Mockery::mock(Person::class, ['store'=>true]),
|
||||
);
|
||||
|
||||
$this->_facade = new Pabc($params);
|
||||
|
||||
$result = $this->_facade->parse_abc($this->valid_abc_1);
|
||||
$this->assertInstanceOf(TuneCollection::class, $result);
|
||||
|
||||
$this->assertFalse($result->get('change_hash'));
|
||||
$saved = $this->_facade->save_collection($result);
|
||||
$this->assertTrue($saved);
|
||||
$this->assertNotNull($result->get('change_hash'));
|
||||
}
|
||||
|
||||
}
|
||||
189
tests/unit/memory/PersonTest.php
Normal file
189
tests/unit/memory/PersonTest.php
Normal file
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @group Lib
|
||||
* @group Unit
|
||||
*/
|
||||
|
||||
use App\Libraries\abcParse\Person;
|
||||
use \Codeception\TestCase\Test;
|
||||
|
||||
class PersonTest extends Test
|
||||
{
|
||||
private $_person;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->_person = new Person();
|
||||
}
|
||||
|
||||
/**
|
||||
* test the model contains the correct attributes
|
||||
*/
|
||||
public function test_model_definition()
|
||||
{
|
||||
$this->assertClassHasAttribute('person_id', Person::class);
|
||||
$this->assertClassHasAttribute('name', Person::class);
|
||||
$this->assertClassHasAttribute('email', Person::class);
|
||||
}
|
||||
|
||||
public function test_construct()
|
||||
{
|
||||
$params = array('person_id' => 5);
|
||||
$this->_person = new Person($params);
|
||||
|
||||
$this->assertEquals(5, $this->_person->get('person_id'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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 provider_set
|
||||
*/
|
||||
public function test_set($property, $value, $expected)
|
||||
{
|
||||
$success = $this->_person->set($property, $value);
|
||||
$this->assertEquals($expected, $success);
|
||||
if($success)
|
||||
{
|
||||
$this->assertEquals($value, $this->_person->get($property));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provider_set
|
||||
*/
|
||||
public function test_magic_set($property, $value, $expected)
|
||||
{
|
||||
$this->test_set($property, $value, $expected);
|
||||
}
|
||||
|
||||
public function provider_set()
|
||||
{
|
||||
return array(
|
||||
array('Y', 'anything', FALSE),
|
||||
array('person_id', 'not', FALSE),
|
||||
array('person_id', 11, TRUE),
|
||||
array('person_id', '11', TRUE),
|
||||
array('name', null, FALSE),
|
||||
array('name', 1, FALSE),
|
||||
array('name', 'anything', TRUE),
|
||||
array('email', 'anything', FALSE),
|
||||
array('email', 1, FALSE),
|
||||
array('email', 'mail@example.com', TRUE),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provider_person_get
|
||||
*/
|
||||
public function test_person_get($key, $expected)
|
||||
{
|
||||
$result = $this->_person->set($key, $expected);
|
||||
$result = $this->_person->get($key);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function provider_person_get()
|
||||
{
|
||||
return array(
|
||||
array('', FALSE),
|
||||
array('me', FALSE),
|
||||
array(array('of','me'), FALSE),
|
||||
array(new Person(), FALSE),
|
||||
array('name', 'Richard Morgan'),
|
||||
array('email', 'r_morgan@sympatico.ca'),
|
||||
array('person_id', 0)
|
||||
);
|
||||
}
|
||||
|
||||
public function test_is_changed()
|
||||
{
|
||||
$person = new Person(array('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 provider_equals
|
||||
*/
|
||||
public function test_equals($params)
|
||||
{
|
||||
// $this->markTestIncomplete();
|
||||
|
||||
$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 provider_equals
|
||||
*/
|
||||
public function test_equals_fails($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 provider_equals()
|
||||
{
|
||||
return array(
|
||||
// array( array('person_id'=>'2') ),
|
||||
array( array('name'=>'a title') ),
|
||||
array( array('email'=>'mail@example.com') ),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
364
tests/unit/memory/SettingTest.php
Normal file
364
tests/unit/memory/SettingTest.php
Normal file
@@ -0,0 +1,364 @@
|
||||
<?php
|
||||
|
||||
use App\Libraries\abcParse\Setting;
|
||||
use App\Libraries\abcParse\Person;
|
||||
use \Codeception\TestCase\Test as TestCase;
|
||||
|
||||
|
||||
/**
|
||||
* @group Lib
|
||||
*/
|
||||
class SettingTest extends TestCase
|
||||
{
|
||||
private $_setting;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->_setting = new Setting();
|
||||
}
|
||||
|
||||
/**
|
||||
* test the model contains the correct attributes
|
||||
*/
|
||||
public function test_model_definition()
|
||||
{
|
||||
$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 provider_set
|
||||
*/
|
||||
public function test_set($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 provider_set
|
||||
*/
|
||||
public function test_magic_set($property, $value, $expected_success, $expected_value = FALSE)
|
||||
{
|
||||
$this->_setting->$property = $value;
|
||||
if($expected_success)
|
||||
{
|
||||
$this->assertEquals($value, $this->_setting->get($property));
|
||||
}
|
||||
}
|
||||
|
||||
public function provider_set()
|
||||
{
|
||||
return array(
|
||||
array('Y', 'anything', FALSE),
|
||||
array('settingID', 1, TRUE),
|
||||
array('tuneID', array('alpha'), FALSE),
|
||||
array('tuneID', 'alpha', FALSE),
|
||||
array('tuneID', '1', TRUE),
|
||||
array('tuneID', 1, TRUE),
|
||||
array('f', 1, FALSE),
|
||||
array('F', 1, FALSE),
|
||||
array('F', '1',FALSE),
|
||||
array('F', array('aplha'), TRUE),
|
||||
array('P', array('string'), FALSE),
|
||||
array('P', 10, FALSE),
|
||||
array('P', 'string', TRUE),
|
||||
array('Q', array('string'), FALSE),
|
||||
array('Q', 10, FALSE),
|
||||
array('Q', 'string', FALSE),
|
||||
array('Q', '1/8=200', TRUE),
|
||||
array('L', array('string'), FALSE),
|
||||
array('L', 10, FALSE),
|
||||
array('L', 'string', FALSE),
|
||||
array('L', '1/8', TRUE),
|
||||
array('M', array('string'), FALSE),
|
||||
array('M', 10, FALSE),
|
||||
array('M', 'string', FALSE),
|
||||
array('M', '6/8', TRUE),
|
||||
array('M', 'C', TRUE),
|
||||
array('M', 'c', TRUE),
|
||||
array('M', 'C|', TRUE),
|
||||
array('K', array('string'), FALSE),
|
||||
array('K', 10, FALSE),
|
||||
array('K', 'C', TRUE),
|
||||
array('K', 'Am', TRUE),
|
||||
array('K', 'A minor', TRUE),
|
||||
array('K', 'E dorian', TRUE),
|
||||
array('music', 'GABc:|\\', TRUE),
|
||||
|
||||
array('Z', new Person(), FALSE),
|
||||
array('Z', array(new Person(), 'not a person'), FALSE),
|
||||
array('Z', array(new Person()), TRUE),
|
||||
array('Z', 111, FALSE),
|
||||
array('N', array('a string'), TRUE),
|
||||
array('D', array('a string'), TRUE),
|
||||
array('S', array('a string'), TRUE),
|
||||
array('W', array('a string'), TRUE),
|
||||
array('B', array('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 test_set_settingID()
|
||||
{
|
||||
$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 provider_append
|
||||
*/
|
||||
public function test_append($property, $value, $expected)
|
||||
{
|
||||
$success = $this->_setting->append($property, $value);
|
||||
$this->assertEquals($expected, $success);
|
||||
if($success)
|
||||
{
|
||||
$this->assertContains($value, $this->_setting->get($property));
|
||||
}
|
||||
}
|
||||
|
||||
public function provider_append()
|
||||
{
|
||||
return array(
|
||||
array('Y', 'anything', FALSE),
|
||||
array('settingID', 1, FALSE),
|
||||
array('tuneID', array('alpha'), FALSE),
|
||||
array('tuneID', 'alpha', FALSE),
|
||||
array('tuneID', '1', FALSE),
|
||||
array('tuneID', 1, FALSE),
|
||||
array('f', 1, FALSE),
|
||||
array('F', 1, TRUE),
|
||||
array('F', '1', TRUE),
|
||||
array('F', array('aplha'), FALSE),
|
||||
array('P', array('string'), FALSE),
|
||||
array('P', 10, FALSE),
|
||||
array('P', 'string', FALSE),
|
||||
array('Q', array('string'), FALSE),
|
||||
array('Q', 10, FALSE),
|
||||
array('Q', 'string', FALSE),
|
||||
array('Q', '1/8=200', FALSE),
|
||||
array('L', array('string'), FALSE),
|
||||
array('L', 10, FALSE),
|
||||
array('L', 'string', FALSE),
|
||||
array('L', '1/8', FALSE),
|
||||
array('M', array('string'), FALSE),
|
||||
array('M', 10, FALSE),
|
||||
array('M', 'string', FALSE),
|
||||
array('M', '6/8', FALSE),
|
||||
array('M', 'C', FALSE),
|
||||
array('M', 'c', FALSE),
|
||||
array('M', 'C|', FALSE),
|
||||
array('K', array('string'), FALSE),
|
||||
array('K', 10, FALSE),
|
||||
array('K', 'C', FALSE),
|
||||
array('K', 'Am', FALSE),
|
||||
array('K', 'A minor', FALSE),
|
||||
array('K', 'E dorian', FALSE),
|
||||
array('music', 'GABc:|\\', FALSE),
|
||||
|
||||
array('Z', new Person(), TRUE),
|
||||
array('Z', array(new Person()), FALSE),
|
||||
array('Z', 111, FALSE),
|
||||
array('N', array('a string'), FALSE),
|
||||
array('D', array('a string'), FALSE),
|
||||
array('S', array('a string'), FALSE),
|
||||
array('W', array('a string'), FALSE),
|
||||
array('B', array('a string'), FALSE),
|
||||
array('N', 'more notes', TRUE),
|
||||
array('D', 'another record', TRUE),
|
||||
array('S', 'another source', TRUE),
|
||||
array('W', 'words', TRUE),
|
||||
array('B', 'another book', TRUE),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provider_get
|
||||
*/
|
||||
public function test_get($key, $expected)
|
||||
{
|
||||
$result = $this->_setting->set($key, $expected);
|
||||
$result = $this->_setting->get($key);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function provider_get()
|
||||
{
|
||||
return array(
|
||||
array('', FALSE),
|
||||
array('me', FALSE),
|
||||
array('settingID', 1),
|
||||
array('tuneID', 2),
|
||||
array('Q', '1/8=100'),
|
||||
array('L', '1/8'),
|
||||
array('M', '6/8'),
|
||||
array('K', 'Am'),
|
||||
array('music', 'GABc:|\\'),
|
||||
|
||||
array('Z', array(new Person())),
|
||||
array('N', array('a string')),
|
||||
array('D', array('a string')),
|
||||
array('S', array('a string')),
|
||||
array('W', array('a string')),
|
||||
array('B', array('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 provider_equals
|
||||
*/
|
||||
public function test_equals($params)
|
||||
{
|
||||
// $this->markTestIncomplete();
|
||||
|
||||
$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 provider_equals
|
||||
*/
|
||||
public function test_equals_fails($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 provider_equals()
|
||||
{
|
||||
return array(
|
||||
array( array('settingID'=>'2') ),
|
||||
array( array('tuneID'=>'2') ),
|
||||
array( array('Z'=> new Person()) ),
|
||||
array( array('N'=>'an author') ),
|
||||
array( array('D'=>'a composer') ),
|
||||
array( array('S'=>'a group') ),
|
||||
array( array('W'=>'some history') ),
|
||||
array( array('B'=>'Plymouth') ),
|
||||
array( array('F'=>'Jig') ),
|
||||
array( array('P'=>'ABB') ),
|
||||
array( array('Q'=>'1/8=100') ),
|
||||
array( array('L'=>'1/4') ),
|
||||
array( array('M'=>'2/4') ),
|
||||
array( array('K'=>'G') ),
|
||||
array( array('music'=>'a|cab|') ),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_isChanged()
|
||||
{
|
||||
$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 test_construct()
|
||||
{
|
||||
$params = array(
|
||||
'settingID' => 3,
|
||||
'Z' => array(new Person()),
|
||||
'P' => 'ABC'
|
||||
);
|
||||
|
||||
$this->_setting = new Setting ($params);
|
||||
|
||||
foreach($params as $key => $val)
|
||||
{
|
||||
$this->assertEquals($val, $this->_setting->get($key));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
210
tests/unit/memory/TuneCollectionTest.php
Normal file
210
tests/unit/memory/TuneCollectionTest.php
Normal file
@@ -0,0 +1,210 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @group Lib
|
||||
* @group Unit
|
||||
*/
|
||||
|
||||
use App\Libraries\abcParse\Tune;
|
||||
//use App\Libraries\memory\Setting;
|
||||
use App\Libraries\abcParse\Person;
|
||||
use App\Libraries\abcParse\TuneCollection;
|
||||
use \Codeception\TestCase\Test as TestCase;
|
||||
|
||||
class TuneCollectionTest extends TestCase
|
||||
{
|
||||
private $_tunes;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->_tunes = new TuneCollection();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* test the implementation of the Iterator interface
|
||||
* 100% coverage! ;)
|
||||
*/
|
||||
public function test_iterator()
|
||||
{
|
||||
$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 test_pop()
|
||||
{
|
||||
$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 provider_set
|
||||
*/
|
||||
public function test_set($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 provider_set
|
||||
*/
|
||||
public function test_magic_setter($property, $value, $expected)
|
||||
{
|
||||
$this->_tunes->$property = $value;
|
||||
if($expected)
|
||||
{
|
||||
$this->assertEquals($value, $this->_tunes->get($property));
|
||||
}
|
||||
}
|
||||
|
||||
public function provider_set()
|
||||
{
|
||||
return array(
|
||||
array('Y', 'anything', FALSE),
|
||||
array('A', 10, FALSE),
|
||||
array('A', array('1','2'), FALSE),
|
||||
array('A', array(new Person(),new Person()), TRUE),
|
||||
array('C', 10, FALSE),
|
||||
array('C', array('1','2'), FALSE),
|
||||
array('C', array(new Person(),new Person()), TRUE),
|
||||
array('H', 10, FALSE),
|
||||
array('H', array('1','2'), TRUE),
|
||||
array('O', 10, FALSE),
|
||||
array('O', array('1','2'), TRUE),
|
||||
array('R', 10, FALSE),
|
||||
array('R', 'reel', TRUE),
|
||||
array('collection', 10, FALSE),
|
||||
array('collection', '10', FALSE),
|
||||
array('collection', array(), FALSE),
|
||||
array('collection', array('1','2'), FALSE),
|
||||
array('collection', array(new Tune(), 'not a tune'), FALSE),
|
||||
array('collection', array(new Tune()), TRUE),
|
||||
array('tc_id', 'abc', FALSE),
|
||||
array('tc_id', '11', TRUE),
|
||||
array('tc_id', 15, TRUE),
|
||||
array('cOwner', 'me', TRUE),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_set_tc_id()
|
||||
{
|
||||
//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 provider_append
|
||||
*/
|
||||
public function test_append($property, $value, $expected)
|
||||
{
|
||||
$success = $this->_tunes->append($property, $value);
|
||||
$this->assertEquals($expected, $success);
|
||||
if($success)
|
||||
{
|
||||
$this->assertContains($value, $this->_tunes->get($property));
|
||||
}
|
||||
}
|
||||
|
||||
public function provider_append()
|
||||
{
|
||||
return array(
|
||||
array('Y', 1, FALSE),
|
||||
array('H', 'history', TRUE),
|
||||
array('R', 'reel', TRUE),
|
||||
array('r', 'reel', FALSE),
|
||||
array('collection', 'setting', FALSE),
|
||||
array('collection', new Tune(), TRUE),
|
||||
array('collection', array(new Tune()), FALSE),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function test_get()
|
||||
{
|
||||
//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'));
|
||||
}
|
||||
|
||||
}
|
||||
310
tests/unit/memory/TuneTest.php
Normal file
310
tests/unit/memory/TuneTest.php
Normal file
@@ -0,0 +1,310 @@
|
||||
<?php
|
||||
|
||||
use App\Libraries\abcParse\Tune;
|
||||
use App\Libraries\abcParse\Setting;
|
||||
use App\Libraries\abcParse\Person;
|
||||
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 test_model_definition()
|
||||
{
|
||||
//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 provider_set
|
||||
*/
|
||||
public function test_set($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 provider_set
|
||||
*/
|
||||
public function test_magic_setter($property, $value, $expected)
|
||||
{
|
||||
$this->_tune->$property = $value;
|
||||
// $this->assertEquals($expected, $success);
|
||||
if($expected)
|
||||
{
|
||||
$this->assertEquals($value, $this->_tune->get($property));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provider_set
|
||||
*/
|
||||
public function test_construct($property, $value, $expected)
|
||||
{
|
||||
$params = array($property => $value);
|
||||
$this->_tune = new Tune($params);
|
||||
|
||||
if($expected)
|
||||
{
|
||||
$this->assertEquals($value, $this->_tune->get($property));
|
||||
}
|
||||
}
|
||||
|
||||
public function provider_set()
|
||||
{
|
||||
return array(
|
||||
array('Y', 'anything', FALSE),
|
||||
array('x', 1, FALSE),
|
||||
array('X', 1, TRUE),
|
||||
array('X', 'aplha', FALSE),
|
||||
array('X', '2', TRUE),
|
||||
array('T', 'string', FALSE),
|
||||
array('T', 10, FALSE),
|
||||
array('T', array('1','2'), TRUE),
|
||||
array('A', 10, FALSE),
|
||||
array('A', array('1','2'), FALSE),
|
||||
array('A', array(new Person(),new Person()), TRUE),
|
||||
array('C', 10, FALSE),
|
||||
array('C', array('1','2'), FALSE),
|
||||
array('C', array(new Person(),new Person()), TRUE),
|
||||
array('G', 10, FALSE),
|
||||
array('G', array('1','2'), TRUE),
|
||||
array('H', 10, FALSE),
|
||||
array('H', array('1','2'), TRUE),
|
||||
array('O', 10, FALSE),
|
||||
array('O', array('1','2'), TRUE),
|
||||
array('R', 10, FALSE),
|
||||
array('R', array('1','2'), TRUE),
|
||||
array('collection', 10, FALSE),
|
||||
array('collection', '10', FALSE),
|
||||
array('collection', array(), FALSE),
|
||||
array('collection', array('1','2'), FALSE),
|
||||
array('collection', array(new Setting()), TRUE),
|
||||
array('tuneHash', 10, FALSE),
|
||||
array('tuneHash', '10', FALSE),
|
||||
array('tuneHash', array(), FALSE),
|
||||
array('tuneHash', array('1','2'), FALSE),
|
||||
array('tuneID', 'abc', FALSE),
|
||||
array('tuneID', '11', TRUE),
|
||||
array('tuneID', 15, TRUE),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_set_tuneID()
|
||||
{
|
||||
//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 provider_append
|
||||
*/
|
||||
public function test_append($property, $value, $expected)
|
||||
{
|
||||
$success = $this->_tune->append($property, $value);
|
||||
$this->assertEquals($expected, $success);
|
||||
if($success)
|
||||
{
|
||||
$this->assertContains($value, $this->_tune->get($property));
|
||||
}
|
||||
}
|
||||
|
||||
public function provider_append()
|
||||
{
|
||||
return array(
|
||||
array('Y', 1, FALSE),
|
||||
array('X', 1, FALSE),
|
||||
array('T','title', TRUE),
|
||||
array('T', array('of','titles'), FALSE),
|
||||
array('A', 'author', TRUE),
|
||||
array('C', 'composer', TRUE),
|
||||
array('G', 'Group', TRUE),
|
||||
array('H', 'history', TRUE),
|
||||
array('O', 'Origin', TRUE),
|
||||
array('R', 'Rhythm', TRUE),
|
||||
array('collection', 'setting', FALSE),
|
||||
array('collection', new Setting(), TRUE),
|
||||
array('collection', array(new Setting()), FALSE),
|
||||
array('tuneHash', 'tuneHash', FALSE),
|
||||
array('tuneHash', new Setting(), FALSE),
|
||||
array('tuneHash', array(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 provider_equals
|
||||
*/
|
||||
public function test_equals($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 provider_equals
|
||||
*/
|
||||
public function test_equals_fails($params)
|
||||
{
|
||||
$ob1 = new Tune();
|
||||
$ob2 = new Tune();
|
||||
|
||||
foreach($params as $key => $val)
|
||||
{
|
||||
if($key === 'collection')
|
||||
{
|
||||
$ob1->set($key, $val);
|
||||
}
|
||||
else if(is_array($ob1->get($key)))
|
||||
{
|
||||
$ob1->append($key, $val);
|
||||
}
|
||||
else {
|
||||
$ob1->set($key, $val);
|
||||
}
|
||||
}
|
||||
$this->assertFalse(Tune::equals($ob1, $ob2));
|
||||
}
|
||||
public function provider_equals()
|
||||
{
|
||||
$setting1 = new Setting(array('settingID'=>5, 'tuneID'=>444));
|
||||
$setting2 = new Setting(array('settingID'=>3, 'tuneID'=>2244));
|
||||
return array(
|
||||
array( array('X'=>'2') ),
|
||||
array( array('T'=>'a title') ),
|
||||
array( array('A'=>'an author') ),
|
||||
array( array('C'=>'a composer') ),
|
||||
array( array('G'=>'a group') ),
|
||||
array( array('H'=>'some history') ),
|
||||
array( array('O'=>'Plymouth') ),
|
||||
array( array('R'=>'Jig') ),
|
||||
array( array('collection' => array($setting1, $setting2) ))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function test_isChanged()
|
||||
{
|
||||
$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 provider_get
|
||||
*/
|
||||
public function test_get($key, $expected)
|
||||
{
|
||||
$result = $this->_tune->set($key, $expected);
|
||||
$result = $this->_tune->get($key);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function provider_get()
|
||||
{
|
||||
return array(
|
||||
array('', FALSE),
|
||||
array('me', FALSE),
|
||||
array('tuneID', 2),
|
||||
array('X', '2'),
|
||||
array('T', array('1','2')),
|
||||
array('A', array(new Person(),new Person())),
|
||||
array('C', array(new Person(),new Person())),
|
||||
array('G', array('1','2')),
|
||||
array('H', array('1','2')),
|
||||
array('O', array('1','2')),
|
||||
array('R', array('1','2')),
|
||||
array('collection', array(new Setting())),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user