public function testClearingAttachedItemsShouldNotCauseIterationToRaiseExceptions() { $form = new Form(); $form->addElements(array('username' => 'text', 'password' => 'text')); $form->clearElements(); try { foreach ($form as $item) { } } catch (\Zend\Form\Exception\UnexpectedValueException $e) { $message = "Clearing elements prior to iteration should not cause iteration to fail;\n" . $e->getMessage(); $this->fail($message); } $form->addElements(array('username' => 'text', 'password' => 'text'))->addDisplayGroup(array('username', 'password'), 'login'); $form->clearDisplayGroups(); try { foreach ($form as $item) { } } catch (\Zend\Form\Exception\UnexpectedValueException $e) { $message = "Clearing display groups prior to iteration should not cause iteration to fail;\n" . $e->getMessage(); $this->fail($message); } $subForm = new \Zend\Form\SubForm(); $form->addSubForm($subForm, 'foo'); $form->clearSubForms(); try { foreach ($form as $item) { } } catch (\Zend\Form\Exception\UnexpectedValueException $e) { $message = "Clearing sub forms prior to iteration should not cause iteration to fail;\n" . $e->getMessage(); $this->fail($message); } }