spatie/phpunit-snapshot-assertions

Reconsider default driver for associative arrays

Closed this issue · 0 comments

I'm mostly using this package to snapshot associative arrays, or something that can be easily converted to an associative array. So I'm looking to optimize this package for that use case.

When no driver is specified, we currently fall back to VarDriver. This is the easy way out, as it works for all datatypes, but the output is noisy.

<?php return array (
  0 => 
  array (
    'id' => 2405,
    'artist_id' => 3374,
  ),
  1 => 
  array (
    'id' => 2425,
    'artist_id' => 3395,
  ),
);

I think we should use the JsonDriver when dealing with associative arrays, which would give a nicer output.

[
    {
        "id": 2405,
        "artist_id": 3374
    },
    {
        "id": 2425,
        "artist_id": 3395
    }
]

Alternatively we could add a YamlDriver. People often complain about YAML, but for reasons that don't really matter when the file is going to be written and read by the same parser over and over again.

YAML sounds like a good idea over JSON because it's even more readable, and it produces better diffs (no comma changes, less changed lines due to bracket changes)

- id: 2405
  artist_id: 3374
- id: 2425
  artist_id: 3395