Fix the failing unit tests
refactor the codestyle for the tests we wanted to keep
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
<?php
|
||||
|
||||
use App\Libraries\abcParse\Tune;
|
||||
use App\Libraries\abcParse\Setting;
|
||||
use App\Libraries\abcParse\Person;
|
||||
use \Codeception\TestCase\Test as TestCase;
|
||||
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
|
||||
@@ -11,17 +13,17 @@ use \Codeception\TestCase\Test as TestCase;
|
||||
*/
|
||||
class TuneTest extends TestCase
|
||||
{
|
||||
private $_tune;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->_tune = new Tune();
|
||||
}
|
||||
|
||||
private $tune;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->tune = new Tune();
|
||||
}
|
||||
|
||||
/**
|
||||
* test the model contains the correct attributes
|
||||
*/
|
||||
public function test_model_definition()
|
||||
public function testModelDefinition()
|
||||
{
|
||||
//Private attributes, probably shouldn't be tested
|
||||
$this->assertClassHasAttribute('tuneID', Tune::class);
|
||||
@@ -35,276 +37,265 @@ class TuneTest extends TestCase
|
||||
$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
|
||||
*
|
||||
* @dataProvider providerSet
|
||||
*/
|
||||
public function test_set($property, $value, $expected)
|
||||
public function testSet($property, $value, $expected)
|
||||
{
|
||||
$success = $this->_tune->set($property, $value);
|
||||
$success = $this->tune->set($property, $value);
|
||||
$this->assertEquals($expected, $success);
|
||||
if($success)
|
||||
{
|
||||
$this->assertEquals($value, $this->_tune->get($property));
|
||||
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()
|
||||
/**
|
||||
* 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');
|
||||
$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');
|
||||
$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');
|
||||
$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
|
||||
*
|
||||
* @dataProvider providerAppend
|
||||
*/
|
||||
public function test_append($property, $value, $expected)
|
||||
public function testAppend($property, $value, $expected)
|
||||
{
|
||||
$success = $this->_tune->append($property, $value);
|
||||
$success = $this->tune->append($property, $value);
|
||||
$this->assertEquals($expected, $success);
|
||||
if($success)
|
||||
{
|
||||
$this->assertContains($value, $this->_tune->get($property));
|
||||
if ($success) {
|
||||
$this->assertContains($value, $this->tune->get($property));
|
||||
}
|
||||
}
|
||||
|
||||
public function provider_append()
|
||||
|
||||
public function providerAppend()
|
||||
{
|
||||
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),
|
||||
);
|
||||
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 provider_equals
|
||||
*
|
||||
* @dataProvider providerEquals
|
||||
*/
|
||||
public function test_equals($params)
|
||||
public function testEquals($params)
|
||||
{
|
||||
// $this->markTestIncomplete();
|
||||
|
||||
|
||||
$ob1 = new Tune();
|
||||
$ob2 = new Tune();
|
||||
|
||||
foreach($params as $key => $val)
|
||||
{
|
||||
if(is_array($ob1->get($key)))
|
||||
{
|
||||
|
||||
foreach ($params as $key => $val) {
|
||||
if (is_array($ob1->get($key))) {
|
||||
$ob1->append($key, $val);
|
||||
$ob2->append($key, $val);
|
||||
}
|
||||
else {
|
||||
} 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
|
||||
*
|
||||
* @dataProvider providerEquals
|
||||
*/
|
||||
public function test_equals_fails($params)
|
||||
public function testEqualsFails($params)
|
||||
{
|
||||
$ob1 = new Tune();
|
||||
$ob2 = new Tune();
|
||||
|
||||
foreach($params as $key => $val)
|
||||
{
|
||||
if($key === 'collection')
|
||||
{
|
||||
|
||||
foreach ($params as $key => $val) {
|
||||
if ($key === 'collection') {
|
||||
$ob1->set($key, $val);
|
||||
}
|
||||
else if(is_array($ob1->get($key)))
|
||||
{
|
||||
} elseif (is_array($ob1->get($key))) {
|
||||
$ob1->append($key, $val);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$ob1->set($key, $val);
|
||||
}
|
||||
}
|
||||
$this->assertFalse(Tune::equals($ob1, $ob2));
|
||||
}
|
||||
public function provider_equals()
|
||||
|
||||
public function providerEquals()
|
||||
{
|
||||
$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) ))
|
||||
);
|
||||
$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 test_isChanged()
|
||||
|
||||
|
||||
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');
|
||||
|
||||
$tune->set('X', '5');
|
||||
$this->assertTrue($tune->is_changed(), 'updating the name changes the data');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provider_get
|
||||
* @dataProvider providerGet
|
||||
*/
|
||||
public function test_get($key, $expected)
|
||||
public function testGet($key, $expected)
|
||||
{
|
||||
$result = $this->_tune->set($key, $expected);
|
||||
$result = $this->_tune->get($key);
|
||||
$result = $this->tune->set($key, $expected);
|
||||
$result = $this->tune->get($key);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function provider_get()
|
||||
public function providerGet()
|
||||
{
|
||||
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())),
|
||||
);
|
||||
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()]],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user