Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'remove-tests-catch-fail' of https://github.com/Maks3w/zf2
Browse files Browse the repository at this point in the history
… into hotfix/tests-exceptions
  • Loading branch information
Show file tree
Hide file tree
Showing 8 changed files with 222 additions and 752 deletions.
272 changes: 61 additions & 211 deletions test/Storage/ImapTest.php

Large diffs are not rendered by default.

96 changes: 22 additions & 74 deletions test/Storage/MaildirFolderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,102 +121,65 @@ public function tearDown()

public function testLoadOk()
{
try {
$mail = new Folder\Maildir($this->_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');
}

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()
Expand Down Expand Up @@ -398,13 +361,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()
Expand All @@ -413,13 +371,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()
Expand All @@ -428,13 +381,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()
Expand Down
77 changes: 16 additions & 61 deletions test/Storage/MaildirTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,53 +102,31 @@ public function tearDown()

public function testLoadOk()
{
try {
$mail = new Storage\Maildir(array('dirname' => $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()
Expand All @@ -169,11 +147,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()
Expand Down Expand Up @@ -240,39 +214,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()
Expand Down Expand Up @@ -316,13 +275,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)
Expand Down
Loading

0 comments on commit d490dab

Please sign in to comment.