Download the PHP package lucatume/codeception-snapshot-assertions without Composer

On this page you can find all versions of the php package lucatume/codeception-snapshot-assertions. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package codeception-snapshot-assertions

Codeception Snapshot Assertions

Leverage Codeception snapshot support to make snapshot testing in Codeception projects easier.

Code example

Requirements

The package is based on the snapshot support added in Codeception since version 2.5.0, as such the library requirments are:

Installation

Install the package using Composer:

Codeception is a requirement for the package to work and will be installed as a dependency if not specified in the project Composer configuration file (composer.json).

What is snapshot testing?

Snapshot testing is a convenient way to test code by testing its output.
Snapshot testing is faster than full-blown visual end-to-end testing (and not a replacement for it) but less cumbersome to write than lower lever unit testing (and, again, not a replacement for it).
This kind of testing lends itself to be used in unit and integration testing to automate the testing of output.
Read more about snapshot testing here:

How is this different from what Codeception does?

How is this different from what the Spatie package does?

Usage

The package supports the following type of assertions:

  1. string snapshot assertions, to compare a string to a string snapshot with the assertMatchesStringSnapshot method.
  2. HTML snapshot assertions, to compare an HTML fragment to an HTML fragment snapshot with the assertMatchesHtmlSnapshot method.
  3. JSON snapshot assertions, to compare a JSON string to a stored JSON snapshot with the assertMatchesJsonSnapshot method.
  4. Code snapshot assertions, to compare code to a stored code snapshot with the assertMatchesCodeSnapshot method.

The first time an assert... method is called the library will generate a snapshot file in the same directory as the tests, in the __snapshots__ folder.
As an example if the following test case lives in the tests/Output/WidgetTest.php file then when the testDefaultContent method runs the library will generate the tests/Output/WidgetTest__testDefaultContent__0.snapshot.html file; you can regenerate failing snapshots by running Codeception tests in debug mode (using the --debug flag of the run command).

Configuration

The library integrates with Codeception configuration system to allow some configuration options to be set. The library supports two configuration parameters:

The configuration parameters can be set in the codeception.yml or codeception.dist.yml file under the snapshot key, as in the following example:

Version

If the version string is set to a non-empty value the snapshot file name will be prefixed with it. In the following example the version parameter is set to alt and the snapshot file name will be WidgetTest__alt__testDefaultContent__alt.snapshot.html:

If the version parameter is not set, or set to an empty string, the snapshot file name will not be prefixed with anything and will be WidgetTest__testDefaultContent__0.snapshot.html:

Refresh

If the refresh parameter is set to true the snapshot will be regenerated on failure automatically. Normally Codeception snapshots are regenerated by running the tests in debug mode, using the --debug flag of the run command, and by replying yes to the prompt asking if the snapshots should be regenerated; or by removing the snapshot files manually. If the refresh parameter is set to true the snapshots will be regenerated automatically on failure, with no prompt, if the current test run is in debug mode.

String assertions

This kind of assertion is useful when the output of a method is a plain string.
The snapshot produced by this kind of assertion will have the .snapshot.txt file extension.
The method used to make string snapshot assertions is tad\Codeception\SnapshotAssertions\SnapshotAssertions::assertStringSnapshot().
Usage example;

HTML assertions

This kind of assertion is useful when the output of a method is an HTML document or HTML fragment.
The snapshot produced by this kind of assertion will have the .snapshot.html file extension.
The method used to make HTML snapshot assertions is tad\Codeception\SnapshotAssertions\SnapshotAssertions::assertHtmlSnapshot().
Usage example;

JSON assertions

This kind of assertion is useful when the output of a method is a JSON string.
The snapshot produced by this kind of assertion will have the .snapshot.html file extension.
The method used to make JSON snapshot assertions is tad\Codeception\SnapshotAssertions\SnapshotAssertions::assertJsonSnapshot().
Usage example:

Code assertions

This kind of assertion is useful when the output of a method is code.
The snapshot produced by this kind of assertion will have the .snapshot.php file extension by default, but you can specify an extension to use for the snapshot.
The method used to make code snapshot assertions is tad\Codeception\SnapshotAssertions\SnapshotAssertions::assertCodeSnapshot().
Usage example;

Directory assertions

This kind of assertion is useful to ensure directory structure and contents do not change overtime, when the output of a code block is a directory and files in it.
This assertion will check that the current directory, and the one captured in the snapshot, have the same files, and that each file has the same contents.
The snapshot produced by this kind of assertion will have the .snapshot file extension; they are plain text files.
The method used to make code snapshot assertions is tad\Codeception\SnapshotAssertions\SnapshotAssertions::assertDirectorySnapshot().
Usage example;

Visitor functions

To allow more fine-grained control over how the assertion on the data should be made, each Snapshot implementation supports "data visitors.".

A data visitor is a callable that will receive, from the snapshot implementation, the expected data and the current data.
Depending on the snapshot type the arguments received by the callback might differ or be more than two.

Examples

In the following example the data visitor is used to exclude some files from a directory snapshot and to drop some hashed lines from some files:

In this example the data visitor is used to remove some hash data from a JSON object:


All versions of codeception-snapshot-assertions with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
ext-dom Version *
gajus/dindent Version ^2.0
codeception/codeception Version ^5.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package lucatume/codeception-snapshot-assertions contains the following files

Loading the files please wait ....