Feature Implementation Plan: Fix Failing Coffee Bean Filter Tests¶
📋 Todo Checklist¶
- [ ] Analyze the root cause of the test failures in
CoffeeBeanSpeciesFilterTest. - [ ] Correct the
api_filters.phpconfiguration to re-introduce the missing filters. - [ ] Verify the fix by running the specific failing tests.
- [ ] Run the full test suite to ensure no regressions were introduced.
- [ ] Final Review and Testing
🔍 Analysis & Investigation¶
Codebase Structure¶
- Failing Tests: The issue is reported in
tests/Controller/Api/CoffeeBeanSpeciesFilterTest.php. - Root Cause Location: The bug is not in the test file itself, but in the filter configuration file it depends on:
config/packages/api_filters.php. - Affected Service: The
src/Service/Api/FilterService.phpconsumes this configuration. When the configuration is missing, the service fails to apply the correct filtering and validation, causing the tests to fail.
Root Cause Analysis¶
A git bisect analysis has identified commit 2ca0a7274a967e238b139c7a1008e1d12d577f5a as the source of the regression.
This commit's purpose was to standardize the roasterId and countryId filters to be array-based (roasterIds[], countryIds[]). However, during this refactoring, the previously implemented configurations for speciesIds and varietyIds were accidentally omitted from the api_filters.php file.
This omission is the direct cause of the two test failures:
1. testFilterByInvalidSpeciesId Fails: The FilterService no longer has a configuration for speciesIds. Therefore, it doesn't know it needs to validate the input as a UUID array. It silently ignores the invalid parameter, the controller proceeds, and the API returns a 200 OK instead of the expected 400 Bad Request.
2. testFilterByNonExistentSpeciesId Fails: Similarly, the FilterService ignores the speciesIds parameter because it's not in the configuration. The query is executed without the species filter, returning all 20 coffee beans instead of the expected 0.
Dependencies & Integration Points¶
- The entire Unified Filtering System is dependent on the
api_filters.phpconfiguration being complete and correct. This small omission has a significant impact on the API's behavior.
Considerations & Challenges¶
- The fix itself is very low-risk and involves restoring missing configuration.
- The primary challenge is ensuring that the restored configuration is correct and that no other filters were accidentally removed. A careful review of the file is necessary.
📝 Implementation Plan¶
Prerequisites¶
- No new external dependencies are required.
Step-by-Step Implementation¶
-
Restore Missing Filter Configurations
- Files to modify:
config/packages/api_filters.php - Changes needed: Add the configurations for
varietyIdsandspeciesIdsback into theApp\Entity\CoffeeBeanfilter set. The file should be corrected to include all necessary array-based UUID filters. - Action: Locate the
roasterIdsandcountryIdsfilter blocks and ensure thevarietyIdsandspeciesIdsblocks are also present. - Correct Configuration Snippet:
// ... inside the 'App\Entity\CoffeeBean' array ... 'roasterIds' => [ 'type' => 'uuid_array', 'field' => 'id', 'alias' => 'ro', ], 'varietyIds' => [ // This block is likely missing or incorrect 'type' => 'uuid_array', 'field' => 'id', 'alias' => 'v', ], 'speciesIds' => [ // This block is likely missing or incorrect 'type' => 'uuid_array', 'field' => 'id', 'alias' => 's', ], 'countryIds' => [ 'type' => 'uuid_array', 'field' => 'id', 'alias' => 'country', ], // ... other filters ...
- Files to modify:
-
Verify the Fix
- Action: After modifying the configuration file, run the tests to confirm the fix.
- Command 1 (Specific Test): First, run the test file that was failing to get a quick confirmation.
- Command 2 (Full Suite): Once the specific test passes, run the entire test suite to ensure the change did not introduce any regressions elsewhere.
🎯 Success Criteria¶
- The two failing tests in
App\Tests\Controller\Api\CoffeeBeanSpeciesFilterTestnow pass. - The full project test suite (
make test) completes successfully with no new errors or failures. - The API endpoints for filtering coffee beans by
speciesIds[]andvarietyIds[]are fully functional, including input validation and correct filtering logic.