Wunderbyte-GmbH / moodle-mod_booking

Moodle Booking Module
https://www.wunderbyte.at
21 stars 38 forks source link

Testing advanced rules #592

Open eynimeni opened 1 month ago

eynimeni commented 1 month ago

We added a new feature to the rules:

Screenshot 2024-07-30 at 10 51 15

In the example when the rule "Overrule rule" applies, the two other rules "Änderungen in Buchungsoption" & "Bookinganswer cancelled" will not be executed. If an event only causes "Bookinganswer cancelled" and not "Overrule rule", actions from "Bookinganswer cancelled" should of course still be executed. The (1) after the name of the rule is the id of the instance, these are all global rules, but since there can also be specific rules for bookinginstances we added this integer.

Could you please extend the rules tests to see if this works as expected?

semteacher commented 1 month ago

Have created a Behat test which is working OK. Tried to create phpunit but faced issue when each next test on booking _rules preserve rule form at least 1st test. See https://github.com/Wunderbyte-GmbH/moodle-mod_booking/commit/b84c7b185313abdbe4b6aea934fc13a453d4e838 for code details. Debugging:

I faced same behavior few times already and still not fully resolve it. It might be caused by wrong approach I crated phpunit tests at all - because I am strugling of following recommendation image However, enforcing object's mock with combination of onlyMethods / willReturn does not have a lot of sense to me in current circumstances. So I need an assistance / adwise on this

semteacher commented 1 month ago

Have to express an issue which could indicate a ptoential problems with rules. Faced it specifically under phpunit tests there https://github.com/Wunderbyte-GmbH/moodle-mod_booking/commit/b84c7b185313abdbe4b6aea934fc13a453d4e838#diff-f44f9514b3b71a68fa866cb953211675c982946b3f7837dc2d2dd1c4ee995aa2 The rule had created in the 1st test in file - persists through all tests in the same file... And It cannot be deleted $this->resetAfterTest(); does not destroy that rule(s). even explicit calling of rules_info::delete_rule($rule1->id);also do not destroy it What I found is the static variable under booking_rules class public static $rules = []; which persist during execution time. Does it had been used for caching purpose? But even forcing it to the empty array in test does not resolve the above issue. I am wonder if it could affect normal workflow.

semteacher commented 1 month ago

Finally I found one more class-level static variable. Reseting both after each test seems solved an issue (https://github.com/Wunderbyte-GmbH/moodle-mod_booking/commit/295725dc5d0d7ba182af6d4428a89bc80027605e):

rules_info::$rulestoexecute = [];
booking_rules::$rules = [];