-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
withContext(...) feature reuqest #4960
Comments
From the example code you shared, I get the impression that you are coupling your test code too tightly to your production code. For instance, you're testing private implementation details. I get the feeling that you are investing a lot of time and effort into testing infrastructure that would be far better invested into refactoring your production code to be easier to test. Please understand that this topic is outside the scope of an issue tracker. |
First of all, thanks for soon-removing Secondly, let's ignore the well explained "situation and background", as you misunderstand ;-)
Last but not least, please add some-way (feature) to log a custom-message, and that right at top of the next failure's log:
|
Note that someone already suggested data-provider, and here is my answer: First of all, that would make the message look something like:
Instead of:
And someone later running the tests would get confused (as we don't write tests for ourselves). Secondly, storing each and every route in
Last and least, rewritting logic to create |
You can use string keys in data providers, so you can receive any text you wish instead of
You don't need to create an array: data provider can be a generator, so you can just |
I already found a solution, which is far more human-readable as well:#4961 (comment)No need to hack Data-provider to log pretty messages. However, Data-provider is enabled through doc-comment, which I never did like, |
In our project's
testRoutes_shouldDenyCustomersAccessToAdminPages()
test, we have a for-loop that iterates each and every "admin" prefixed route of ourPHP
App.Now sometimes an error is thrown, or the assertion fails, and we would like to know for which route exactly, for that, said for-loop stores the context in
lastRoute
instance-variable of test-case, andTestListener
prefixes the loggedmessage
with said context, like:@sebastianbergmann How can we achive above with the new
TestHook
API?Which looks like:
Solutions
As you deprecated our side of handling this,
please consider implementing one of below solutions into
PHPUnit
API.# 1 You could change your existing API's
$message
to&$message
, I mean, to a reference, then use reflection like above (to update message).# 2 Or, like some other frameworks, provide
withContext(...)
method, and the next failure (no matter if error or assert) should log thecontext
before actualmessage
, then clear context.The text was updated successfully, but these errors were encountered: