From f0f6b13707cf454fef1a15a71e21fa33bbcb736c Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 28 Jul 2007 18:33:43 +0000 Subject: [PATCH] - Switch to using Exception in Xml.php, Register.php, and Input.php - We now have a fully working test suite again --- Input.php | 6 +-- Register.php | 16 +++--- Xml.php | 2 +- docs/UnitTest/InputTest.php | 13 ++--- docs/UnitTest/RegisterTest.php | 92 +++++++++++++++++++++++----------- docs/UnitTest/XmlTest.php | 11 ++-- 6 files changed, 90 insertions(+), 50 deletions(-) diff --git a/Input.php b/Input.php index b30d0ec..b4bf4f6 100644 --- a/Input.php +++ b/Input.php @@ -358,7 +358,7 @@ class BSInput } else { - trigger_error('Invalid clean type specified in BSInput::clean()'); + throw new Exception('Invalid clean type specified in BSInput::clean()'); return; } @@ -395,7 +395,7 @@ class BSInput $method = strtolower($_SERVER['REQUEST_METHOD']); if (!in_array($method, array('get', 'post'))) { - trigger_error('Invalid server request method: ' . $method); + throw new Exception('Invalid server request method: ' . $method); } return $method; } @@ -417,7 +417,7 @@ class BSInput if ($ourhost != $host) { - trigger_error('No external hosts are allowed to POST to this application'); + throw new Exception('No external hosts are allowed to POST to this application'); exit; } BSRegister::Debug('remote post check = ok'); diff --git a/Register.php b/Register.php index c4bcd93..bed8ccf 100644 --- a/Register.php +++ b/Register.php @@ -31,10 +31,10 @@ * @package ISSO */ -// we need PHP5 to run -if (!function_exists('stripos')) +// we need PHP 5.2.0 to run +if (!function_exists('array_fill_keys')) { - trigger_error('You need PHP version 5.0.0 or newer to run ISSO', E_USER_ERROR); + print('You need PHP version 5.2.0 or newer to run ISSO'); exit; } @@ -270,7 +270,7 @@ class BSRegister { if (isset(self::_Instance()->registry["$key"])) { - trigger_error('Cannot overwrite a key in the registry'); + throw new Exception('Cannot overwrite a key in the registry'); return; } @@ -288,7 +288,7 @@ class BSRegister { if (!isset(self::_Instance()->registry["$key"])) { - trigger_error('You cannot unregister a key that does not exist'); + throw new Exception('You cannot unregister a key that does not exist'); return; } @@ -307,7 +307,7 @@ class BSRegister { if (!isset(self::_Instance()->registry["$key"])) { - trigger_error('Cannot access the registry with a non-existent key'); + throw new Exception('Cannot access the registry with a non-existent key'); return; } @@ -399,7 +399,7 @@ class BSRegister if (!class_exists($class)) { - trigger_error('Specifed module does not conform to the ISSO specification, or the class is missing'); + throw new Exception('Specifed module does not conform to the ISSO specification, or the class is missing'); return; } @@ -583,7 +583,7 @@ class BSRegister { if (self::GetType($module) == null AND !class_exists("BS$module")) { - trigger_error('The ' . $module . ' module is required in order to use this framework module'); + throw new Exception('The ' . $module . ' module is required in order to use this framework module'); } } } diff --git a/Xml.php b/Xml.php index 991832f..23aa9b6 100644 --- a/Xml.php +++ b/Xml.php @@ -118,7 +118,7 @@ class BSXml $error['string'] = xml_error_string($error['code']); $error['line'] = xml_get_current_line_number($parser->parser); $error['column'] = xml_get_current_column_number($parser->parser); - trigger_error("XML Error: $error[string] at line $error[line] colunn $error[column]"); + throw new Exception("XML Error: $error[string] at line $error[line] colunn $error[column]"); } // destroy the parser diff --git a/docs/UnitTest/InputTest.php b/docs/UnitTest/InputTest.php index a35d38e..7ff5887 100644 --- a/docs/UnitTest/InputTest.php +++ b/docs/UnitTest/InputTest.php @@ -97,9 +97,13 @@ class InputTest extends PHPUnit_Framework_TestCase $this->assertEquals('åß∂ƒ©˙∆˚¬…æΩ≈ç√∫≤≥÷œ∑®†¥øπ“‘’”', $this->fixture->clean('åß∂ƒ©˙∆˚¬…æΩ≈ç√∫≤≥÷œ∑®†¥øπ“‘’”', TYPE_BIN)); - $this->fixture->clean('asdfa', TYPE_THIS_DOES_NOT_EXIST); - // TODO - use exceptions - // $this->assertError(); + try + { + $this->fixture->clean('asdfa', TYPE_THIS_DOES_NOT_EXIST); + $this->fail('exception expected'); + } + catch (Exception $e) + {} } public function testCleanArray() @@ -130,7 +134,6 @@ class InputTest extends PHPUnit_Framework_TestCase public function testInputCleanArray() { - $this->setUp(); $this->fixture->inputCleanArray(array( 'abc' => TYPE_FLOAT, 'ab"c"' => TYPE_INT @@ -153,8 +156,6 @@ class InputTest extends PHPUnit_Framework_TestCase public function testPostCheck() { - define('ISSO_CHECK_POST_REFERER', true); - $this->setUp(); } } diff --git a/docs/UnitTest/RegisterTest.php b/docs/UnitTest/RegisterTest.php index 594ee30..db81747 100644 --- a/docs/UnitTest/RegisterTest.php +++ b/docs/UnitTest/RegisterTest.php @@ -26,9 +26,13 @@ class RegisterTest extends PHPUnit_Framework_TestCase public function testLoadBadModule() { - BSRegister::LoadModule('nonExistentModule'); - // TODO - use exceptions - // $this->assertError(); + try + { + BSRegister::LoadModule('nonExistentModule'); + $this->fail('exception expected'); + } + catch (Exception $e) + {} } public function testSetGetAppPath() @@ -87,11 +91,16 @@ class RegisterTest extends PHPUnit_Framework_TestCase public function testOverWriteRegister() { - BSRegister::Register('valueToOverWrite', 1); - BSRegister::Register('valueToOverWrite', 2); - // TODO - use exceptions - // $this->assertError(); - $this->assertEquals(1, BSRegister::Get('valueToOverWrite')); + try + { + BSRegister::Register('valueToOverWrite', 1); + BSRegister::Register('valueToOverWrite', 2); + $this->fail('exception expected'); + } + catch (Exception $e) + { + $this->assertEquals(1, BSRegister::Get('valueToOverWrite')); + } } public function testGet() @@ -102,27 +111,40 @@ class RegisterTest extends PHPUnit_Framework_TestCase public function testUnregister() { - BSRegister::Register('testUnregister', 1); - BSRegister::Unregister('testUnregister'); - BSRegister::Register('testUnregister', 2); - // TODO - use exceptions - // $this->assertNoErrors(); - $this->assertEquals(2, BSRegister::Get('testUnregister')); + try + { + BSRegister::Register('testUnregister', 1); + BSRegister::Unregister('testUnregister'); + BSRegister::Register('testUnregister', 2); + $this->fail('exception expected'); + } + catch (Exception $e) + { + $this->assertEquals(2, BSRegister::Get('testUnregister')); + } } - /* TODO - use exceptions public function testGetNoExist() { - BSRegister::Get('doesNotExist'); - $this->assertError(); + try + { + BSRegister::Get('doesNotExist'); + $this->fail('exception expected'); + } + catch (Exception $e) + {} } public function testUnregisterNoExist() { - BSRegister::Unregister('keyThatWontExist'); - $this->assertError(); + try + { + BSRegister::Unregister('keyThatWontExist'); + $this->fail('exception expected'); + } + catch (Exception $e) + {} } - */ public function testGetType() { @@ -133,19 +155,33 @@ class RegisterTest extends PHPUnit_Framework_TestCase $this->assertEquals(null, BSRegister::GetType('Date')); } - /* TODO - use exceptions public function testRequiredModules() { - BSRegister::RequiredModules(array('Input')); - $this->assertNoErrors(); + try + { + BSRegister::RequiredModules(array('Input')); + } + catch (Exception $e) + { + $this->fail('unexpcted exception'); + } - BSRegister::RequiredModules(array('Input', 'Db')); - $this->assertError(); + try + { + BSRegister::RequiredModules(array('Input', 'Db')); + $this->fail('exception expected'); + } + catch (Exception $e) + {} - BSRegister::RequiredModules(array('Date')); - $this->assertError(); + try + { + BSRegister::RequiredModules(array('Date')); + $this->fail('exception expected'); + } + catch (Exception $e) + {} } - */ } ?> \ No newline at end of file diff --git a/docs/UnitTest/XmlTest.php b/docs/UnitTest/XmlTest.php index 2a642a5..d684d85 100644 --- a/docs/UnitTest/XmlTest.php +++ b/docs/UnitTest/XmlTest.php @@ -44,10 +44,13 @@ class XmlTest extends PHPUnit_Framework_TestCase { $xml = 'soemValue'; - BSXml::Parse($xml); - - // TODO - use exceptions - // $this->assertError(); + try + { + BSXml::Parse($xml); + $this->fail('exception expcted'); + } + catch (Exception $e) + {} } public function testUnifyNode() -- 2.22.5