Skip to content

Snapshots: collision-free file names with a rename-only migration mode #115

Open

Description

@temp

Part of #101. Line numbers refer to branch chore/php-8.4-dependabot (#98). Verified = reproduced, suspected = from reading the code.

The current naming produces collisions and odd names. A new scheme changes every snapshot file name, so it comes with a migration mode.

Bugs fixed by the new scheme:

  • The second snapshot in a test always gets the .json extension: snapshotFilename() (SnapshotTrait.php:186) hardcodes it for the _2, _3, … suffix. Two text snapshots write …_2.json, and two XML snapshots crash with Start tag expected. Verified.
  • A counter suffix collides with a named snapshot: the second unnamed JSON snapshot and assertMatchesNamedJsonSnapshot($x, '2') both resolve to method_2.json. Verified.
  • Different tests map to the same file: FooBarTest::testBaz and FooTest::testBarBaz both become foo_bar_baz, and testQuxX / testQux_x collide too (snapshotName(), :220). Verified.
  • Data set names are normalized lossily: say "hi" / say "bye", 'Foo Bar' / 'foo-bar' and '+' / '-' each share one file. Verified.
  • The default snapshotPath() (:212) depends on the namespace and the current working directory instead of the test file's location. Verified.
  • Mangled names: HTMLParserTest becomes h_t_m_l_parser, testimonialRenders becomes imonial_renders, and non-ASCII data set names become non-ASCII file names. Suspected.

Plan:

  • New scheme, e.g. __snapshots__/<Class>/<method>__<dataset>.<ext> or a reversible encoding, plus an error when two tests resolve to the same file.
  • Default path from dirname((new ReflectionClass(static::class))->getFileName()).
  • MIGRATE_SNAPSHOT_NAMES=1: on each assertion, move the old file to its new name without touching the content, so git shows pure renames. Files that two tests used to share are listed at the end, because those tests were wrong before.
  • UPGRADE-8.0.md: run the name migration and commit first, then update the contents and commit.

Breaking: all snapshot file names change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions