PHPackages                             fkupper/module-dynamic-snapshots - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. fkupper/module-dynamic-snapshots

ActiveLibrary[Testing &amp; Quality](/categories/testing)

fkupper/module-dynamic-snapshots
================================

Dynamic content snapshot testing for Codeception

v5.0.2(2y ago)1184.9k↓58.2%2[2 PRs](https://github.com/fkupper/module-dynamic-snapshots/pulls)MITPHPPHP ^8.0.|^8.1|^8.2CI passing

Since Oct 3Pushed 2y ago1 watchersCompare

[ Source](https://github.com/fkupper/module-dynamic-snapshots)[ Packagist](https://packagist.org/packages/fkupper/module-dynamic-snapshots)[ RSS](/packages/fkupper-module-dynamic-snapshots/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (9)Dependencies (5)Versions (16)Used By (0)

Codeception Dynamic Snapshots Module
====================================

[](#codeception-dynamic-snapshots-module)

[![Build Status](https://github.com/fkupper/module-dynamic-snapshots/actions/workflows/php.yml/badge.svg?branch=master)](https://github.com/fkupper/module-dynamic-snapshots/actions/workflows/php.yml/badge.svg?branch=master)[![Coverage Status](https://camo.githubusercontent.com/a7c596d23639ee9d24dfd60509de12705dd7ae0e40795a9cbb9f0a536fba80b1/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f666b75707065722f6d6f64756c652d64796e616d69632d736e617073686f74732f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/fkupper/module-dynamic-snapshots?branch=master)[![Total Downloads](https://camo.githubusercontent.com/eea8ab2db3dfaa24b8db696347b11c390151b4efff8ddfdf640b6be60712f544/68747470733a2f2f706f7365722e707567782e6f72672f666b75707065722f6d6f64756c652d64796e616d69632d736e617073686f74732f646f776e6c6f616473)](//packagist.org/packages/fkupper/module-dynamic-snapshots)[![Monthly Downloads](https://camo.githubusercontent.com/a901bd58f615724702cbb991ec9e64500e90e66fab2c6e4d24c0fe31e21bb23d/68747470733a2f2f706f7365722e707567782e6f72672f666b75707065722f6d6f64756c652d64796e616d69632d736e617073686f74732f642f6d6f6e74686c79)](//packagist.org/packages/fkupper/module-dynamic-snapshots)

This is a module that can be used together with [Codeception](https://github.com/Codeception/Codeception) to test Snapshots with dynamic data.

Installation
============

[](#installation)

Using composer:

```
composer require "fkupper/module-dynamic-snapshots"
```

On your `codeception.yml` file, add:

```
extensions:
    commands:
        - Fkupper\Command\GenerateDynamicSnapshot
```

Usage
=====

[](#usage)

Creating Snapshots
------------------

[](#creating-snapshots)

New snapshots cna be created using codeception client with the custom command in this package. Eg:

```
php ./vendor/bin/codecept generate:dynamicsnapshot Acceptance Products
```

Fetching dynamic snapshot data
------------------------------

[](#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:

```
class FooSnapshot extends DynamicSnapshot
{
    /**
     * @var Tester
     */
    protected $tester;

    public function fetchDynamicData()
    {
        // fetch snapshot from a helper method or snomething and return
        return $this->tester->fetchDataFromSomewhere();
    }
}
```

Substitutions
-------------

[](#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:

```
class FooSnapshot extends DynamicSnapshot
{
    /**
     * @var Tester
     */
    protected $tester;

    public function fetchDynamicData()
    {
        $this->setSubstitutions(
            // $this->tester->getAppVersion() returns "v8.8.9"
            'app_version' => $this->tester->getAppVersion()
        );
        // fetch snapshot from a helper method or snomething and return
        return $this->tester->fetchDataFromXml();
    }
}
```

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
-------------------------------------------

[](#using-the-dynamic-snapshot-classes-in-tests)

Please refer to [Codepcetion's standard Snapshot documentation](https://codeception.com/docs/09-Data#Testing-Dynamic-Data-with-Snapshots).

Custom placeholder wrappers
---------------------------

[](#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`:

```
class FooSnapshot extends DynamicSnapshot
{
    protected $tester;

    public function __constructor(Tester $I)
    {
        $this->tester = $I;
        $this->setWrappers('{', '}');
        // $this->setWrappers('(', ')');
        // $this->setWrappers('');
    }
}
```

Ignoring parts of the snapshot data
-----------------------------------

[](#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:

```
$this->setIgnoredLinesPatterns(['/^.*favicon.*$/m']);
```

Handling space sequences
------------------------

[](#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
------------------------

[](#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.

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 79.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~143 days

Recently: every ~136 days

Total

10

Last Release

782d ago

Major Versions

v1.0.1 → v2.02021-07-13

v2.0.1 → v3.0.02022-09-22

v3.0.1 → v5.0.02023-03-01

PHP version history (4 changes)v1.0PHP &gt;=7.2 &lt;8.0

v2.0PHP ^7.4 || ^8.0

v3.0.0PHP ^8.0

v5.0.0PHP ^8.0.|^8.1|^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/599fb5c824458d0e5cb099f6b83f0bd158c1c094f5d52821784f437ecf849741?d=identicon)[fernando.kupper](/maintainers/fernando.kupper)

---

Top Contributors

[![fkupper](https://avatars.githubusercontent.com/u/10757561?v=4)](https://github.com/fkupper "fkupper (47 commits)")[![countless-integers](https://avatars.githubusercontent.com/u/2060726?v=4)](https://github.com/countless-integers "countless-integers (11 commits)")[![arkaitzgarro](https://avatars.githubusercontent.com/u/1712467?v=4)](https://github.com/arkaitzgarro "arkaitzgarro (1 commits)")

---

Tags

codeceptiondynamic-datadynamic-snapshotssnapshot-datasnapshot-testssnapshotcodeception

###  Code Quality

Static AnalysisPsalm

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/fkupper-module-dynamic-snapshots/health.svg)

```
[![Health](https://phpackages.com/badges/fkupper-module-dynamic-snapshots/health.svg)](https://phpackages.com/packages/fkupper-module-dynamic-snapshots)
```

###  Alternatives

[lucatume/wp-browser

A set of Codeception modules to test WordPress projects.

6394.0M169](/packages/lucatume-wp-browser)[codeception/module-asserts

Codeception module containing various assertions

8552.9M1.4k](/packages/codeception-module-asserts)[codeception/lib-innerbrowser

Parent library for all Codeception framework modules and PhpBrowser

8643.5M86](/packages/codeception-lib-innerbrowser)[allure-framework/allure-codeception

Allure Codeception integration

5412.5M9](/packages/allure-framework-allure-codeception)[codeception/module-symfony

Codeception module for Symfony framework

979.8M128](/packages/codeception-module-symfony)[codeception/module-webdriver

WebDriver module for Codeception

3832.8M301](/packages/codeception-module-webdriver)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
