Array Collection PHP Unit Tests

The following unit test uses SimpleTest unit test framework to test the Array Collection PHP class.

require_once('simpletest/autorun.php');
require_once('ig/ArrayCollection.class.php');
 
/**
 * Array Collection unit tests.
 * @author Ivan Georgiev
 */
class ig_test_ArrayCollection extends UnitTestCase {
 
	function testArrayCollection() {
		$obj1 =& new StdClass();
		$obj2 =& new StdClass();
		$c =& new ig_ArrayCollection();
		$this->assertTrue($c->add($obj1));
		$this->assertFalse($c->add($obj1));
		$this->assertTrue($c->add($obj2));
 
		$it =& $c->iterator();
		$this->assertIsA($it, 'ig_Iterator');
		$this->assertReference($obj1, $it->next());
		$this->assertReference($obj2, $it->next());
	}
 
	function testRemove() {
		$obj1 =& new StdClass();
		$obj2 =& new StdClass();
		$obj3 =& new StdClass();
		$c =& new ig_ArrayCollection();
		$this->assertTrue($c->add($obj1));
		$this->assertTrue($c->add($obj2));
		$this->assertTrue($c->add($obj3));
 
		$this->assertTrue($c->remove($obj2));
		$this->assertFalse($c->remove($obj2));
 
		$it =& $c->iterator();
		$this->assertIsA($it, 'ig_Iterator');
		$this->assertReference($obj1, $it->next());
		$this->assertReference($obj3, $it->next());
	}
}

See also: How To Unit Tests in PHP, Array Collection in PHP

 
php/util/arraycollection_test.txt · Last modified: 2009/10/31 23:39 (external edit)
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki