Skip to content

[Tests] Fixed stale @depends targets and outdated assertions in ContentService integration tests - #833

Merged
konradoboza merged 1 commit into
5.0from
fix-stale-depends-5.0
Sep 17, 2026
Merged

konradoboza merged 1 commit into
5.0from
fix-stale-depends-5.0

Conversation

@ViniTou

@ViniTou ViniTou commented Sep 16, 2026

Copy link
Copy Markdown
Contributor
🎫 Issue n/a

Description:

Six @depends annotations in the ContentService integration tests point at methods that no longer exist since the loadContentDrafts()loadContentDraftList() rename (aba61e9098): ContentServiceTest::testLoadContentDrafts (×4, incl. a duplicated line) and a typo loadRelationList (×2, meant testLoadRelationList). PHPUnit 9 silently skips dependents of a missing target, so 7 tests have not executed on 5.0/6.0 since then; PHPUnit 11 turns this into a hard error (surfaced by #831). 4.6 is unaffected (the targets still exist there and the tests pass).

Retargeting the annotations makes those 7 tests run again, and 6 of them failed (the 7th, testDeleteVersionInTransactionWithCommit, passes). Each was a test bug, none a product regression (the tested code is byte-identical between 4.6 and 5.0):

  • ContentServiceTest::testLoadRelationsSkipsArchivedContent — created its draft under location 56 and then trashed location 56; TrashService::trash() purges draft-only content in the subtree, deleting the test's own draft and relations. Draft now created under "Home" (2).
  • ContentServiceTest::testLoadContentWithinGracePeriod set the shared ContentService's grace period to 10 via reflection and never restored it. Resolving the @depends changes PHPUnit's execution order, so this test now runs before ContentServiceAuthorizationTest::testLoadContentThrowsUnauthorizedExceptionsOnArchives, which then read the archived version inside the leaked grace period (passes on unmodified 5.0 only because of the old order). Fixed at the source: original value restored in a finally.
  • testLoadContentDraftsThrowsUnauthorizedException / …WithUser → renamed testLoadContentDraftListReturnsEmptyListForUserWithoutVersionReadAccess / …WithUser: loadContentDraftList() never throws, it returns an empty list without versionread (the throwing loadContentDrafts() was removed on 5.0).
  • testLoadRelationsThrowsUnauthorizedException / testLoadRelationsForDraftVersionThrowsUnauthorizedException → renamed testLoadRelationsReturnsEmptyListForUserWithoutReadAccess / testLoadRelationsForDraftVersionReturnsEmptyListForUserWithoutVersionReadAccess: loadRelationList() returns an empty list for a non-readable source version instead of throwing.
  • testLoadRelationsWithUnauthorizedRelationsloadRelationList() keeps one item per relation and exposes non-readable targets as UnauthorizedRelationListItem (hasRelation() === false) rather than omitting them; assertions now expect 4 items, 2 of them unauthorized.

Reflection sweep of all 1179 @depends annotations under tests/ finds no other stale target. phpstan-baseline.neon: 4 missingType.return entries dropped, the renamed methods now declare : void. No src/ changes.

Legacy integration (ContentServiceTest|ContentServiceAuthorizationTest|ContentTypeServiceTest|UserServiceTest): 557 tests, 0 failures. Unit: 7462 tests, 0 failures. PHPStan and check-cs clean.

Merge-up note: #831 (PHPUnit 11) carries a minimal retarget of the same annotations; after this merges up to 6.0, #831 gets rebased and that part dropped.

For QA:

N/A

Documentation:

N/A

…ntService integration tests

Several @Depends annotations still targeted testLoadContentDrafts and
loadRelationList, method names that no longer exist since the
testLoadContentDrafts -> testLoadContentDraftList rename (aba61e9).
PHPUnit 9 silently skips tests whose @Depends target is unresolvable,
so these dependents had not actually run since that rename.

Retargeted:
- ContentServiceAuthorizationTest::testLoadContentDraftListReturnsEmptyListForUserWithoutVersionReadAccess(WithUser)
  (was testLoadContentDraftsThrowsUnauthorizedException(WithUser)): testLoadContentDrafts -> testLoadContentDraftList
- ContentServiceTest::testLoadRelationsSkipsArchivedContent/SkipsDraftContent: loadRelationList -> testLoadRelationList
- ContentServiceTest::testDeleteVersionInTransactionWithCommit: testLoadContentDrafts -> testLoadContentDraftList

A full reflection-based sweep of tests/ found no other stale @Depends targets.

Running the previously-skipped tests uncovered that several no longer test what
their names claim, because loadRelationList()/loadContentDraftList() were
redesigned (already true on 4.6) to never throw UnauthorizedException -
they return an empty/partial list instead:

- testLoadRelationsThrowsUnauthorizedException,
  testLoadRelationsForDraftVersionThrowsUnauthorizedException,
  testLoadContentDraftsThrowsUnauthorizedException(WithUser): renamed and
  rewritten to assert the actual current behaviour (empty list back).
- testLoadRelationsWithUnauthorizedRelations: loadRelationList() keeps one
  list item per relation, exposing unreadable ones as
  UnauthorizedRelationListItem placeholders rather than omitting them, so
  the test now asserts 4 items (2 authorized + 2 unauthorized) instead of 2.

ContentServiceTest::testLoadRelationsSkipsArchivedContent also had its own
fixture bug: it created its throwaway draft under the very Location it then
trashed, so trashing purged the draft (and its relations) itself, instead of
just archiving the "Demo Design" relation target. Moved the draft under the
unrelated Home location instead.

No src/ changes.

- testLoadContentWithinGracePeriod overrode the shared ContentService's
  grace period via reflection and never restored it. With the @Depends
  above resolvable again PHPUnit reorders execution so this test now runs
  before ContentServiceAuthorizationTest::testLoadContentThrowsUnauthorizedExceptionsOnArchives,
  which then read the archived version inside the leaked grace period.
  The original value is now restored in a finally block.
- The four renamed authorization tests declare `: void` instead of
  keeping their phpstan-baseline "no return type" entries.
@ViniTou
ViniTou force-pushed the fix-stale-depends-5.0 branch from 26a7363 to 3e3e238 Compare September 16, 2026 12:47
@sonarqubecloud

Copy link
Copy Markdown

@alongosz alongosz changed the title [Tests] Fixed stale @depends targets and outdated assertions in ContentService integration tests [Tests] Fixed stale @depends targets and outdated assertions in ContentService integration tests Sep 17, 2026
@konradoboza
konradoboza merged commit 22d4f0b into 5.0 Sep 17, 2026
39 of 40 checks passed
@konradoboza
konradoboza deleted the fix-stale-depends-5.0 branch September 17, 2026 06:43
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.

3 participants