/** * Tests the `ArrayAccess` interface implementation for manipulating values by direct offsets. * * @return void */ public function testArrayAccessOffsetMethods() { $collection = new Collection(array('data' => array('foo', 'bar', 'baz' => 'dib'))); $this->assertTrue($collection->offsetExists(0)); $this->assertTrue($collection->offsetExists(1)); $this->assertTrue($collection->offsetExists('0')); $this->assertTrue($collection->offsetExists('baz')); $this->assertFalse($collection->offsetExists('2')); $this->assertFalse($collection->offsetExists('bar')); $this->assertFalse($collection->offsetExists(2)); $this->assertEqual('foo', $collection->offsetSet('bar', 'foo')); $this->assertTrue($collection->offsetExists('bar')); $this->assertNull($collection->offsetUnset('bar')); $this->assertFalse($collection->offsetExists('bar')); }
/** * Tests the `ArrayAccess` interface implementation for manipulating values by direct offsets. */ public function testArrayAccessOffsetMethods() { $collection = new Collection(array('data' => array('foo', 'bar', 'baz' => 'dib'))); $this->assertTrue($collection->offsetExists(0)); $this->assertTrue($collection->offsetExists(1)); $this->assertTrue($collection->offsetExists('0')); $this->assertTrue($collection->offsetExists('baz')); $this->assertFalse($collection->offsetExists('2')); $this->assertFalse($collection->offsetExists('bar')); $this->assertFalse($collection->offsetExists(2)); $this->assertEqual('foo', $collection->offsetSet('bar', 'foo')); $this->assertTrue($collection->offsetExists('bar')); $this->assertNull($collection->offsetUnset('bar')); $this->assertFalse($collection->offsetExists('bar')); $data = array('Hello', 2, 3, null, 6, false, true, 0); $collection = new Collection(array('data' => $data)); $cpt = 0; foreach ($collection as $i => $word) { $this->assertTrue(isset($collection[$cpt])); $cpt++; } $this->assertIdentical(8, $cpt); }