Fix the failing unit tests

refactor the codestyle for the tests we wanted to keep
This commit is contained in:
2017-10-17 06:41:19 -04:00
parent 8ae78ef047
commit 0cc8361929
40 changed files with 1395 additions and 5439 deletions

View File

@@ -1,210 +1,203 @@
<?php
/**
* @group Lib
* @group Unit
*/
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\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;
private $tunes;
public function setUp()
{
$this->_tunes = new TuneCollection();
$this->tunes = new TuneCollection();
}
/**
* test the implementation of the Iterator interface
* 100% coverage! ;)
*/
public function test_iterator()
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->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');
$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()
public function testPop()
{
$this->assertEquals(0, count($this->_tunes), 'no tunes in collection to begin with');
$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->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));
// }
// $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
*
* @dataProvider providerSet
*/
public function test_set($property, $value, $expected)
public function testSet($property, $value, $expected)
{
$success = $this->_tunes->set($property, $value);
$success = $this->tunes->set($property, $value);
$this->assertEquals($expected, $success);
if($success)
{
$this->assertEquals($value, $this->_tunes->get($property));
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
*
* @dataProvider providerSet
*/
public function test_magic_setter($property, $value, $expected)
public function testMagicSetter($property, $value, $expected)
{
$this->_tunes->$property = $value;
if($expected)
{
$this->assertEquals($value, $this->_tunes->get($property));
$this->tunes->$property = $value;
if ($expected) {
$this->assertEquals($value, $this->tunes->get($property));
}
}
public function provider_set()
public function providerSet()
{
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),
);
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 test_set_tc_id()
public function testSetTcId()
{
//we should start with tc_id = 0
$this->assertEquals(0, $this->_tunes->get('tc_id'), 'should start at 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');
$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');
$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
*
* @dataProvider providerAppend
*/
public function test_append($property, $value, $expected)
public function testAppend($property, $value, $expected)
{
$success = $this->_tunes->append($property, $value);
$success = $this->tunes->append($property, $value);
$this->assertEquals($expected, $success);
if($success)
{
$this->assertContains($value, $this->_tunes->get($property));
if ($success) {
$this->assertContains($value, $this->tunes->get($property));
}
}
public function provider_append()
public function providerAppend()
{
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),
);
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 test_get()
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'));
$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'));
$this->assertFalse($this->tunes->get('X'));
}
}