Skip to content

Improved exceptions #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 1, 2012
Merged

Improved exceptions #7

merged 4 commits into from
Dec 1, 2012

Conversation

mauris
Copy link
Contributor

@mauris mauris commented Dec 1, 2012

Exceptions now have better description than before.
use of \InvalidArgumentException and more categorisation of exceptions

@ghost
Copy link

ghost commented Dec 1, 2012

Test cases evolving with improved exceptions

https://github.com/thephpdeveloper/php-queue/blob/master/test/PHPQueue/BaseTest.php#L30
https://github.com/thephpdeveloper/php-queue/blob/master/test/PHPQueue/BaseTest.php#L39
https://github.com/thephpdeveloper/php-queue/blob/master/test/PHPQueue/BaseTest.php#L118
https://github.com/thephpdeveloper/php-queue/blob/master/test/PHPQueue/BaseTest.php#L127

Can now catch the more generic [Queue|Worker]NotFoundException and no longer need to assertTest the error message.

try {
    Base::getQueue('NonExistent');
    $this->fail("Should not be able to get the Queue");  //IS SUFFICE
} catch (QueueNotFoundException $ex) {
}

Or the more pragmatic way:

/**
 * @expectedException QueueNotFoundException
 */
public function testCanFailWhenInvalidQueueNameAreGiven()
{
    //...
}

@miccheng
Copy link
Member

miccheng commented Dec 1, 2012

Agree on using the separate test function for testing exception.

@ghost
Copy link

ghost commented Dec 1, 2012

Maybe conclude this PR first as Sam may be busy for that.

miccheng added a commit that referenced this pull request Dec 1, 2012
@miccheng miccheng merged commit d4e5da1 into CoderKungfu:master Dec 1, 2012
@mauris
Copy link
Contributor Author

mauris commented Dec 1, 2012

Actually for PHPUnit, it is recommended we write a failing test, then write the @expectedException tags to help us test exceptions proper.

Read: http://www.phpunit.de/manual/3.2/en/writing-tests-for-phpunit.html

@miccheng
Copy link
Member

miccheng commented Dec 1, 2012

Yeah, i was trying to keep things in the same assert block. But yes, let's do it as a separate @expectException function.

@ghost ghost mentioned this pull request Dec 1, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants