Skip to content

test(jsonld,hydra,hal): migrate behat features to ApiTestCase#7957

Merged
soyuka merged 21 commits into
api-platform:mainfrom
soyuka:test/jsonld-behat-migration
May 11, 2026
Merged

test(jsonld,hydra,hal): migrate behat features to ApiTestCase#7957
soyuka merged 21 commits into
api-platform:mainfrom
soyuka:test/jsonld-behat-migration

Conversation

@soyuka
Copy link
Copy Markdown
Member

@soyuka soyuka commented May 7, 2026

Summary

Migrates the JSON-LD, Hydra and HAL Behat feature suites to PHPUnit ApiTestCase. Stacked on top of #7952 (refactor(jsonld): simplify @context building) — until #7952 merges, this PR's diff also contains that refactor commit.

Commits (0da37943b6a057352d):

  • test(jsonld): migrate trivial behat features to ApiTestCase
  • test(jsonld): migrate context/non-resource and abs/net URL features
  • test(hydra): migrate entrypoint, error and item_uri_template features
  • test(hydra): migrate collection, docs and input_output features
  • test(jsonld): close coverage gaps left by behat migration
  • chore(tests): remove fixtures orphaned by jsonld behat migration
  • chore(tests): fix references orphaned by jsonld behat migration
  • test(jsonld): fix CI failures from behat migration
  • test(hal): migrate behat features to ApiTestCase
  • cs: enforce yoda style in JsonLd CollectionPagedResource

Test plan

🤖 Generated with Claude Code

@soyuka soyuka force-pushed the test/jsonld-behat-migration branch from 6a05735 to 75701fc Compare May 7, 2026 11:51
soyuka added 20 commits May 11, 2026 14:47
Replaces 9 jsonld behat features with ApiTestCase functional tests
backed by isolated static-provider fixtures (no Doctrine entities,
except PropertyCollectionIriOnlyTest which keeps the existing entities
to preserve Link/uriVariables semantics). Covers disable_id_generation,
no_output, getter_setter_renaming, interface_as_resource,
interface_dto_output, max_depth, json_serializable, iri_only and drops
the debug-only inheritance scenarios.
Replaces context.feature (entrypoint, resource, embed-relation,
extended jsonldContext), non_resource.feature (genid, sparse fieldsets,
DateTime, plain object, non-resource relation), absolute_url.feature,
network_path.feature and hydra/absolute.feature (paged hydra:view).
Per-operation urlGenerationStrategy replaces the legacy app-level
configuration; new fixtures use static providers and ArrayPaginator.
Replaces the entrypoint, error and item_uri_template hydra behat
features with ApiTestCase functional tests. Error scenarios use
ValidationException + BadRequestHttpException via dedicated processors;
item_uri_template covers cars/brands plus the existing issue5662 and
CollectionReferencingItem fixtures registered through SetupClassResources.
Replaces the remaining hydra/jsonld behat features:
* hydra/collection.feature: pagination, filters, partial pagination,
  no-prefix mode and cursor pagination (cursor variant uses SoMany).
* hydra/docs.feature: simplified to assert vocabulary, supportedClass,
  property/operation surface and deprecations on a dedicated fixture.
* jsonld/input_output.feature: custom input/output DTO, output: false,
  input: false, full input/output cycle.

Drops legacy @V3 / messenger / DataTransformer scenarios that no
longer reflect 4.x semantics.
* abs/network URL tests now run against http://example.com via base_uri
  override, matching the original behat host.
* HydraDocsTest exercises the original assertions on a richer fixture:
  subClassOf via types, range/maxCardinality on relations, schema:FindAction
  type on GET, per-method hydra:title and description, deprecation
  propagating from a deprecated resource into the entrypoint.
* InputOutputDtoTest restores the three legacy @V3 collection-DTO scenarios
  (genid for resource without id, custom itemUriTemplate, identifier-bearing
  resource still falling back to genid when no item operation exists).
* New EntityClassWithDateTimeTest covers JSON-LD on a resource backed by
  a Doctrine entity through stateOptions.
* HydraCollectionTest now uses a partial-only paginator implementation,
  asserting that hydra:view drops first/last and keeps next/previous.
* RenamedGetterSetterTest restores the exact @id assertion (collection URI
  fallback when the resource has no identifier).
EntityWithRenamedGetterAndSetter, EntityWithDtoOutput,
JsonldContextDummy and MaxDepthEagerDummy (entity + document)
were only referenced by the deleted behat features. Other
fixtures touched by the migration (IriOnlyDummy, AbsoluteUrlDummy,
NetworkPathDummy, MaxDepthDummy, ContainNonResource, PlainObjectDummy,
NonRelationResource, DisableIdGeneration) are still referenced from
DoctrineContext, the JSON Schema command test, the jsonapi feature
suite or HAL tests, so they stay.
DtoOutput was defined inside EntityWithDtoOutput.php (deleted in
fbfe043); src/JsonSchema/Tests/DefinitionNameFactoryTest.php still
imports it as a class-string for definition-name generation. Re-adds a
minimal class. Also narrows InterfaceTaxonImpl::getCode() to non-nullable
string (covariant) which phpstan now catches.
Two fixes for the JsonLd functional tests added yesterday:

* Consolidate dual #[ApiResource] declarations sharing the same
  shortName on AbsoluteUrlChild, NetworkPathResource and UriTemplateCar
  into a single attribute with all operations. Avoids the 4.2-deprecated
  duplicate-shortName path that was failing the no-deprecation and
  Symfony-dev PHPUnit jobs.
* Skip MongoDB-only paths in ItemUriTemplateHydraTest and the
  UserResource branch of InputOutputDtoTest where the underlying
  fixtures live in the Entity namespace and aren't loaded under the
  Document kernel; skip InputOutputDtoTest::testCreateNoInputResource
  in event-listener mode where PlaceholderAction cannot resolve $data
  for input:false POST.
Replaces the eleven hal behat features with ApiTestCase functional tests
under tests/Functional/Hal, mirroring the jsonld/hydra migration done
yesterday. Most use static-provider fixtures; PropertyCollectionIriOnly
and TableInheritance keep the existing entity fixtures (still referenced
by features/main/table_inheritance.feature). MaxDepthEagerDummy was
already deleted in fbfe043 — this restores coverage for that scenario
under HalMaxDepth.

With features/hal, features/jsonld and features/hydra all gone, the
ld-api-hal-hydra shard reduced to features/jsonapi alone; renames the
shard accordingly.
* HydraTest -> JsonLd/HydraHideFromDocsTest (descriptive name reflects what
  the single test asserts: hiding hydra:supportedClass and operations)
* LinkedDataPlatformTest -> JsonLd/LinkedDataPlatformTest (LDP is JSON-LD)
* ItemUriTemplateTest -> JsonLd/ItemUriTemplateNotFoundTest (rename
  testIssue6718 to testNotFoundOnInvalidItemUriTemplateRelation)
Replace the 9-method root JsonLdTest.php with 6 focused JsonLd/* test
files, one per feature:

* InputDtoIriDenormalizationTest (input DTO with IRI relation)
* ContextOutputTest (output DTO @context shape, ignored properties)
* GenIdFalseTest (genId:false at resource and nested levels)
* PolymorphicResourceCollectionTest (per-item @type in collections)
* ItemUriTemplateCollectionTest (itemUriTemplate as @id, with stateOptions)
* MultiResourceContextTest (correct shortName per ApiResource variant)

Each file scopes its setUp/recreateSchema to only the entities it uses,
and replaces issue-numbered method names with descriptive ones.
Replace the 8-method root JsonApiTest.php with 4 focused JsonApi/* test
files, mirroring the JsonLd/ and Hal/ subdir layout:

* JsonApi/ErrorTest (ErrorResource rendered in vnd.api+json)
* JsonApi/IdentifierModeTest (4 use_iri_as_id:false tests sharing the
  bootJsonApiKernel helper)
* JsonApi/IriModeTest (default use_iri_as_id:true mode)
* JsonApi/InputDtoTest (POST with input DTOs, preserved attributes and
  required constructor args)

Each file scopes its fixtures to only what its tests use.
Replaces features/authorization/{deny,legacy_deny}.feature with functional
tests under tests/Functional/Authorization, preserving full scenario
coverage. Each @link_security scenario lives in its own test so the
positive and negative paths are asserted independently.

Drops features/authorization from the misc behat shard; the
SecuredDummy-with-related-dummies fixture step stays since
features/graphql/authorization.feature still uses it.
Replaces 13 jsonapi behat features with ApiTestCase functional tests
backed by static-provider fixtures (CollectionUriTemplateTest reuses
the existing PropertyCollectionIriOnly entities to preserve Link
semantics). Covers errors, absolute/network URLs, item/collection
URI templates, circular refs, non-resource handling, DTO output,
ordering, filtering with sparse fieldsets, pagination, entrypoint,
CRUD with relationships, and include= related-resources resolution.
CrudTest now uses Dummy/RelatedDummy/ThirdLevel/RelationEmbedder
entities through recreateSchema/persist/flush instead of static
processors that fabricated ids, matching the authorization migration
pattern. RelatedResourcesInclusionTest grows from 5 partial scenarios
to all 15 original behat scenarios (many-to-one, many-to-many, dedup,
path-based, collection variants) backed by DummyProperty/DummyGroup/
FourthLevel/RelatedOwningDummy. The 6 now-unused static JsonApi
fixtures are dropped.
* Drop empty `jsonapi` behat shard from CI matrix (features/jsonapi
  was deleted in 0bf7af5).
* PHPStan: replace `is_int($offset)` always-true narrowing with an
  upfront page-range guard in PaginationDummy.
* CS: prefix `array_slice` with `\` in OrderingTest per project style.
Seven DenyTest cases assume the freshly-seeded SecuredDummy gets id=1
on every run. The MongoDB ODM INCREMENT strategy keeps its counter
outside the dropped document collection, so subsequent test runs
re-target a non-existent id and the API returns 404 instead of the
expected 403 / 200. Skip them on MongoDB to match the existing
isMongoDB() pattern used by the link-security tests in this file.

Also baseline the multi-shortName deprecation triggered by
RelatedLinkedDummy (used only by DenyTest now) so the
phpunit-no-deprecations CI job stays green.
…tions

* RelatedLinkedDummy (Entity + Document) gives each #[ApiResource] a
  distinct shortName so the multi-shortName 4.2 deprecation no longer
  fires. The baseline entry added in 8f0cb09 is reverted.
* DenyTest / LegacyDenyTest no longer hard-code /secured_dummies/1:
  POSTs now return the IRI which subsequent GET/PUT calls consume.
  seedLinkedDummy switches to API POST and returns the created ids,
  so the helper works on both ORM and ODM. This removes seven
  isMongoDB() skips and the failures from the MongoDB CI job (the
  ODM INCREMENT counter survives collection drops and never gives id=1
  twice in a row).

Verified locally against both APP_ENV=test and APP_ENV=mongodb.
Add PUT/PATCH on HAL relation embedder, PUT on HAL max-depth resource,
JSON-LD messenger and DataTransformerInitializer scenarios. Restore the
PropertyFilter on JsonLdNonResourceContainer (lost during migration) and
tighten the sparse-fieldset assertion so excluded keys are checked.
@soyuka soyuka force-pushed the test/jsonld-behat-migration branch from 2ed7dc0 to 5f9f5f7 Compare May 11, 2026 12:47
The deleted features/jsonld/inheritance.feature only had
"print last JSON response" steps. Replace with a real assertion
that confirms each collection member uses its concrete subtype's
URI template (Contractor5438 → /contractor_5438/{id}, Employee5438
→ /employee_5438/{id}) — the original behavior fixed in api-platform#5449.
@soyuka soyuka merged commit 1d7695d into api-platform:main May 11, 2026
115 of 118 checks passed
@soyuka soyuka deleted the test/jsonld-behat-migration branch May 11, 2026 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant