Skip to content
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

Allow multiple exceptions to be thrown in one call with andThrowExceptions (array $exceptions) #312

Closed
wants to merge 1 commit into from

Conversation

Byte-Lab
Copy link

@Byte-Lab Byte-Lab commented Apr 9, 2014

Tests for function have been written in ExpectationTest.php. Let me know if you'd like me to extend the tests before merging.

throw new Exception('You must pass an array of exception objects to andThrowExceptions');
}
}
$this->andReturnValues($exceptions);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just add return here, since andReturnValues also returns current expectation object.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

@Byte-Lab
Copy link
Author

@aik099 Changes made, new commit pushed.

@aik099
Copy link

aik099 commented Apr 10, 2014

Can you please squash commits to make history cleaner?

* Function andThrowExceptions(array $exceptions)
  added to Expectation.php.

* Tests that exceptions are thrown in correct order,
  that the correct number of exceptions are thrown,
  and that an exception is thrown if a non-object
  is passed as an array element to the method.
@Byte-Lab
Copy link
Author

@aik099 Commits squashed

@Byte-Lab
Copy link
Author

Hi @aik099 ,

Just wanted to make sure that this PR is good to go. If you'd like me to fix anything else up please let me know.

@@ -183,6 +183,53 @@ public function testThrowsExceptionSequentially()
$this->mock->foo();
}

public function testAndThrowExceptions()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this test be refactored to contain less duplication code?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly, but it's not immediately apparent to me how that could be done. It seems important to enclose both $this->mock->foo(); statements in full, separate try / catch blocks to ensure that the exceptions are called in the correct order and that the correct number of exceptions are thrown. Separating them into separate try / catch blocks (with catch blocks for both types of exceptions in both try / catch blocks) achieves both of those goals.

Furthermore, if we were to put the try / catch blocks into a separate helper function, wouldn't we have a problem with scope for both thexxxExceptionThrown booleans, as well as the count on the number of exceptions thrown? I suppose we could have the helper method return an array of which exceptions were caught, and the number of exceptions that were thrown in each block, but that doesn't seem like a clean approach.

Not saying I'm correct, but that is my first impression after looking over the code again. Any suggestions are welcome.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Then maybe adding some blank lines to separate logically independent code pieces would increase readability of the method.

@aik099
Copy link

aik099 commented Apr 15, 2014

Just wanted to make sure that this PR is good to go. If you'd like me to fix anything else up please let me know.

It's @davedevelopment who can do the merging. I'm just helping out. Thanks for your contribution.

new OutOfBoundsException,
new InvalidArgumentException,
)
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add ) before this line and remove previous line to create properly formatted multi-line function call.

@davedevelopment
Copy link
Collaborator

See #326

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.

None yet

3 participants