I am completely new to PHP unit testing, but I decided it was time to learn after discovering a critical bug in a small WooCommerce extension I had built for a client.
The extension I built added a feature that allowed administrators to limit specific coupons to new customers only. I had done some manual testing and made sure that new customers could use the coupon and existing customers could not. But there was a logic bug I missed that prevented existing customers from using any coupons, even ones that did not have the “new customer” restriction.
After finding the bug, I knew there were several use cases I would need to check every time an update was made to the plugin:
- New customer should be able to apply a coupon
- New customer should be able to apply a coupon with a “new customer” restriction
- Existing customer should be able to apply a coupon without a “new customer” restriction
- Existing customer should *not* be able to apply a coupon with the “new customer” restriction
Obviously, checking this manually each time would be rather tedious- which is why I turned to unit tests.Continue reading