start on Tune::merge()

This commit is contained in:
2018-05-04 20:30:17 -04:00
parent e8c8709976
commit 655a04a501
2 changed files with 55 additions and 1 deletions

View File

@@ -273,7 +273,22 @@ class Tune implements EntityInterface
*/ */
protected function set($attribute, $value) protected function set($attribute, $value)
{ {
call_user_func([$this, 'set'.$attribute], [$value]); switch ($attribute) {
case 'index':
call_user_func([$this, 'set'.$attribute], $value);
break;
default:
$this->append($attribute, $value);
}
}
protected function append($attribute, array $values)
{
$method = 'add' . substr($attribute, 0, -1);
foreach ($values as $value) {
call_user_func([$this, $method], $value);
}
} }
/** /**
@@ -320,4 +335,11 @@ class Tune implements EntityInterface
return $this; return $this;
} }
public function merge(Tune $source)
{
//TODO
$this->titles = array_merge($this->getTitles(), $source->getTitles());
return $this;
}
} }

View File

@@ -28,6 +28,22 @@ class TuneTest extends \PHPUnit_Framework_TestCase
$this->assertInstanceOf(Tune::class, $tune); $this->assertInstanceOf(Tune::class, $tune);
} }
public function testCanIntializeFromArray()
{
$titles = ['Title'];
$authors = ['Richard Morgan'];
$config = [
'Titles' => $titles,
'Authors' => $authors
];
$tune = new Tune($config);
$this->assertInstanceOf(Tune::class, $tune);
$this->assertEquals($tune->getTitles(), $titles);
}
public function testNewTuneHasIdentitySet() public function testNewTuneHasIdentitySet()
{ {
$params = []; $params = [];
@@ -168,4 +184,20 @@ class TuneTest extends \PHPUnit_Framework_TestCase
$this->assertNotEmpty($result); $this->assertNotEmpty($result);
$this->assertEquals($setting, $result[0]); $this->assertEquals($setting, $result[0]);
} }
public function testMergeAddsExtraDataToTune()
{
$targetTune = new Tune([
'titles' => ['target']
]);
$sourceTune = new Tune([
'titles' => ['source']
]);
$result = $targetTune->merge($sourceTune);
$this->assertEquals(new Tune([
'titles' => ['target', 'source']
]), $result);
}
} }