test: add suite for sweeper tasks (+ fix flushSnapshots static-call crash) - #4
Open
erikfrerejean wants to merge 9 commits into
Open
test: add suite for sweeper tasks (+ fix flushSnapshots static-call crash)#4erikfrerejean wants to merge 9 commits into
erikfrerejean wants to merge 9 commits into
Conversation
- Capture and assert output in testDeleteOrphanedVersionsDryReportsCountAndKeepsRows - Add assertGreaterThanOrEqual(3) guard in testDeleteArchivedVersionsDryReportsCountAndKeepsRows - Add clarifying comment in testFlushClassFastSkipsDeleteOldVersions about retention pass iterating all RecordIDs
The container entrypoint runs sake dev/build without test classes, caching a manifest that excludes test-only class config (e.g. ReportPopulatedObject::$extensions, VersionedRecord::$extensions). PHPUnit reused that stale cache, causing testExcludesAppliedDataExtension to fail and ~10 missing _Versions table errors. Fix: rm -rf /tmp/silverstripe-cache-* before every phpunit invocation (test-unit, test-integration, test-snapshots, coverage) so the test kernel rebuilds the manifest with test classes included.
…uisite assertions Add `assertSame(DataObject::class, get_parent_class(SnapshotEvent::class))` and `assertTrue(DataObject::has_extension(SnapshotEvent::class, Versioned::class))` before the `assertNotContains`, so the test proves the exclusion guard actually fired rather than passing vacuously if SnapshotEvent were never a candidate. Also add `deps: [docker-env]` to `ensure-up-snapshots` task in Taskfile.yml, matching the pattern already used by `ensure-up`.
…or handling fix: use Snapshot::singleton() for hashObjectForSnapshot() — the trait method is non-static and calling it statically throws in PHP 8.3.
Add assertStringContainsString('Cleared', \$output) to
testFlushSnapshotsDryReportsCountsAndDeletesNothing so the test
proves the per-object retention loop executed — not just that the
opening (dry-run) prefix line was printed.
Add 'namespace excludes all' data-provider case to testExtensionFilterMatrix so the str_contains exclusion arm is exercised (namespace-filter matching nothing, excluding NeverAppliedExtension and all SilverStripe\ classes).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
First test suite for the sweeper module's two loadable
BuildTasks, plus aversioned-snapshotstestbed profile so the optional snapshot path is covered. The module previously had zero tests — a real risk given its production use against live databases and_Versionshistory.Coverage
SweeperReportTask— no-instance DataObject detection, the SilverStripe / namespace filters, and never-appliedDataExtensiondetection (incl. a 5-case filter matrix).SweeperClearArchiveTask— version-retention math across the draft / archived / orphaned / subclass-orphaned paths, dry-run-vs-real for every mutating method,getKeepVersions()config precedence,flushClassfast/non-fast, andgetBaseVersionedClasses()filtering.flushSnapshots()(snapshots profile) — dry/real retention and the per-object exception-swallowing path.All integration tests (
SapphireTest) with programmatic test-only DataObjects — no YAML fixtures, since the versioned/deleted/orphaned states aren't expressible statically. PHPUnit 9.6 (annotations, not attributes), matching the testbed.Results: default suite 30 tests / 49 assertions; snapshots profile 4 tests / 10 assertions.
src/)The new tests surfaced that
SweeperClearArchiveTask::flushSnapshots()never worked on SS5 / PHP 8: line 141 called the instance methodSnapshot::hashObjectForSnapshot()statically, a fatalErroron the first object processed. Fixed minimally:This is the only
src/change. The separateSweeperArtefactsnamespace bug is deliberately left for a follow-up.Testbed
snapshotsDocker compose profile (mirrors the grid module's Fluent profile):composer.snapshots.json,app-snapshotsservice with its ownvendor-snapshotsvolume +silverstripe_snapshotsDB, asnapshotsPHPUnit suite, andtask test-snapshots. The defaultintegrationsuite excludes the snapshot-only tests so they never loadSnapshotEventwhere the module isn't installed.dev/buildcaches a test-excluding manifest, so without this the first run on a fresh container fails to apply test-only classes' config (missing_Versionstables, unapplied extensions).Notes
getDraftObjects()'s >100-record batching boundary is exercised single-batch only (provoking it needs 100+ records × multiple versions — a deliberate cost trade-off).