From 7d215c9af473e31c41741808935703814c20fb90 Mon Sep 17 00:00:00 2001 From: Vyacheslav Agafonov Date: Fri, 25 Nov 2011 13:54:31 +0400 Subject: [PATCH] replace Exception on GeneralException --- form/Form.php | 2 +- form/FormField.php | 6 +++--- form/FormViewHelper.php | 4 ++-- tests/form/FormFieldTest.php | 7 ++++--- tests/form/FormTest.php | 3 ++- tests/form/FormViewHelperTest.php | 8 +++----- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/form/Form.php b/form/Form.php index 04e43a3..c867b0d 100644 --- a/form/Form.php +++ b/form/Form.php @@ -39,7 +39,7 @@ abstract class Form public function isValid($data) { if (!is_array($data)) { - throw new Exception(__CLASS__ . '::' . __METHOD__ . ' expects an array'); + throw new InitializationException(__CLASS__ . '::' . __METHOD__ . ' expects an array'); } foreach ($this->fields as $field_name => $field) { diff --git a/form/FormField.php b/form/FormField.php index baac180..0e93d03 100644 --- a/form/FormField.php +++ b/form/FormField.php @@ -72,7 +72,7 @@ class FormField $name = $validator . 'Validator'; $validator = new $name(); } else { - throw new Exception('Invalid validator provided to addValidator; must be string or iValidator'); + throw new InitializationException('Invalid validator provided to addValidator; must be string or iValidator'); } $this->validators[$name] = $validator; return $this; @@ -94,7 +94,7 @@ class FormField $name = $filter . 'Filter'; $filter = new $name(); } else { - throw new Exception('Invalid filter provided to addFilter; must be string or iFilter'); + throw new InitializationException('Invalid filter provided to addFilter; must be string or iFilter'); } $this->filters[$name] = $filter; return $this; @@ -147,7 +147,7 @@ class FormField if (!$validator->isValid($val, $context)) { $valid = false; if (!$this->default_message) { - throw new Exception('Define default message for array fields'); + throw new InitializationException('Define default message for array fields'); } $this->message = $this->default_message; } diff --git a/form/FormViewHelper.php b/form/FormViewHelper.php index a1186f8..b87487d 100644 --- a/form/FormViewHelper.php +++ b/form/FormViewHelper.php @@ -18,7 +18,7 @@ class FormViewHelper extends ViewHelper { if ($this->data === null) { if ($form == null) { - throw new Exception('Form name required for helper init'); + throw new InitializationException('Form name required for helper init'); } $this->data = Session::get($form, array()); Session::del($form); @@ -34,7 +34,7 @@ class FormViewHelper extends ViewHelper return $this->view->escape($default); } - public function message($field) + public function message($fgrepield) { if (isset($this->data['messages'][$field])) { return '' . $this->view->escape($this->data['messages'][$field]) . ''; diff --git a/tests/form/FormFieldTest.php b/tests/form/FormFieldTest.php index 29d731d..8a3cc92 100644 --- a/tests/form/FormFieldTest.php +++ b/tests/form/FormFieldTest.php @@ -15,6 +15,7 @@ require_once dirname(__FILE__) . '/../../validator/NotEmptyValidator.php'; require_once dirname(__FILE__) . '/../../validator/RegexValidator.php'; require_once dirname(__FILE__) . '/../../validator/EmailValidator.php'; require_once dirname(__FILE__) . '/../../form/FormField.php'; +require_once dirname(__FILE__) . '/../../exception/InitializationException.php'; class FormFieldTest extends PHPUnit_Framework_TestCase { @@ -100,7 +101,7 @@ class FormFieldTest extends PHPUnit_Framework_TestCase $validator = true; $tmp_form_field = new FormField(); // @TODO Fix exception type - $this->setExpectedException('Exception', 'Invalid validator provided to addValidator; must be string or iValidator'); // Text of Exception + $this->setExpectedException('InitializationException', 'Invalid validator provided to addValidator; must be string or iValidator'); // Text of Exception $tmp_form_field->addValidator($validator); } @@ -144,7 +145,7 @@ class FormFieldTest extends PHPUnit_Framework_TestCase $filter = new NotEmptyValidator(); $form_field = new FormField(); // @TODO Fix exception type - $this->setExpectedException('Exception', 'Invalid filter provided to addFilter; must be string or iFilter'); // Text of exception + $this->setExpectedException('InitializationException', 'Invalid filter provided to addFilter; must be string or iFilter'); // Text of exception $form_field->addFilter($filter); } @@ -217,7 +218,7 @@ class FormFieldTest extends PHPUnit_Framework_TestCase ); $form_field = new FormField(); $form_field->addValidator('NotEmpty'); - $this->setExpectedException('Exception', 'Define default message for array fields'); + $this->setExpectedException('InitializationException', 'Define default message for array fields'); $form_field->isValid($test_array); } diff --git a/tests/form/FormTest.php b/tests/form/FormTest.php index 4650e2f..22ff327 100644 --- a/tests/form/FormTest.php +++ b/tests/form/FormTest.php @@ -17,6 +17,7 @@ require_once dirname(__FILE__) . '/../../validator/Validator.php'; require_once dirname(__FILE__) . '/../../validator/RegexValidator.php'; require_once dirname(__FILE__) . '/../../validator/NotEmptyValidator.php'; require_once dirname(__FILE__) . '/../../validator/EmailValidator.php'; +require_once dirname(__FILE__) . '/../../exception/InitializationException.php'; class FormTest extends PHPUnit_Framework_TestCase { @@ -51,7 +52,7 @@ class FormTest extends PHPUnit_Framework_TestCase { $form = new NotEmptyForm(); // @TODO Fix exception type - $this->setExpectedException('Exception', 'Form::Form::isValid expects an array'); + $this->setExpectedException('InitializationException', 'Form::Form::isValid expects an array'); $form->isValid(''); } diff --git a/tests/form/FormViewHelperTest.php b/tests/form/FormViewHelperTest.php index f8b15b1..8f569b1 100644 --- a/tests/form/FormViewHelperTest.php +++ b/tests/form/FormViewHelperTest.php @@ -14,6 +14,7 @@ require_once dirname(__FILE__) . '/../../view/PHPView.php'; require_once dirname(__FILE__) . '/../../view/helpers/ViewHelper.php'; require_once dirname(__FILE__) . '/../../form/FormViewHelper.php'; require_once dirname(__FILE__) . '/../../session/Session.php'; +require_once dirname(__FILE__) . '/../../exception/InitializationException.php'; class FormViewHelperTest extends PHPUnit_Framework_TestCase { @@ -35,7 +36,7 @@ class FormViewHelperTest extends PHPUnit_Framework_TestCase public function testFormUnsetFormName() { $helper = new FormViewHelper($this->view); - $this->setExpectedException('Exception', 'Form name required for helper init'); + $this->setExpectedException('InitializationException', 'Form name required for helper init'); // @TODO Refactor for form name is required param? $helper->form(); } @@ -43,7 +44,7 @@ class FormViewHelperTest extends PHPUnit_Framework_TestCase public function testFormEmptyFormName() { $helper = new FormViewHelper($this->view); - $this->setExpectedException('Exception', 'Form name required for helper init'); + $this->setExpectedException('InitializationException', 'Form name required for helper init'); $helper->form(''); } @@ -80,14 +81,11 @@ class FormViewHelperTest extends PHPUnit_Framework_TestCase { $helper = new FormViewHelper($this->view); $helper->form($this->formname); - $value = $helper->message('field1'); $this->assertSame('' . $this->view->escape('Can\'t serialize "value"') . '', $value); } - public function testMessageNotSet() { - $helper = new FormViewHelper($this->view); $helper->form($this->formname);