Menu

How Architecture Tests Caught a Data Isolation Bug Before It Reached Production
📰
0

How Architecture Tests Caught a Data Isolation Bug Before It Reached Production

DEV Community·Sheikh Shahzaman·about 1 month ago
#boB0mwTN
Reading 0:00
15s threshold

TL;DR: Pest PHP architecture tests let you write your team coding rules as automated tests. Controllers using the DB facade directly? Build fails. Model missing the tenant isolation trait? Build fails. These tests caught a critical data isolation bug three weeks after we added them. We had a rule in our team wiki. Every model that stores tenant-specific data must use the BelongsToTenant trait. This trait adds a global scope that automatically filters all queries by the current tenant. Without it a query could accidentally return data from other tenants. The rule was clear. Everyone knew about it. It was mentioned in onboarding. It was in our code review checklist. A new developer joined the team. Three weeks later they added a new model without the trait. The code review missed it because the reviewer was focused on the business logic which was actually well written. The model went to production. For two days one tenant could see fragments of another tenant data in a specific report.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More