104 lines
2.7 KiB
PHP
104 lines
2.7 KiB
PHP
<?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'));
|
|
}
|
|
|
|
} |