diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 21d57da5..00000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "tools/phptools"] - path = tools/phptools - url = git://github.com/ralphschindler/PHPTools.git diff --git a/composer.json b/composer.json index 2a3d0f3b..5694d107 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "zendframework/zend-mail", - "description": "Zend\\Mail component", + "description": "provides generalized functionality to compose and send both text and MIME-compliant multipart e-mail messages", "license": "BSD-3-Clause", "keywords": [ "zf2", @@ -9,11 +9,11 @@ "homepage": "https://github.com/zendframework/zend-mail", "autoload": { "psr-4": { - "Zend\\Mail\\": "src/" + "Zend\\Mail": "src/" } }, "require": { - "php": ">=5.3.23", + "php": ">=5.3.3", "zendframework/zend-crypt": "self.version", "zendframework/zend-loader": "self.version", "zendframework/zend-mime": "self.version", @@ -27,7 +27,8 @@ "phpunit/PHPUnit": "~4.0" }, "suggest": { - "zendframework/zend-servicemanager": "Zend\\ServiceManager component" + "zendframework/zend-servicemanager": "Zend\\ServiceManager component", + "zendframework/zend-validator": "Zend\\Validator component" }, "extra": { "branch-alias": { diff --git a/src/Address.php b/src/Address.php index a6b1e4ea..397afb00 100644 --- a/src/Address.php +++ b/src/Address.php @@ -1,21 +1,11 @@ addParameter($key, $value); } } @@ -99,18 +79,18 @@ public function getFieldValue($format = HeaderInterface::FORMAT_RAW) public function setEncoding($encoding) { - $this->encoding = $encoding; + // This header must be always in US-ASCII return $this; } public function getEncoding() { - return $this->encoding; + return 'ASCII'; } public function toString() { - return 'Content-Type: ' . $this->getFieldValue(HeaderInterface::FORMAT_RAW); + return 'Content-Type: ' . $this->getFieldValue(); } /** diff --git a/src/Header/Date.php b/src/Header/Date.php index d6d93360..d2b0565e 100644 --- a/src/Header/Date.php +++ b/src/Header/Date.php @@ -1,22 +1,11 @@ encoding = $encoding; + // This header must be always in US-ASCII return $this; } public function getEncoding() { - return $this->encoding; + return 'ASCII'; } public function toString() { - return 'Date: ' . $this->getFieldValue(HeaderInterface::FORMAT_RAW); + return 'Date: ' . $this->getFieldValue(); } } diff --git a/src/Header/Exception/BadMethodCallException.php b/src/Header/Exception/BadMethodCallException.php index 80292958..dfb20d57 100644 --- a/src/Header/Exception/BadMethodCallException.php +++ b/src/Header/Exception/BadMethodCallException.php @@ -1,22 +1,11 @@ 'Zend\Mail\Header\Subject', 'to' => 'Zend\Mail\Header\To', ); -} \ No newline at end of file +} diff --git a/src/Header/HeaderWrap.php b/src/Header/HeaderWrap.php index 7c2dfee9..1b2d0b79 100644 --- a/src/Header/HeaderWrap.php +++ b/src/Header/HeaderWrap.php @@ -1,22 +1,11 @@ getFieldValue(HeaderInterface::FORMAT_RAW); + return 'MIME-Version: ' . $this->getFieldValue(); } /** diff --git a/src/Header/MultipleHeadersInterface.php b/src/Header/MultipleHeadersInterface.php index 00a90e21..6e8e228d 100644 --- a/src/Header/MultipleHeadersInterface.php +++ b/src/Header/MultipleHeadersInterface.php @@ -1,22 +1,11 @@ encoding = $encoding; + // This header must be always in US-ASCII return $this; } public function getEncoding() { - return $this->encoding; + return 'ASCII'; } public function toString() { - return 'Received: ' . $this->getFieldValue(HeaderInterface::FORMAT_RAW); + return 'Received: ' . $this->getFieldValue(); } /** diff --git a/src/Header/ReplyTo.php b/src/Header/ReplyTo.php index 09583291..945f49fa 100644 --- a/src/Header/ReplyTo.php +++ b/src/Header/ReplyTo.php @@ -1,22 +1,11 @@ \Zend\Mail\Storage\Folder folder) diff --git a/src/Storage/Folder/FolderInterface.php b/src/Storage/Folder/FolderInterface.php index 27bf6c35..613f05e2 100644 --- a/src/Storage/Folder/FolderInterface.php +++ b/src/Storage/Folder/FolderInterface.php @@ -1,22 +1,11 @@ _params); - } catch (\Exception $e) { - $this->fail('exception raised while loading connection to imap server'); - } + new Storage\Imap($this->_params); } public function testConnectConfig() { - try { - $mail = new Storage\Imap(new Config\Config($this->_params)); - } catch (\Exception $e) { - $this->fail('exception raised while loading connection to imap server'); - } + new Storage\Imap(new Config\Config($this->_params)); } public function testConnectFailure() { $this->_params['host'] = 'example.example'; - try { - $mail = new Storage\Imap($this->_params); - } catch (\Exception $e) { - return; // test ok - } - - // I can only hope noone installs a imap server there - $this->fail('no exception raised while connecting to example.example'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + new Storage\Imap($this->_params); } public function testNoParams() { - try { - $mail = new Storage\Imap(array()); - } catch (\Exception $e) { - return; // test ok - } - - $this->fail('no exception raised with empty params'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + new Storage\Imap(array()); } @@ -150,11 +118,8 @@ public function testConnectSSL() } $this->_params['ssl'] = 'SSL'; - try { - $mail = new Storage\Imap($this->_params); - } catch (\Exception $e) { - $this->fail('exception raised while loading connection to imap server with SSL'); - } + new Storage\Imap($this->_params); + } public function testConnectTLS() @@ -164,51 +129,29 @@ public function testConnectTLS() } $this->_params['ssl'] = 'TLS'; - try { - $mail = new Storage\Imap($this->_params); - } catch (\Exception $e) { - $this->fail('exception raised while loading connection to imap server with TLS'); - } + new Storage\Imap($this->_params); } public function testInvalidService() { $this->_params['port'] = TESTS_ZEND_MAIL_IMAP_INVALID_PORT; - - try { - $mail = new Storage\Imap($this->_params); - } catch (\Exception $e) { - return; // test ok - } - - $this->fail('no exception while connection to invalid port'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + new Storage\Imap($this->_params); } public function testWrongService() { $this->_params['port'] = TESTS_ZEND_MAIL_IMAP_WRONG_PORT; - - try { - $mail = new Storage\Imap($this->_params); - } catch (\Exception $e) { - return; // test ok - } - - $this->fail('no exception while connection to wrong port'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + new Storage\Imap($this->_params); } public function testWrongUsername() { // this also triggers ...{chars}token for coverage $this->_params['user'] = "there is no\nnobody"; - - try { - $mail = new Storage\Imap($this->_params); - } catch (\Exception $e) { - return; // test ok - } - - $this->fail('no exception while using wrong username'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + new Storage\Imap($this->_params); } public function testWithInstanceConstruction() @@ -216,56 +159,36 @@ public function testWithInstanceConstruction() $protocol = new Protocol\Imap($this->_params['host']); $protocol->login($this->_params['user'], $this->_params['password']); // if $protocol is invalid the constructor fails while selecting INBOX - $mail = new Storage\Imap($protocol); + new Storage\Imap($protocol); } public function testWithNotConnectedInstance() { $protocol = new Protocol\Imap(); - try { - $mail = new Storage\Imap($protocol); - } catch (ProtocolException\ExceptionInterface $e) { - return; // test ok - } - - $this->fail('no exception while using not connected low-level class'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + new Storage\Imap($protocol); } public function testWithNotLoggedInstance() { $protocol = new Protocol\Imap($this->_params['host']); - try { - $mail = new Storage\Imap($protocol); - } catch (Exception\ExceptionInterface $e) { - return; // test ok - } - - $this->fail('no exception while using not logged in low-level class'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + new Storage\Imap($protocol); } public function testWrongFolder() { $this->_params['folder'] = 'this folder does not exist on your server'; - try { - $mail = new Storage\Imap($this->_params); - } catch (\Exception $e) { - return; // test ok - } - - $this->fail('no exception with not existing folder'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + new Storage\Imap($this->_params); } public function testClose() { $mail = new Storage\Imap($this->_params); - - try { - $mail->close(); - } catch (\Exception $e) { - $this->fail('exception raised while closing imap connection'); - } + $mail->close(); } /* currently imap has no top @@ -287,12 +210,7 @@ public function testHasCreate() public function testNoop() { $mail = new Storage\Imap($this->_params); - - try { - $mail->noop(); - } catch (\Exception $e) { - $this->fail('exception raised while doing nothing (noop)'); - } + $mail->noop(); } public function testCount() @@ -372,35 +290,21 @@ public function testTooLateCount() $mail->close(); // after closing we can't count messages - try { - $mail->countMessages(); - } catch (\Exception $e) { - return; // test ok - } - - $this->fail('no exception raised while counting messages on closed connection'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->countMessages(); } public function testLoadUnkownFolder() { $this->_params['folder'] = 'UnknownFolder'; - try { - $mail = new Storage\Imap($this->_params); - } catch (\Exception $e) { - return; // test ok - } - - $this->fail('no exception raised while loading unknown folder'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + new Storage\Imap($this->_params); } public function testChangeFolder() { $mail = new Storage\Imap($this->_params); - try { - $mail->selectFolder('subfolder/test'); - } catch (\Exception $e) { - $this->fail('exception raised while selecting existing folder'); - } + $mail->selectFolder('subfolder/test'); $this->assertEquals($mail->getCurrentFolder(), 'subfolder/test'); } @@ -408,34 +312,20 @@ public function testChangeFolder() public function testUnknownFolder() { $mail = new Storage\Imap($this->_params); - try { - $mail->selectFolder('/Unknown/Folder/'); - } catch (\Exception $e) { - return; // test ok - } - - $this->fail('no exception raised while selecting unknown folder'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->selectFolder('/Unknown/Folder/'); } public function testGlobalName() { $mail = new Storage\Imap($this->_params); - try { - // explicit call of __toString() needed for PHP < 5.2 - $this->assertEquals($mail->getFolders()->subfolder->__toString(), 'subfolder'); - } catch (\Exception $e) { - $this->fail('exception raised while selecting existing folder and getting global name'); - } + $this->assertEquals($mail->getFolders()->subfolder->__toString(), 'subfolder'); } public function testLocalName() { $mail = new Storage\Imap($this->_params); - try { - $this->assertEquals($mail->getFolders()->subfolder->key(), 'test'); - } catch (MailException\ExceptionInterface $e) { - $this->fail('exception raised while selecting existing folder and getting local name'); - } + $this->assertEquals($mail->getFolders()->subfolder->key(), 'test'); } public function testKeyLocalName() @@ -548,13 +438,8 @@ public function testUniqueId() public function testWrongUniqueId() { $mail = new Storage\Imap($this->_params); - try { - $mail->getNumberByUniqueId('this_is_an_invalid_id'); - } catch (\Exception $e) { - return; // test ok - } - - $this->fail('no exception while getting number for invalid id'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->getNumberByUniqueId('this_is_an_invalid_id'); } public function testCreateFolder() @@ -564,26 +449,17 @@ public function testCreateFolder() $mail->createFolder('test2', 'subfolder'); $mail->createFolder('test3', $mail->getFolders()->subfolder); - try { - $mail->getFolders()->subfolder->test1; - $mail->getFolders()->subfolder->test2; - $mail->getFolders()->subfolder->test3; - } catch (\Exception $e) { - $this->fail('could not get new folders'); - } + $mail->getFolders()->subfolder->test1; + $mail->getFolders()->subfolder->test2; + $mail->getFolders()->subfolder->test3; } public function testCreateExistingFolder() { $mail = new Storage\Imap($this->_params); - try { - $mail->createFolder('subfolder/test'); - } catch (\Exception $e) { - return; // ok - } - - $this->fail('should not be able to create existing folder'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->createFolder('subfolder/test'); } public function testRemoveFolderName() @@ -591,12 +467,8 @@ public function testRemoveFolderName() $mail = new Storage\Imap($this->_params); $mail->removeFolder('subfolder/test'); - try { - $mail->getFolders()->subfolder->test; - } catch (\Exception $e) { - return; // ok - } - $this->fail('folder still exists'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->getFolders()->subfolder->test; } public function testRemoveFolderInstance() @@ -604,42 +476,27 @@ public function testRemoveFolderInstance() $mail = new Storage\Imap($this->_params); $mail->removeFolder($mail->getFolders()->subfolder->test); - try { - $mail->getFolders()->subfolder->test; - } catch (\Exception $e) { - return; // ok - } - $this->fail('folder still exists'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->getFolders()->subfolder->test; } public function testRemoveInvalidFolder() { $mail = new Storage\Imap($this->_params); - try { - $mail->removeFolder('thisFolderDoestNotExist'); - } catch (\Exception $e) { - return; // ok - } - $this->fail('no error while removing invalid folder'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->removeFolder('thisFolderDoestNotExist'); } public function testRenameFolder() { $mail = new Storage\Imap($this->_params); - try { - $mail->renameFolder('subfolder/test', 'subfolder/test1'); - $mail->renameFolder($mail->getFolders()->subfolder->test1, 'subfolder/test'); - } catch (\Exception $e) { - $this->fail('renaming failed'); - } - try { - $mail->renameFolder('subfolder/test', 'INBOX'); - } catch (\Exception $e) { - return; // ok - } - $this->fail('no error while renaming folder to INBOX'); + $mail->renameFolder('subfolder/test', 'subfolder/test1'); + $mail->renameFolder($mail->getFolders()->subfolder->test1, 'subfolder/test'); + + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->renameFolder('subfolder/test', 'INBOX'); } public function testAppend() @@ -658,12 +515,8 @@ public function testAppend() $this->assertEquals($count + 1, $mail->countMessages()); $this->assertEquals($mail->getMessage($count + 1)->subject, 'append test'); - try { - $mail->appendMessage(''); - } catch (\Exception $e) { - return; // ok - } - $this->fail('no error while appending empty message'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->appendMessage(''); } public function testCopy() @@ -682,12 +535,8 @@ public function testCopy() $this->assertEquals($mail->getMessage($count + 1)->from, $message->from); $this->assertEquals($mail->getMessage($count + 1)->to, $message->to); - try { - $mail->copyMessage(1, 'justARandomFolder'); - } catch (\Exception $e) { - return; // ok - } - $this->fail('no error while copying to wrong folder'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->copyMessage(1, 'justARandomFolder'); } public function testSetFlags() @@ -715,12 +564,8 @@ public function testSetFlags() $this->assertFalse($message->hasFlag(Storage::FLAG_FLAGGED)); $this->assertTrue($message->hasFlag('myflag')); - try { - $mail->setFlags(1, array(Storage::FLAG_RECENT)); - } catch (\Exception $e) { - return; // ok - } - $this->fail('should not be able to set recent flag'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->setFlags(1, array(Storage::FLAG_RECENT)); } public function testCapability() @@ -757,12 +602,8 @@ public function testClosedSocketNewlineToken() $protocol->login($this->_params['user'], $this->_params['password']); $protocol->logout(); - try { - $protocol->select("foo\nbar"); - } catch (\Exception $e) { - return; // ok - } - $this->fail('no exception while using procol with closed socket'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $protocol->select("foo\nbar"); } public function testEscaping() @@ -796,12 +637,8 @@ public function testFetch() $this->assertTrue(is_array($v['FLAGS'])); } - try { - $protocol->fetch('UID', 99); - } catch (\Exception $e) { - return; // ok - } - $this->fail('no exception while fetching message'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $protocol->fetch('UID', 99); } public function testStore() diff --git a/test/Storage/MaildirFolderTest.php b/test/Storage/MaildirFolderTest.php index ff4f4997..3cb4251a 100644 --- a/test/Storage/MaildirFolderTest.php +++ b/test/Storage/MaildirFolderTest.php @@ -1,22 +1,11 @@ _params); - } catch (\Exception $e) { - $this->fail('exception raised while loading Maildir folder'); - } + new Folder\Maildir($this->_params); } public function testLoadConfig() { - try { - $mail = new Folder\Maildir(new Config\Config($this->_params)); - } catch (\Exception $e) { - $this->fail('exception raised while loading Maildir folder'); - } + new Folder\Maildir(new Config\Config($this->_params)); } public function testNoParams() { - try { - $mail = new Folder\Maildir(array()); - } catch (\Exception $e) { - return; // test ok - } - - $this->fail('no exception raised with empty params'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + new Folder\Maildir(array()); } public function testLoadFailure() { - try { - $mail = new Folder\Maildir(array('dirname' => 'This/Folder/Does/Not/Exist')); - } catch (\Exception $e) { - return; // test ok - } - - $this->fail('no exception raised while loading unknown dirname'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + new Folder\Maildir(array('dirname' => 'This/Folder/Does/Not/Exist')); } public function testLoadUnkownFolder() { $this->_params['folder'] = 'UnknownFolder'; - try { - $mail = new Folder\Maildir($this->_params); - } catch (\Exception $e) { - return; // test ok - } - - $this->fail('no exception raised while loading unknown folder'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + new Folder\Maildir($this->_params); } public function testChangeFolder() { $this->markTestIncomplete("Fail"); $mail = new Folder\Maildir($this->_params); - try { - $mail->selectFolder('subfolder.test'); - } catch (\Exception $e) { - $this->fail('exception raised while selecting existing folder'); - } + + $mail->selectFolder('subfolder.test'); $this->assertEquals($mail->getCurrentFolder(), 'subfolder.test'); } @@ -187,36 +148,25 @@ public function testChangeFolder() public function testUnknownFolder() { $mail = new Folder\Maildir($this->_params); - try { - $mail->selectFolder('/Unknown/Folder/'); - } catch (\Exception $e) { - return; // test ok - } - $this->fail('no exception raised while selecting unknown folder'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->selectFolder('/Unknown/Folder/'); } public function testGlobalName() { $this->markTestIncomplete("Fail"); $mail = new Folder\Maildir($this->_params); - try { - // explicit call of __toString() needed for PHP < 5.2 - $this->assertEquals($mail->getFolders()->subfolder->__toString(), 'subfolder'); - } catch (\Exception $e) { - $this->fail('exception raised while selecting existing folder and getting global name'); - } + + $this->assertEquals($mail->getFolders()->subfolder->__toString(), 'subfolder'); } public function testLocalName() { $this->markTestIncomplete("Fail"); $mail = new Folder\Maildir($this->_params); - try { - $this->assertEquals($mail->getFolders()->subfolder->key(), 'test'); - } catch (\Exception $e) { - $this->fail('exception raised while selecting existing folder and getting local name'); - } + + $this->assertEquals($mail->getFolders()->subfolder->key(), 'test'); } public function testIterator() @@ -398,13 +348,8 @@ public function testGetInvalidFolder() $root = $mail->getFolders(); $root->foobar = new Folder('foobar', DIRECTORY_SEPARATOR . 'foobar'); - try { - $mail->selectFolder('foobar'); - } catch (\Exception $e) { - return; // ok - } - - $this->fail('no error while getting invalid folder'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->selectFolder('foobar'); } public function testGetVanishedFolder() @@ -413,13 +358,8 @@ public function testGetVanishedFolder() $root = $mail->getFolders(); $root->foobar = new Folder('foobar', 'foobar'); - try { - $mail->selectFolder('foobar'); - } catch (\Exception $e) { - return; // ok - } - - $this->fail('no error while getting vanished folder'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->selectFolder('foobar'); } public function testGetNotSelectableFolder() @@ -428,13 +368,8 @@ public function testGetNotSelectableFolder() $root = $mail->getFolders(); $root->foobar = new Folder('foobar', 'foobar', false); - try { - $mail->selectFolder('foobar'); - } catch (\Exception $e) { - return; // ok - } - - $this->fail('no error while getting not selectable folder'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->selectFolder('foobar'); } public function testWithAdditionalFolder() diff --git a/test/Storage/MaildirMessageOldTest.php b/test/Storage/MaildirMessageOldTest.php index 607dfc68..ac0d7cbc 100644 --- a/test/Storage/MaildirMessageOldTest.php +++ b/test/Storage/MaildirMessageOldTest.php @@ -1,22 +1,11 @@ $this->_maildir)); - } catch (\Exception $e) { - $this->fail('exception raised while loading maildir'); - } + new Storage\Maildir(array('dirname' => $this->_maildir)); } public function testLoadConfig() { - try { - $mail = new Storage\Maildir(new Config\Config(array('dirname' => $this->_maildir))); - } catch (\Exception $e) { - $this->fail('exception raised while loading maildir'); - } + new Storage\Maildir(new Config\Config(array('dirname' => $this->_maildir))); } public function testLoadFailure() { - try { - $mail = new Storage\Maildir(array('dirname' => '/This/Dir/Does/Not/Exist')); - } catch (\Exception $e) { - return; // test ok - } - - $this->fail('no exception raised while loading unknown dir'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + new Storage\Maildir(array('dirname' => '/This/Dir/Does/Not/Exist')); } public function testLoadInvalid() { - try { - $mail = new Storage\Maildir(array('dirname' => __DIR__)); - } catch (\Exception $e) { - return; // test ok - } - - $this->fail('no exception while loading invalid dir'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + new Storage\Maildir(array('dirname' => __DIR__)); } public function testClose() { $mail = new Storage\Maildir(array('dirname' => $this->_maildir)); - try { - $mail->close(); - } catch (\Exception $e) { - $this->fail('exception raised while closing maildir'); - } + $mail->close(); } public function testHasTop() @@ -169,11 +134,7 @@ public function testNoop() { $mail = new Storage\Maildir(array('dirname' => $this->_maildir)); - try { - $mail->noop(); - } catch (\Exception $e) { - $this->fail('exception raised while doing nothing (noop)'); - } + $mail->noop(); } public function testCount() @@ -240,39 +201,24 @@ public function testFetchWrongSize() { $mail = new Storage\Maildir(array('dirname' => $this->_maildir)); - try { - $mail->getSize(0); - } catch (\Exception $e) { - return; // test ok - } - - $this->fail('no exception raised while getting size for message 0'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->getSize(0); } public function testFetchWrongMessageBody() { $mail = new Storage\Maildir(array('dirname' => $this->_maildir)); - try { - $mail->getMessage(0); - } catch (\Exception $e) { - return; // test ok - } - - $this->fail('no exception raised while fetching message 0'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->getMessage(0); } public function testFailedRemove() { $mail = new Storage\Maildir(array('dirname' => $this->_maildir)); - try { - $mail->removeMessage(1); - } catch (\Exception $e) { - return; // test ok - } - - $this->fail('no exception raised while deleting message (maildir is read-only)'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->removeMessage(1); } public function testHasFlag() @@ -316,13 +262,9 @@ public function testUniqueId() public function testWrongUniqueId() { $mail = new Storage\Maildir(array('dirname' => $this->_maildir)); - try { - $mail->getNumberByUniqueId('this_is_an_invalid_id'); - } catch (\Exception $e) { - return; // test ok - } - $this->fail('no exception while getting number for invalid id'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->getNumberByUniqueId('this_is_an_invalid_id'); } public function isFileTest($dir) diff --git a/test/Storage/MaildirWritableTest.php b/test/Storage/MaildirWritableTest.php index 87951d3a..36e6133c 100644 --- a/test/Storage/MaildirWritableTest.php +++ b/test/Storage/MaildirWritableTest.php @@ -1,22 +1,11 @@ createFolder('test3', $mail->getFolders()->subfolder); $mail->createFolder('foo.bar'); - try { - $mail->selectFolder($mail->getFolders()->subfolder->test1); - $mail->selectFolder($mail->getFolders()->subfolder->test2); - $mail->selectFolder($mail->getFolders()->subfolder->test3); - $mail->selectFolder($mail->getFolders()->foo->bar); - } catch (\Exception $e) { - $this->fail('could not get new folders'); - } + $mail->selectFolder($mail->getFolders()->subfolder->test1); + $mail->selectFolder($mail->getFolders()->subfolder->test2); + $mail->selectFolder($mail->getFolders()->subfolder->test3); + $mail->selectFolder($mail->getFolders()->foo->bar); // to tear down $this->_subdirs[] = '.subfolder.test1'; @@ -155,37 +138,22 @@ public function testCreateFolder() public function testCreateFolderEmtpyPart() { $mail = new Writable\Maildir($this->_params); - try { - $mail->createFolder('foo..bar'); - } catch (\Exception $e) { - return; //ok - } - - $this->fail('no exception while creating folder with empty part name'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->createFolder('foo..bar'); } public function testCreateFolderSlash() { $mail = new Writable\Maildir($this->_params); - try { - $mail->createFolder('foo/bar'); - } catch (\Exception $e) { - return; //ok - } - - $this->fail('no exception while creating folder with slash'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->createFolder('foo/bar'); } public function testCreateFolderDirectorySeparator() { $mail = new Writable\Maildir($this->_params); - try { - $mail->createFolder('foo' . DIRECTORY_SEPARATOR . 'bar'); - } catch (\Exception $e) { - return; //ok - } - - $this->fail('no exception while creating folder with DIRECTORY_SEPARATOR'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->createFolder('foo' . DIRECTORY_SEPARATOR . 'bar'); } public function testCreateFolderExistingDir() @@ -194,26 +162,16 @@ public function testCreateFolderExistingDir() $mail = new Writable\Maildir($this->_params); unset($mail->getFolders()->subfolder->test); - try { - $mail->createFolder('subfolder.test'); - } catch (\Exception $e) { - return; // ok - } - - $this->fail('should not be able to create existing folder'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->createFolder('subfolder.test'); } public function testCreateExistingFolder() { $mail = new Writable\Maildir($this->_params); - try { - $mail->createFolder('subfolder.test'); - } catch (\Exception $e) { - return; // ok - } - - $this->fail('should not be able to create existing folder'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->createFolder('subfolder.test'); } public function testRemoveFolderName() @@ -222,12 +180,8 @@ public function testRemoveFolderName() $mail = new Writable\Maildir($this->_params); $mail->removeFolder('INBOX.subfolder.test'); - try { - $mail->selectFolder($mail->getFolders()->subfolder->test); - } catch (\Exception $e) { - return; // ok - } - $this->fail('folder still exists'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->selectFolder($mail->getFolders()->subfolder->test); } public function testRemoveFolderInstance() @@ -236,25 +190,16 @@ public function testRemoveFolderInstance() $mail = new Writable\Maildir($this->_params); $mail->removeFolder($mail->getFolders()->subfolder->test); - try { - $mail->selectFolder($mail->getFolders()->subfolder->test); - } catch (\Exception $e) { - return; // ok - } - $this->fail('folder still exists'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->selectFolder($mail->getFolders()->subfolder->test); } public function testRemoveFolderWithChildren() { $mail = new Writable\Maildir($this->_params); - try { - $mail->removeFolder($mail->getFolders()->subfolder); - } catch (\Exception $e) { - return; // ok - } - - $this->fail('should not be able to remove a folder with children'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->removeFolder($mail->getFolders()->subfolder); } public function testRemoveSelectedFolder() @@ -263,43 +208,28 @@ public function testRemoveSelectedFolder() $mail = new Writable\Maildir($this->_params); $mail->selectFolder('subfolder.test'); - try { - $mail->removeFolder('subfolder.test'); - } catch (\Exception $e) { - return; // ok - } - $this->fail('no error while removing selected folder'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->removeFolder('subfolder.test'); } public function testRemoveInvalidFolder() { $mail = new Writable\Maildir($this->_params); - try { - $mail->removeFolder('thisFolderDoestNotExist'); - } catch (\Exception $e) { - return; // ok - } - $this->fail('no error while removing invalid folder'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->removeFolder('thisFolderDoestNotExist'); } public function testRenameFolder() { $this->markTestIncomplete("Fail"); $mail = new Writable\Maildir($this->_params); - try { - $mail->renameFolder('INBOX.subfolder', 'INBOX.foo'); - $mail->renameFolder($mail->getFolders()->foo, 'subfolder'); - } catch (\Exception $e) { - $this->fail('renaming failed'); - } - try { - $mail->renameFolder('INBOX', 'foo'); - } catch (\Exception $e) { - return; // ok - } - $this->fail('no error while renaming INBOX'); + $mail->renameFolder('INBOX.subfolder', 'INBOX.foo'); + $mail->renameFolder($mail->getFolders()->foo, 'subfolder'); + + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->renameFolder('INBOX', 'foo'); } public function testRenameSelectedFolder() @@ -308,24 +238,16 @@ public function testRenameSelectedFolder() $mail = new Writable\Maildir($this->_params); $mail->selectFolder('subfolder.test'); - try { - $mail->renameFolder('subfolder.test', 'foo'); - } catch (\Exception $e) { - return; // ok - } - $this->fail('no error while renaming selected folder'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->renameFolder('subfolder.test', 'foo'); } public function testRenameToChild() { $mail = new Writable\Maildir($this->_params); - try { - $mail->renameFolder('subfolder.test', 'subfolder.test.foo'); - } catch (\Exception $e) { - return; // ok - } - $this->fail('no error while renaming folder to child of old'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->renameFolder('subfolder.test', 'subfolder.test.foo'); } public function testAppend() @@ -362,12 +284,8 @@ public function testCopy() $this->assertEquals($mail->getMessage($count + 1)->from, $message->from); $this->assertEquals($mail->getMessage($count + 1)->to, $message->to); - try { - $mail->copyMessage(1, 'justARandomFolder'); - } catch (\Exception $e) { - return; // ok - } - $this->fail('no error while copying to wrong folder'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->copyMessage(1, 'justARandomFolder'); } public function testSetFlags() @@ -389,12 +307,8 @@ public function testSetFlags() $this->assertFalse($message->hasFlag(Storage::FLAG_SEEN)); $this->assertTrue($message->hasFlag(Storage::FLAG_FLAGGED)); - try { - $mail->setFlags(1, array(Storage::FLAG_RECENT)); - } catch (\Exception $e) { - return; // ok - } - $this->fail('should not be able to set recent flag'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->setFlags(1, array(Storage::FLAG_RECENT)); } public function testSetFlagsRemovedFile() @@ -402,13 +316,7 @@ public function testSetFlagsRemovedFile() $mail = new Writable\Maildir($this->_params); unlink($this->_params['dirname'] . 'cur/1000000000.P1.example.org:2,S'); - try { - $mail->setFlags(1, array(Storage::FLAG_FLAGGED)); - } catch (\Exception $e) { - return; // ok - } - - $this->fail('should not be able to set flags with removed file'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); } public function testRemove() @@ -428,13 +336,8 @@ public function testRemoveRemovedFile() $mail = new Writable\Maildir($this->_params); unlink($this->_params['dirname'] . 'cur/1000000000.P1.example.org:2,S'); - try { - $mail->removeMessage(1); - } catch (\Exception $e) { - return; // ok - } - - $this->fail('should not be able to remove message which is already removed in fs'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->removeMessage(1); } public function testCheckQuota() @@ -497,13 +400,8 @@ public function testMissingMaildirsize() $this->assertNull($mail->getQuota()); - try { - $mail->getQuota(true); - } catch(MailException\ExceptionInterface $e) { - // ok - return; - } - $this->fail('get quota from file should fail if file is missing'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->getQuota(true); } public function testMissingMaildirsizeWithFixedQuota() @@ -548,21 +446,14 @@ public function testAppendMessage() $mail->setQuota(false); $this->assertTrue($mail->checkQuota()); - try { - $mail->appendMessage("Subject: test\r\n\r\n"); - } catch(MailException\ExceptionInterface $e) { - $this->fail('appending should not fail if quota check is not active'); - } + + $mail->appendMessage("Subject: test\r\n\r\n"); $mail->setQuota(true); $this->assertTrue($mail->checkQuota()); - try { - $mail->appendMessage("Subject: test\r\n\r\n"); - } catch(MailException\ExceptionInterface $e) { - // ok - return; - } - $this->fail('appending after being over quota should fail'); + + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->appendMessage("Subject: test\r\n\r\n"); } public function testRemoveMessage() @@ -641,11 +532,8 @@ public function testInit() $e = null; try { $mail = new Writable\Maildir($this->_params); - } catch (\Exception $e) { - } - - if ($e === null) { $this->fail('empty maildir should not be accepted'); + } catch (\Exception $e) { } Writable\Maildir::initMaildir($this->_params['dirname']); @@ -661,11 +549,8 @@ public function testCreate() $e = null; try { $mail = new Writable\Maildir($this->_params); - } catch (\Exception $e) { - } - - if ($e === null) { $this->fail('empty maildir should not be accepted'); + } catch (\Exception $e) { } $this->_params['create'] = true; diff --git a/test/Storage/MboxFolderTest.php b/test/Storage/MboxFolderTest.php index 08b6be12..7fb035c3 100644 --- a/test/Storage/MboxFolderTest.php +++ b/test/Storage/MboxFolderTest.php @@ -1,22 +1,11 @@ _params); - } catch (\Exception $e) { - $this->fail('exception raised while loading mbox folder'); - } + new Folder\Mbox($this->_params); } public function testLoadConfig() { - try { - $mail = new Folder\Mbox(new Config\Config($this->_params)); - } catch (\Exception $e) { - $this->fail('exception raised while loading mbox folder'); - } + new Folder\Mbox(new Config\Config($this->_params)); } public function testNoParams() { - try { - $mail = new Folder\Mbox(array()); - } catch (\Exception $e) { - return; // test ok - } - - $this->fail('no exception raised with empty params'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + new Folder\Mbox(array()); } public function testFilenameParam() { - try { - // filename is not allowed in this subclass - $mail = new Folder\Mbox(array('filename' => 'foobar')); - } catch (\Exception $e) { - return; // test ok - } - - $this->fail('no exception raised with filename as param'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + // filename is not allowed in this subclass + new Folder\Mbox(array('filename' => 'foobar')); } public function testLoadFailure() { - try { - $mail = new Folder\Mbox(array('dirname' => 'This/Folder/Does/Not/Exist')); - } catch (\Exception $e) { - return; // test ok - } - - $this->fail('no exception raised while loading unknown dirname'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + new Folder\Mbox(array('dirname' => 'This/Folder/Does/Not/Exist')); } public function testLoadUnkownFolder() { $this->_params['folder'] = 'UnknownFolder'; - try { - $mail = new Folder\Mbox($this->_params); - } catch (\Exception $e) { - return; // test ok - } - $this->fail('no exception raised while loading unknown folder'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + new Folder\Mbox($this->_params); } public function testChangeFolder() { $mail = new Folder\Mbox($this->_params); - try { - $mail->selectFolder(DIRECTORY_SEPARATOR . 'subfolder' . DIRECTORY_SEPARATOR . 'test'); - } catch (\Exception $e) { - $this->fail('exception raised while selecting existing folder'); - } + + $mail->selectFolder(DIRECTORY_SEPARATOR . 'subfolder' . DIRECTORY_SEPARATOR . 'test'); $this->assertEquals($mail->getCurrentFolder(), DIRECTORY_SEPARATOR . 'subfolder' . DIRECTORY_SEPARATOR . 'test'); } @@ -182,46 +139,29 @@ public function testChangeFolder() public function testChangeFolderUnselectable() { $mail = new Folder\Mbox($this->_params); - try { - $mail->selectFolder(DIRECTORY_SEPARATOR . 'subfolder'); - } catch (\Exception $e) { - return; // test ok - } - - $this->fail('no exception raised while selecting unselectable folder'); + $this->setExpectedException('Zend\Mail\Storage\Exception\RuntimeException'); + $mail->selectFolder(DIRECTORY_SEPARATOR . 'subfolder'); } public function testUnknownFolder() { $mail = new Folder\Mbox($this->_params); - try { - $mail->selectFolder('/Unknown/Folder/'); - } catch (\Exception $e) { - return; // test ok - } - - $this->fail('no exception raised while selecting unknown folder'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->selectFolder('/Unknown/Folder/'); } public function testGlobalName() { $mail = new Folder\Mbox($this->_params); - try { - // explicit call of __toString() needed for PHP < 5.2 - $this->assertEquals($mail->getFolders()->subfolder->__toString(), DIRECTORY_SEPARATOR . 'subfolder'); - } catch (MailException\ExceptionInterface $e) { - $this->fail('exception raised while selecting existing folder and getting global name'); - } + + $this->assertEquals($mail->getFolders()->subfolder->__toString(), DIRECTORY_SEPARATOR . 'subfolder'); } public function testLocalName() { $mail = new Folder\Mbox($this->_params); - try { - $this->assertEquals($mail->getFolders()->subfolder->key(), 'test'); - } catch (\Exception $e) { - $this->fail('exception raised while selecting existing folder and getting local name'); - } + + $this->assertEquals($mail->getFolders()->subfolder->key(), 'test'); } public function testIterator() @@ -341,13 +281,8 @@ public function testNotMboxFile() touch($this->_params['dirname'] . 'foobar'); $mail = new Folder\Mbox($this->_params); - try { - $mail->getFolders()->foobar; - } catch (\Exception $e) { - return; // ok - } - - $this->fail('file, which is not mbox, got parsed'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->getFolders()->foobar; } public function testNotReadableFolder() @@ -385,13 +320,8 @@ public function testGetInvalidFolder() $mail = new Folder\Mbox($this->_params); $root = $mail->getFolders(); $root->foobar = new Folder('x', 'x'); - try { - $mail->getFolders('foobar'); - } catch (\Exception $e) { - return; // ok - } - - $this->fail('no error while getting invalid folder'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->getFolders('foobar'); } public function testGetVanishedFolder() @@ -400,12 +330,7 @@ public function testGetVanishedFolder() $root = $mail->getFolders(); $root->foobar = new Folder('foobar', DIRECTORY_SEPARATOR . 'foobar'); - try { - $mail->selectFolder('foobar'); - } catch (\Exception $e) { - return; // ok - } - - $this->fail('no error while getting vanished folder'); + $this->setExpectedException('Zend\Mail\Storage\Exception\RuntimeException'); + $mail->selectFolder('foobar'); } } diff --git a/test/Storage/MboxInterfaceTest.php b/test/Storage/MboxInterfaceTest.php index 182ab7f1..cb67b203 100644 --- a/test/Storage/MboxInterfaceTest.php +++ b/test/Storage/MboxInterfaceTest.php @@ -1,22 +1,11 @@ $this->_mboxFile)); - try { - $list[1] = 'test'; - } catch (\Exception $e) { - return; // test ok - } - - $this->fail('no exception thrown while writing to array access'); + $this->setExpectedException('Zend\Mail\Storage\Exception\RuntimeException'); + $list[1] = 'test'; } public function testIterationKey() @@ -145,25 +127,16 @@ public function testFallback() { $list = new Storage\Mbox(array('filename' => $this->_mboxFile)); - try { - $result = $list->noop(); - $this->assertTrue($result); - } catch (\Exception $e) { - $this->fail('exception raised while calling noop thru fallback'); - } + $result = $list->noop(); + $this->assertTrue($result); } public function testWrongVariable() { $list = new Storage\Mbox(array('filename' => $this->_mboxFile)); - try { - $list->thisdoesnotexist; - } catch (\Exception $e) { - return; // test ok - } - - $this->fail('no exception thrown while reading wrong variable (via __get())'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $list->thisdoesnotexist; } public function testGetHeaders() @@ -177,12 +150,7 @@ public function testWrongHeader() { $list = new Storage\Mbox(array('filename' => $this->_mboxFile)); - try { - $list[1]->thisdoesnotexist; - } catch (\Exception $e) { - return; // test ok - } - - $this->fail('no exception thrown while reading wrong header'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $list[1]->thisdoesnotexist; } } diff --git a/test/Storage/MboxMessageOldTest.php b/test/Storage/MboxMessageOldTest.php index df248fe8..84d4e3a3 100644 --- a/test/Storage/MboxMessageOldTest.php +++ b/test/Storage/MboxMessageOldTest.php @@ -1,22 +1,11 @@ $this->_mboxFile)); - } catch (\Exception $e) { - $this->fail('exception raised while loading mbox file'); - } + new Storage\Mbox(array('filename' => $this->_mboxFile)); } public function testLoadConfig() { - try { - $mail = new Storage\Mbox(new Config\Config(array('filename' => $this->_mboxFile))); - } catch (\Exception $e) { - $this->fail('exception raised while loading mbox folder'); - } + new Storage\Mbox(new Config\Config(array('filename' => $this->_mboxFile))); } public function testNoParams() { - try { - $mail = new Storage\Mbox(array()); - } catch (\Exception $e) { - return; // test ok - } - - $this->fail('no exception raised with empty params'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + new Storage\Mbox(array()); } public function testLoadFailure() { - try { - $mail = new Storage\Mbox(array('filename' => 'ThisFileDoesNotExist')); - } catch (\Exception $e) { - return; // test ok - } - - $this->fail('no exception raised while loading unknown file'); + $this->setExpectedException('Zend\Mail\Storage\Exception\RuntimeException'); + new Storage\Mbox(array('filename' => 'ThisFileDoesNotExist')); } public function testLoadInvalid() { - try { - $mail = new Storage\Mbox(array('filename' => __FILE__)); - } catch (\Exception $e) { - return; // test ok - } - - $this->fail('no exception while loading invalid file'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + new Storage\Mbox(array('filename' => __FILE__)); } public function testClose() { $mail = new Storage\Mbox(array('filename' => $this->_mboxFile)); - try { - $mail->close(); - } catch (\Exception $e) { - $this->fail('exception raised while closing mbox file'); - } + $mail->close(); } public function testHasTop() @@ -152,11 +112,7 @@ public function testNoop() { $mail = new Storage\Mbox(array('filename' => $this->_mboxFile)); - try { - $mail->noop(); - } catch (\Exception $e) { - $this->fail('exception raised while doing nothing (noop)'); - } + $mail->noop(); } public function testCount() @@ -224,13 +180,8 @@ public function testFailedRemove() { $mail = new Storage\Mbox(array('filename' => $this->_mboxFile)); - try { - $mail->removeMessage(1); - } catch (\Exception $e) { - return; // test ok - } - - $this->fail('no exception raised while deleting message (mbox is read-only)'); + $this->setExpectedException('Zend\Mail\Storage\Exception\RuntimeException'); + $mail->removeMessage(1); } public function testCapa() @@ -254,13 +205,8 @@ public function testOutOfBounds() { $mail = new Storage\Mbox(array('filename' => $this->_mboxFile)); - try { - $mail->seek(INF); - } catch (\Exception $e) { - return; // test ok - } - - $this->fail('no exception raised while seeking to not invalid id'); + $this->setExpectedException('Zend\Mail\Storage\Exception\OutOfBoundsException'); + $mail->seek(INF); } public function testSleepWake() diff --git a/test/Storage/MessageTest.php b/test/Storage/MessageTest.php index fdd39f85..c0679baf 100644 --- a/test/Storage/MessageTest.php +++ b/test/Storage/MessageTest.php @@ -1,22 +1,11 @@ _params); - } catch (\Exception $e) { - $this->fail('exception raised while loading connection to pop3 server'); - } + new Storage\Pop3($this->_params); } public function testConnectConfig() { - try { - $mail = new Storage\Pop3(new Config\Config($this->_params)); - } catch (\Exception $e) { - $this->fail('exception raised while loading connection to pop3 server'); - } + new Storage\Pop3(new Config\Config($this->_params)); } public function testConnectFailure() { $this->_params['host'] = 'example.example'; - try { - $mail = new Storage\Pop3($this->_params); - } catch (\Exception $e) { - return; // test ok - } - // I can only hope noone installs a POP3 server there - $this->fail('no exception raised while connecting to example.example'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + new Storage\Pop3($this->_params); } public function testNoParams() { - try { - $mail = new Storage\Pop3(array()); - } catch (\Exception $e) { - return; // test ok - } - - $this->fail('no exception raised with empty params'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + new Storage\Pop3(array()); } public function testConnectSSL() @@ -149,11 +118,8 @@ public function testConnectSSL() } $this->_params['ssl'] = 'SSL'; - try { - $mail = new Storage\Pop3($this->_params); - } catch (\Exception $e) { - $this->fail('exception raised while loading connection to pop3 server with SSL'); - } + + new Storage\Pop3($this->_params); } public function testConnectTLS() @@ -163,48 +129,31 @@ public function testConnectTLS() } $this->_params['ssl'] = 'TLS'; - try { - $mail = new Storage\Pop3($this->_params); - } catch (\Exception $e) { - $this->fail('exception raised while loading connection to pop3 server with TLS'); - } + + new Storage\Pop3($this->_params); } public function testInvalidService() { $this->_params['port'] = TESTS_ZEND_MAIL_POP3_INVALID_PORT; - try { - $mail = new Storage\Pop3($this->_params); - } catch (\Exception $e) { - return; // test ok - } - - $this->fail('no exception while connection to invalid port'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + new Storage\Pop3($this->_params); } public function testWrongService() { $this->_params['port'] = TESTS_ZEND_MAIL_POP3_WRONG_PORT; - try { - $mail = new Storage\Pop3($this->_params); - } catch (\Exception $e) { - return; // test ok - } - - $this->fail('no exception while connection to wrong port'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + new Storage\Pop3($this->_params); } public function testClose() { $mail = new Storage\Pop3($this->_params); - try { - $mail->close(); - } catch (\Exception $e) { - $this->fail('exception raised while closing pop3 connection'); - } + $mail->close(); } public function testHasTop() @@ -225,11 +174,7 @@ public function testNoop() { $mail = new Storage\Pop3($this->_params); - try { - $mail->noop(); - } catch (\Exception $e) { - $this->fail('exception raised while doing nothing (noop)'); - } + $mail->noop(); } public function testCount() @@ -312,27 +257,19 @@ public function testWithInstanceConstruction() { $protocol = new Protocol\Pop3($this->_params['host']); $mail = new Storage\Pop3($protocol); - try { - // because we did no login this has to throw an exception - $mail->getMessage(1); - } catch (\Exception $e) { - return; // test ok - } - $this->fail('no exception raised while fetching with wrong transport'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + // because we did no login this has to throw an exception + $mail->getMessage(1); } public function testRequestAfterClose() { $mail = new Storage\Pop3($this->_params); $mail->close(); - try { - $mail->getMessage(1); - } catch (\Exception $e) { - return; // test ok - } - $this->fail('no exception raised while requesting after closing connection'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->getMessage(1); } public function testServerCapa() @@ -386,13 +323,9 @@ public function testUniqueId() public function testWrongUniqueId() { $mail = new Storage\Pop3($this->_params); - try { - $mail->getNumberByUniqueId('this_is_an_invalid_id'); - } catch (\Exception $e) { - return; // test ok - } - $this->fail('no exception while getting number for invalid id'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $mail->getNumberByUniqueId('this_is_an_invalid_id'); } public function testReadAfterClose() @@ -400,13 +333,8 @@ public function testReadAfterClose() $protocol = new Protocol\Pop3($this->_params['host']); $protocol->logout(); - try { - $protocol->readResponse(); - } catch (\Exception $e) { - return; // test ok - } - - $this->fail('no exception while reading from closed socket'); + $this->setExpectedException('Zend\Mail\Storage\Exception\InvalidArgumentException'); + $protocol->readResponse(); } public function testRemove() diff --git a/test/TestAsset/SmtpProtocolSpy.php b/test/TestAsset/SmtpProtocolSpy.php index 6d349675..83c790ed 100644 --- a/test/TestAsset/SmtpProtocolSpy.php +++ b/test/TestAsset/SmtpProtocolSpy.php @@ -1,22 +1,11 @@ rcpt; } -} \ No newline at end of file +} diff --git a/test/TestAsset/StringSerializableObject.php b/test/TestAsset/StringSerializableObject.php index 532d2002..35c9fde9 100644 --- a/test/TestAsset/StringSerializableObject.php +++ b/test/TestAsset/StringSerializableObject.php @@ -1,4 +1,12 @@