Skip to content

Commit afc9dbe

Browse files
author
Conduction Release Bot
committed
fix(softwarecatalog): resolve the config key through one map, not by derivation
CI's PHPUnit matrix went red on all six cells. Three separate causes, and all three are the same shape: something DERIVED the app-config key from the object type, and the slug half of that pair was just translated. - `getRegisterIdForObjectType()` builds `$objectType . '_schema'`. With slugs English and the stored keys still Dutch that lookup misses, and a miss is not an error — it returns null and the caller reads "not configured". Ratings and every catalog type resolved to no register. - `FacetService::fetchBaseObjects()` did the same and returned an empty facet set, which renders as a page with no filters rather than a failure. - `catalog-ratings.json` still declared the schema map key `beoordeeling`. The by-hand fix for map keys covered the main register file only; the register.d fragments were not swept. Found systematically this time. All three now go through `SettingsService::LEGACY_SCHEMA_KEY`, the one place that knows slug and stored key diverge. FacetService reads it as a CONSTANT rather than calling the service: it takes SettingsService as a collaborator and every test mocks it, so a method call there returns the mock default and misses in exactly the tests meant to catch this. Also: one assertion hardcoded the old name inside a REGEX literal (`/module.*dienst|dienst.*module/`) — a position no rename pattern reaches. The control I used before this was WRONG. `git stash` reverts uncommitted work only, and this branch already had three commits, so what I compared against was my own branch. It reported 7 pre-existing failures where a real control from `origin/development` reports none. Rebuilt with `git archive origin/development`. Verified against that real control, full unit suite both sides: 684 tests, 1 error, 25 skipped on BOTH — same count, so nothing silently stopped running, and the one error (Symfony HeaderUtils missing under the unit bootstrap) is identical on development.
1 parent 8067241 commit afc9dbe

4 files changed

Lines changed: 58 additions & 5 deletions

File tree

lib/Service/FacetService.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,17 @@ private function buildCacheKey(string $schema, array $filters, ?string $search,
399399
private function fetchBaseObjects(ObjectService $objectService, string $schema, ?string $search, ?string $organization): array {
400400
$voorzieningenConfig = $this->settingsService->getVoorzieningenConfig();
401401
$registerId = $voorzieningenConfig['register'] ?? null;
402-
$schemaId = $voorzieningenConfig[$schema . '_schema'] ?? null;
402+
// NOT `$schema . '_schema'`: the slugs are English now and the stored
403+
// config keys are still Dutch, so the derived key would miss and this
404+
// method would log "not configured" and return an empty facet set —
405+
// which renders as a page with no filters rather than as an error.
406+
//
407+
// Read as a CONSTANT rather than through SettingsService: this class
408+
// takes that service as a collaborator and every test mocks it, so a
409+
// method call here returns the mock's default and the lookup misses in
410+
// exactly the tests meant to catch that.
411+
$schemaKey = (SettingsService::LEGACY_SCHEMA_KEY[$schema] ?? $schema . '_schema');
412+
$schemaId = ($voorzieningenConfig[$schemaKey] ?? null);
403413

404414
if (empty($registerId) === true || empty($schemaId) === true) {
405415
$this->logger->warning(

lib/Service/SettingsService.php

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,34 @@ class SettingsService {
102102
*/
103103
private const MIN_OPENREGISTER_VERSION = '0.1.7';
104104

105+
/**
106+
* Object type => the app-config key its schema id is actually stored under.
107+
*
108+
* The key was always derived from the schema SLUG. Eight slugs are now
109+
* English while the stored keys are deliberately still Dutch — renaming that
110+
* family is a migration across ~40 sites in three shapes, and doing a SUBSET
111+
* resolves some types while leaving others silently "not configured", which
112+
* is how the ratings feature died once already.
113+
*
114+
* So slug and key diverge, and every place that DERIVES the key from the
115+
* object type (`$objectType . '_schema'`) has to come through here. Missing
116+
* one is not an error: the lookup finds nothing and the caller reads it as
117+
* "not configured". `getRegisterIdForObjectType()` did exactly that.
118+
*
119+
* @var array<string, string>
120+
*/
121+
public const LEGACY_SCHEMA_KEY = [
122+
'assessment' => 'beoordeeling_schema',
123+
'bioMeasure' => 'bioMaatregel_schema',
124+
'connection' => 'koppeling_schema',
125+
'contactPerson' => 'contactpersoon_schema',
126+
'moduleVersion' => 'moduleVersie_schema',
127+
'organization' => 'organisatie_schema',
128+
'service' => 'dienst_schema',
129+
'usage' => 'gebruik_schema',
130+
'vulnerability' => 'kwetsbaarheid_schema',
131+
];
132+
105133
/**
106134
* SettingsService constructor
107135
*
@@ -986,6 +1014,21 @@ public function getSchemaIdForObjectType(string $objectType): ?int {
9861014
return $result;
9871015
}//end getSchemaIdForObjectType()
9881016

1017+
/**
1018+
* The app-config key an object type's schema id is stored under.
1019+
*
1020+
* Slug and stored key diverged when the slugs were translated, so never
1021+
* build the key as `$objectType . '_schema'` directly — see LEGACY_SCHEMA_KEY.
1022+
*
1023+
* @param string $objectType The object type (schema slug).
1024+
*
1025+
* @return string The app-config key.
1026+
* @spec openspec/specs/settings-service/spec.md
1027+
*/
1028+
public function voorzieningenSchemaKey(string $objectType): string {
1029+
return (self::LEGACY_SCHEMA_KEY[$objectType] ?? $objectType . '_schema');
1030+
}//end voorzieningenSchemaKey()
1031+
9891032
/**
9901033
* Gets the configured register ID for a specific object type
9911034
*
@@ -1029,9 +1072,9 @@ public function getRegisterIdForObjectType(string $objectType): ?int {
10291072
// key map: any type with a `<type>_schema` in the voorzieningen config
10301073
// belongs to the voorzieningen register.
10311074
$voorzieningenConfig = $this->getVoorzieningenConfig();
1032-
$isVoorzieningenType = in_array($objectType, ['organization', 'organization', 'contactPerson', 'contact'], true);
1075+
$isVoorzieningenType = in_array($objectType, ['organization', 'contactPerson', 'contact'], true);
10331076
if ($isVoorzieningenType === false) {
1034-
$isVoorzieningenType = isset($voorzieningenConfig[$objectType . '_schema']);
1077+
$isVoorzieningenType = isset($voorzieningenConfig[$this->voorzieningenSchemaKey(objectType: $objectType)]);
10351078
}
10361079

10371080
if ($result === null && $isVoorzieningenType === true) {

lib/Settings/register.d/catalog-ratings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"components": {
33
"schemas": {
4-
"beoordeeling": {
4+
"assessment": {
55
"properties": {
66
"auteur": {
77
"type": "string",

tests/Unit/Service/FacetServiceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public function testGetFacetsThrowsForUnsupportedSchema(): void {
210210
$service = $this->makeService(objectService: $this->createMock(ObjectService::class));
211211

212212
$this->expectException(\InvalidArgumentException::class);
213-
$this->expectExceptionMessageMatches('/module.*dienst|dienst.*module/');
213+
$this->expectExceptionMessageMatches('/module.*service|service.*module/');
214214
$service->getFacets(schema: 'contract');
215215

216216
}//end testGetFacetsThrowsForUnsupportedSchema()

0 commit comments

Comments
 (0)