tunes = new TuneCollection(); } /** * test the implementation of the Iterator interface * 100% coverage! ;) */ 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->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 testPop() { $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 providerSet */ public function testSet($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 providerSet */ public function testMagicSetter($property, $value, $expected) { $this->tunes->$property = $value; if ($expected) { $this->assertEquals($value, $this->tunes->get($property)); } } public function providerSet() { 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 testSetTcId() { //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 providerAppend */ public function testAppend($property, $value, $expected) { $success = $this->tunes->append($property, $value); $this->assertEquals($expected, $success); if ($success) { $this->assertContains($value, $this->tunes->get($property)); } } public function providerAppend() { 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 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')); //X is not a property, so we should get FALSE $this->assertFalse($this->tunes->get('X')); } }