Files
abcParser/tests/unit/memory/TuneCollectionTest.php
2016-04-15 21:44:45 -04:00

211 lines
6.6 KiB
PHP

<?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'));
}
}