<?php
/**
 * Test class for phpMorphy_Util_Collection_ArrayBased.
 * Generated by PHPUnit on 2010-12-06 at 05:04:35.
 */
class test_Collection_ArrayBased extends PHPUnit_Framework_TestCase
{
    /**
     * @var phpMorphy_Util_Collection_ArrayBased
     */
    protected $object;

    /**
     * Sets up the fixture, for example, opens a network connection.
     * This method is called before a test is executed.
     */
    protected function setUp()
    {
        $this->object = new phpMorphy_Util_Collection_ArrayBased();
    }

    protected function fixture() {
        $this->object->append(1);
        $this->object->append(2);
        $this->object->append(3);
    }

    public function testGetIterator()
    {
        $this->fixture();
        $this->assertEquals(
            array(1, 2, 3),
            iterator_to_array($this->object)
        );
    }

    public function testImportWithIterator()
    {
        $this->object->import(new ArrayIterator(array(1, 2, 3)));

        $this->assertEquals(
            array(1, 2, 3),
            iterator_to_array($this->object)
        );
    }

    public function testImportWithArray()
    {
        $this->object->import(array(1, 2, 3));

        $this->assertEquals(
            array(1, 2, 3),
            iterator_to_array($this->object)
        );
    }

    public function testAppend()
    {
        $this->fixture();
        $this->object->append(4);
        
        $this->assertEquals(
            array(1, 2, 3, 4),
            iterator_to_array($this->object)
        );
    }

    /**
     * @todo Implement testClear().
     */
    public function testClear()
    {
        $this->fixture();
        $this->assertEquals(3, $this->object->count());
        $this->object->clear();
        $this->assertEquals(0, $this->object->count());
    }

    /**
     * @todo Implement testOffsetExists().
     */
    public function testOffsetExists()
    {
        $this->fixture();
        $this->assertTrue(isset($this->object[0]));
        $this->assertTrue(isset($this->object[1]));
        $this->assertTrue(isset($this->object[2]));
        $this->assertFalse(isset($this->object[3]));
    }

    public function testOffsetGet()
    {
        $this->fixture();
        $this->assertEquals(1, $this->object[0]);
        $this->assertEquals(2, $this->object[1]);
        $this->assertEquals(3, $this->object[2]);
    }

    public function testOffsetSet()
    {
        $this->fixture();
        $this->assertEquals(1, $this->object[0]);
        $this->object[0] = 100;
        $this->assertEquals(100, $this->object[0]);
    }

    public function testOffsetUnset()
    {
        $this->fixture();
        $this->assertEquals(3, count($this->object));
        $this->assertTrue(isset($this->object[1]));

        unset($this->object[1]);

        $this->assertEquals(2, count($this->object));
        $this->assertTrue(isset($this->object[0]));
        $this->assertTrue(isset($this->object[1]));
        $this->assertFalse(isset($this->object[2]));
    }

    /**
     * @todo Implement testCount().
     */
    public function testCount()
    {
        $this->fixture();
        $this->assertEquals(3, count($this->object));
    }
}
?>
