/** * @dataProvider instanceProvider * * @since 1.20 * * @param GenericArrayObject $list * * @covers GenericArrayObject::offsetUnset */ public function testUnset(GenericArrayObject $list) { if ($list->isEmpty()) { $this->assertTrue(true); // We cannot test unset if there are no elements } else { $offset = $list->getIterator()->key(); $count = $list->count(); $list->offsetUnset($offset); $this->assertEquals($count - 1, $list->count()); } if (!$list->isEmpty()) { $offset = $list->getIterator()->key(); $count = $list->count(); unset($list[$offset]); $this->assertEquals($count - 1, $list->count()); } }
/** * @see ArrayObject::offsetUnset() * * @since 1.21 * * @param mixed $index */ public function offsetUnset($index) { if ($this->offsetExists($index)) { /** * @var Site $site */ $site = $this->offsetGet($index); unset($this->byGlobalId[$site->getGlobalId()]); unset($this->byInternalId[$site->getInternalId()]); $ids = $site->getNavigationIds(); foreach ($ids as $navId) { unset($this->byNavigationId[$navId]); } } parent::offsetUnset($index); }
/** * @see ArrayObject::offsetUnset() * * @since 1.21 * * @param mixed $index */ public function offsetUnset($index) { if ($this->offsetExists($index)) { /** * @var Site $site */ $site = $this->offsetGet($index); unset($this->byGlobalId[$site->getGlobalId()]); unset($this->byInternalId[$site->getInternalId()]); } parent::offsetUnset($index); }
/** * @dataProvider instanceProvider * * @since 1.20 * * @param GenericArrayObject $list */ public function testUnset(GenericArrayObject $list) { if (!$list->isEmpty()) { $offset = $list->getIterator()->key(); $count = $list->count(); $list->offsetUnset($offset); $this->assertEquals($count - 1, $list->count()); } if (!$list->isEmpty()) { $offset = $list->getIterator()->key(); $count = $list->count(); unset($list[$offset]); $this->assertEquals($count - 1, $list->count()); } $exception = null; try { $list->offsetUnset('sdfsedtgsrdysftu'); } catch (\Exception $exception) { } $this->assertInstanceOf('\\Exception', $exception); }