From 3fe17b4d0b69ac8c811f8c2f5f73262c7b6c475f Mon Sep 17 00:00:00 2001 From: Ralph Schindler Date: Mon, 27 Sep 2010 11:18:10 -0500 Subject: [PATCH] Miletones/Exceptions - Refactored various tests for Application, Config, Console, Currency and Date components --- src/Writer/AbstractFileWriter.php | 4 ++-- test/ConfigTest.php | 14 +++++++------- test/IniTest.php | 18 +++++++++--------- test/Writer/ArrayWriterTest.php | 6 +++--- test/Writer/IniTest.php | 8 ++++---- test/Writer/XmlTest.php | 8 ++++---- test/XmlTest.php | 16 ++++++++-------- 7 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/Writer/AbstractFileWriter.php b/src/Writer/AbstractFileWriter.php index a09ab54..8e7dd84 100644 --- a/src/Writer/AbstractFileWriter.php +++ b/src/Writer/AbstractFileWriter.php @@ -101,11 +101,11 @@ public function write($filename = null, Config\Config $config = null, $exclusive } if ($this->_filename === null) { - throw new Config\Exception\InvalidArugmentException('No filename was set'); + throw new Config\Exception\InvalidArgumentException('No filename was set'); } if ($this->_config === null) { - throw new Config\Exception\InvalidArugmentException('No config was set'); + throw new Config\Exception\InvalidArgumentException('No config was set'); } $configString = $this->render(); diff --git a/test/ConfigTest.php b/test/ConfigTest.php index 49ff215..8152874 100644 --- a/test/ConfigTest.php +++ b/test/ConfigTest.php @@ -126,14 +126,14 @@ public function testModification() public function testNoModifications() { - $this->setExpectedException('\\Zend\\Config\\Exception', 'is read only'); + $this->setExpectedException('Zend\Config\Exception\InvalidArgumentException', 'is read only'); $config = new Config($this->_all); $config->hostname = 'test'; } public function testNoNestedModifications() { - $this->setExpectedException('\\Zend\\Config\\Exception', 'is read only'); + $this->setExpectedException('Zend\Config\Exception\InvalidArgumentException', 'is read only'); $config = new Config($this->_all); $config->db->host = 'test'; } @@ -195,7 +195,7 @@ public function testArray() public function testErrorWriteToReadOnly() { - $this->setExpectedException('\\Zend\\Config\\Exception', 'read only'); + $this->setExpectedException('Zend\Config\Exception\InvalidArgumentException', 'read only'); $config = new Config($this->_all); $config->test = '32'; } @@ -268,7 +268,7 @@ public function testUnsetException() $this->assertTrue(isset($config->hostname)); // top level - $this->setExpectedException('\\Zend\\Config\\Exception', 'is read only'); + $this->setExpectedException('Zend\Config\Exception\InvalidArgumentException', 'is read only'); unset($config->hostname); } @@ -354,7 +354,7 @@ public function testSetReadOnly() $config->b = 'b'; $config->setReadOnly(); - $this->setExpectedException('\\Zend\\Config\\Exception', 'is read only'); + $this->setExpectedException('Zend\Config\Exception\InvalidArgumentException', 'is read only'); $config->c = 'c'; } @@ -394,14 +394,14 @@ public function testMergeHonoursAllowModificationsFlagAtAllLevels() $config2->merge($config); try { $config2->key2 = 'no'; - } catch (\Zend\Config\Exception $e) { + } catch (\Zend\Config\Exception\RuntimeException $e) { $this->fail('Unexpected exception at top level has been raised: ' . $e->getMessage()); } $this->assertEquals('no', $config2->key2); try { $config2->key->nested = 'no'; - } catch (\Zend\Config\Exception $e) { + } catch (\Zend\Config\Exception\RuntimeException $e) { $this->fail('Unexpected exception on nested object has been raised: ' . $e->getMessage()); } $this->assertEquals('no', $config2->key->nested); diff --git a/test/IniTest.php b/test/IniTest.php index 954ff9d..92b9321 100644 --- a/test/IniTest.php +++ b/test/IniTest.php @@ -108,7 +108,7 @@ public function testMultiDepthExtends() public function testErrorNoExtendsSection() { - $this->setExpectedException('\\Zend\\Config\\Exception', 'cannot be found'); + $this->setExpectedException('Zend\Config\Exception\RuntimeException', 'cannot be found'); $config = new Ini($this->_iniFileConfig, 'extendserror'); } @@ -119,7 +119,7 @@ public function testInvalidKeys() try { $config = new Ini($this->_iniFileConfig, $section); $this->fail('An expected Zend\\Config\\Exception has not been raised'); - } catch (\Zend\Config\Exception $expected) { + } catch (\Zend\Config\Exception\RuntimeException $expected) { $this->assertContains('Invalid key', $expected->getMessage()); } } @@ -127,7 +127,7 @@ public function testInvalidKeys() public function testZF426() { - $this->setExpectedException('\\Zend\\Config\\Exception', 'Cannot create sub-key for'); + $this->setExpectedException('Zend\Config\Exception\RuntimeException', 'Cannot create sub-key for'); $config = new Ini($this->_iniFileConfig, 'zf426'); } @@ -164,32 +164,32 @@ public function testZF414() public function testZF415() { - $this->setExpectedException('\\Zend\\Config\\Exception', 'circular inheritance'); + $this->setExpectedException('Zend\Config\Exception\RuntimeException', 'circular inheritance'); $config = new Ini($this->_iniFileCircularConfig, null); } public function testErrorNoFile() { - $this->setExpectedException('\\Zend\\Config\\Exception', 'Filename is not set'); + $this->setExpectedException('Zend\Config\Exception\InvalidArgumentException', 'Filename is not set'); $config = new Ini('',''); } public function testErrorMultipleExensions() { - $this->setExpectedException('\\Zend\\Config\\Exception', 'may not extend multiple sections'); + $this->setExpectedException('Zend\Config\Exception\RuntimeException', 'may not extend multiple sections'); $config = new Ini($this->_iniFileMultipleInheritanceConfig, 'three'); zend::dump($config); } public function testErrorNoSectionFound() { - $this->setExpectedException('\\Zend\\Config\\Exception', 'cannot be found'); + $this->setExpectedException('Zend\Config\Exception\InvalidArgumentException', 'cannot be found'); $config = new Ini($this->_iniFileConfig,'notthere'); } public function testErrorNoSectionFoundWhenMultipleSectionsProvided() { - $this->setExpectedException('\\Zend\\Config\\Exception', 'cannot be found'); + $this->setExpectedException('Zend\Config\Exception\InvalidArgumentException', 'cannot be found'); $config = new Ini($this->_iniFileConfig,array('all', 'notthere')); } @@ -217,7 +217,7 @@ public function testZF3196_InvalidIniFile() try { $config = new Ini($this->_iniFileInvalid); $this->fail('An expected Zend\Config\Exception has not been raised'); - } catch (\Zend\Config\Exception $expected) { + } catch (\Zend\Config\Exception\RuntimeException $expected) { $this->assertRegexp('/(Error parsing|syntax error, unexpected)/', $expected->getMessage()); } diff --git a/test/Writer/ArrayWriterTest.php b/test/Writer/ArrayWriterTest.php index d617d90..3f5c704 100644 --- a/test/Writer/ArrayWriterTest.php +++ b/test/Writer/ArrayWriterTest.php @@ -50,21 +50,21 @@ public function tearDown() public function testNoFilenameSet() { $writer = new ArrayWriter(array('config' => new Config(array()))); - $this->setExpectedException('\\Zend\\Config\\Exception', 'No filename was set'); + $this->setExpectedException('Zend\Config\Exception\InvalidArgumentException', 'No filename was set'); $writer->write(); } public function testNoConfigSet() { $writer = new ArrayWriter(array('filename' => $this->_tempName)); - $this->setExpectedException('\\Zend\\Config\\Exception', 'No config was set'); + $this->setExpectedException('Zend\Config\Exception\InvalidArgumentException', 'No config was set'); $writer->write(); } public function testFileNotWritable() { $writer = new ArrayWriter(array('config' => new Config(array()), 'filename' => '/../../../')); - $this->setExpectedException('\\Zend\\Config\\Exception', 'Could not write to file'); + $this->setExpectedException('Zend\Config\Exception\RuntimeException', 'Could not write to file'); $writer->write(); } diff --git a/test/Writer/IniTest.php b/test/Writer/IniTest.php index bf64d66..583445e 100644 --- a/test/Writer/IniTest.php +++ b/test/Writer/IniTest.php @@ -51,14 +51,14 @@ public function tearDown() public function testNoFilenameSet() { $writer = new Ini(array('config' => new Config(array()))); - $this->setExpectedException('\\Zend\\Config\\Exception', 'No filename was set'); + $this->setExpectedException('Zend\Config\Exception\InvalidArgumentException', 'No filename was set'); $writer->write(); } public function testNoConfigSet() { $writer = new Ini(array('filename' => $this->_tempName)); - $this->setExpectedException('\\Zend\\Config\\Exception', 'No config was set'); + $this->setExpectedException('Zend\Config\Exception\InvalidArgumentException', 'No config was set'); $writer->write(); } @@ -66,7 +66,7 @@ public function testFileNotWritable() { $writer = new Ini(array('config' => new Config(array()), 'filename' => '/../../../')); - $this->setExpectedException('\\Zend\\Config\\Exception', 'Could not write to file'); + $this->setExpectedException('Zend\Config\Exception\RuntimeException', 'Could not write to file'); $writer->write(); } @@ -213,7 +213,7 @@ public function testNoDoubleQuoutesInValue() { $config = new Config(array('default' => array('test' => 'fo"o'))); - $this->setExpectedException('\\Zend\\Config\\Exception', 'Value can not contain double quotes'); + $this->setExpectedException('Zend\Config\Exception\RuntimeException', 'Value can not contain double quotes'); $writer = new Ini(array('config' => $config, 'filename' => $this->_tempName)); $writer->write(); } diff --git a/test/Writer/XmlTest.php b/test/Writer/XmlTest.php index d4ff8fe..7642d63 100644 --- a/test/Writer/XmlTest.php +++ b/test/Writer/XmlTest.php @@ -52,7 +52,7 @@ public function testNoFilenameSet() { $writer = new Xml(array('config' => new Config(array()))); - $this->setExpectedException('\\Zend\\Config\\Exception', 'No filename was set'); + $this->setExpectedException('Zend\Config\Exception\InvalidArgumentException', 'No filename was set'); $writer->write(); } @@ -60,7 +60,7 @@ public function testNoConfigSet() { $writer = new Xml(array('filename' => $this->_tempName)); - $this->setExpectedException('\\Zend\\Config\\Exception', 'No config was set'); + $this->setExpectedException('Zend\Config\Exception\InvalidArgumentException', 'No config was set'); $writer->write(); } @@ -68,7 +68,7 @@ public function testFileNotWritable() { $writer = new Xml(array('config' => new Config(array()), 'filename' => '/../../../')); - $this->setExpectedException('\\Zend\\Config\\Exception', 'Could not write to file'); + $this->setExpectedException('Zend\Config\Exception\RuntimeException', 'Could not write to file'); $writer->write(); } @@ -165,7 +165,7 @@ public function testMixedArrayFailure() { $config = new Config(array('foo' => array('bar' => array('a', 'b', 'c' => 'd')))); - $this->setExpectedException('\\Zend\\Config\\Exception', 'Mixing of string and numeric keys is not allowed'); + $this->setExpectedException('Zend\Config\Exception\RuntimeException', 'Mixing of string and numeric keys is not allowed'); $writer = new Xml(array('config' => $config, 'filename' => $this->_tempName)); $writer->write(); } diff --git a/test/XmlTest.php b/test/XmlTest.php index 4ee45bc..ecb5703 100644 --- a/test/XmlTest.php +++ b/test/XmlTest.php @@ -87,19 +87,19 @@ public function testMultiDepthExtends() public function testErrorNoInitialSection() { - $this->setExpectedException('\\Zend\\Config\\Exception', 'cannot be found in'); + $this->setExpectedException('Zend\Config\Exception\InvalidArgumentException', 'cannot be found in'); $config = @new Xml($this->_xmlFileConfig, 'notthere'); } public function testErrorNoInitialSectionWhenArrayOfSectionsSpecified() { - $this->setExpectedException('\\Zend\\Config\\Exception', 'cannot be found in'); + $this->setExpectedException('Zend\Config\Exception\InvalidArgumentException', 'cannot be found in'); $config = @new Xml($this->_xmlFileConfig, array('notthere', 'all')); } public function testErrorNoExtendsSection() { - $this->setExpectedException('\\Zend\\Config\\Exception', 'cannot be found'); + $this->setExpectedException('Zend\Config\Exception\RuntimeException', 'cannot be found'); $config = new Xml($this->_xmlFileConfig, 'extendserror'); } @@ -135,13 +135,13 @@ public function testZF414() public function testZF415() { - $this->setExpectedException('\\Zend\\Config\\Exception', 'circular inheritance'); + $this->setExpectedException('Zend\Config\Exception\RuntimeException', 'circular inheritance'); $config = new Xml($this->_xmlFileCircularConfig, null); } public function testErrorNoFile() { - $this->setExpectedException('\\Zend\\Config\\Exception', 'Filename is not set'); + $this->setExpectedException('Zend\Config\Exception\InvalidArgumentException', 'Filename is not set'); $config = new Xml('',null); } @@ -185,7 +185,7 @@ public function testZF2437_ArraysWithMultipleChildren() */ public function testInvalidXmlFile() { - $this->setExpectedException('\\Zend\\Config\\Exception', 'parser error'); + $this->setExpectedException('Zend\Config\Exception\InvalidArgumentException', 'parser error'); $config = new Xml($this->_xmlFileInvalid); } @@ -194,7 +194,7 @@ public function testInvalidXmlFile() */ public function testMissingXmlFile() { - $this->setExpectedException('\\Zend\\Config\\Exception', 'failed to load'); + $this->setExpectedException('Zend\Config\Exception\InvalidArgumentException', 'failed to load'); $config = new Xml('I/dont/exist'); } @@ -251,7 +251,7 @@ public function testNonExistentConstant() EOT; - $this->setExpectedException('\\Zend\\Config\\Exception', "Constant with name 'ZEND_CONFIG_XML_TEST_NON_EXISTENT_CONSTANT' was not defined"); + $this->setExpectedException('Zend\Config\Exception\RuntimeException', "Constant with name 'ZEND_CONFIG_XML_TEST_NON_EXISTENT_CONSTANT' was not defined"); $config = new Xml($string, 'all'); }