Download the PHP package fkupper/module-dynamic-snapshots without Composer
On this page you can find all versions of the php package fkupper/module-dynamic-snapshots. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download fkupper/module-dynamic-snapshots
More information about fkupper/module-dynamic-snapshots
Files in fkupper/module-dynamic-snapshots
Package module-dynamic-snapshots
Short Description Dynamic content snapshot testing for Codeception
License MIT
Informations about the package module-dynamic-snapshots
Codeception Dynamic Snapshots Module
This is a module that can be used together with Codeception to test Snapshots with dynamic data.
Installation
Using composer:
On your codeception.yml
file, add:
Usage
Creating Snapshots
New snapshots cna be created using codeception client with the custom command in this package. Eg:
Fetching dynamic snapshot data
Similar to vanilla Codeception snapshots, the DynamicSnapshots classes will fetch data using the method fetchDynamicData
. So, in your snapshots you will have to implement this method:
Substitutions
This is the main feature of this package. When dealing with variable data in snapshots, they can be replaced with placeholders and replaced back in runtime everytime the snapshot tests are executed.
For example, if you want to test a XML API response containing static data and variable data:
The property "appVersion"
can change anytime and to avoid updating it every time, use setSubstitutions
method to replace it with a string (or a value that can be casted to string) of your choice:
The first time the dynamic snapshot test is executed, a snapshot data file will be created like:
Note that placeholders are wrapped in [ ]
, and from now on, whenever the app version changes, the snapshot will not break or require an update.
Using the dynamic snapshot classes in tests
Please refer to Codepcetion's standard Snapshot documentation.
Custom placeholder wrappers
By default, placeholders are wrapped in brackets [ ]
, but it is possible to change what character or sequence of charaters it should use.
For example, if brackets are sensible part of your snapshot data, you can change it to something else using setWrappers
:
Ignoring parts of the snapshot data
If your snapshot have variable data that cannot be tested or that you just want to igore, it is possible to provide a list of regular expression patterns that will be removed from the data when asserting.
For example, in the snapshot data below, the current timestamp in the favicon href property have to be ignored:
So you can ignore this line by calling setIgnoredLinesPatterns
from your snapshot object:
Handling space sequences
Sometimes your snapshot data can have variable amounts of space characters in sequence that change out of your control.
To toggle your snapshot behavior to ignore these spaces or not, use shouldAllowSpaceSequences(true|false)
. Setting it to true will compact these space sequences to a single space character.
Note that the default is true
, so these sequences will never be reduced to one space if you do not specify them to.
Handling trailing spaces
If you want to clear every line of your snapshot data of trailing spaces, use shouldAllowTrailingSpaces(false)
.
Note that the default is true
, so trailing spaces in your snapshot data will never be removed.