Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+4 votes
780 views
in Plugins by
is there any way to write test cases (PHPUnit) for one of my plugin which depends on the events are fired .

Please help me out by giving your valuable tip .
Q2A version: 1.6.3

1 Answer

+2 votes
by

If you split the application logic an put it apart from the event handler so that the latter calls your application logic then you can test your application logic just by calling it directly from the test.

If you also want to test how your plugin handles the event then you have 2 options. On one hand you can simulate a situation in which the event gets actually fired. For example, if you want to catch an upvote then create 2 users, then one could create a post and then the other one would upvote it (you can do all of this programatically). This would be the most realistic situation.

On the other hand, you could directly generate the event yourself by calling the qa_report_event function manually. This one is self explanatory.

by
ok . thanks @pupi . i will try this approach
...