Testing: assertDispatched does not work #230
Replies: 1 comment
-
The It doesn't test that top-level calls like Instead, you should focus on testing that your observer method was triggered. For example:
Or, if you want to go a bit further and make the WorkflowStub call testable, you can wrap it like this:
Then update your observer to use the dispatcher:
And now you can mock it in your test:
This gives you clean separation, keeps your tests focused on your own logic, and avoids trying to mock or assert framework internals. Of course, if you actually want to test things end-to-end, then you shouldn't call |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I'm going on with your great package. Nice work by the way !
I start a workflow on model creation within an observer:
It works as expected. My worker runs the workflow and its activities.
Now, I would like to unit test this behaviour by simply asserting the
ArticleProcessWorkflow
is dispatched uponArticle
creation:That does not work.
I get the error
The expected [App\Workflows\ArticleProcessWorkflow] workflow/activity was not dispatched.
. And, after debugging, I can see thatApp::make(self::$DISPATCHED_LIST)
is an empty array.What did I miss ?
Beta Was this translation helpful? Give feedback.
All reactions