PHP code example of lucatume / wp-snaphot-assertions
1. Go to this page and download the library: Download lucatume/wp-snaphot-assertions library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lucatume / wp-snaphot-assertions example snippets
use Spatie\Snapshots\MatchesSnapshots;
use tad\WP\Snapshots\WPHtmlOutputDriver;
class MySnapshotTest extends \Codeception\TestCase\WPTestCase {
use MatchesSnapshots;
/**
* Test snapshot for render
*/
public function test_snapshot_render() {
// from some environment variable
$currentWpUrl = getenv('WP_URL');
$snapshotUrl = 'http://wp.localhost';
$driver = new WPHtmlOutputDriver($currentWpUrl, $snapshotUrl);
$sut = new MyPluginHTMLRenderingClass();
// create a random post and return its post ID
$postId= $this->factory->post->create();
$renderedHtml = $sut->renderHtmlFor($postId);
$driver->setTolerableDifferences([$postId]);
$driver->setTolerableDifferencesPrefixes(['post_', 'post-']);
$driver->setTolerableDifferencesPostfixes(['-single', '-another-postfix']);
$this->assertMatchesSnapshot($renderedHtml, $driver);
}
}
// Void all the `data-one` attributes in the HTML document.
$driver->setTimeDependentAttributes(['data-one']);
// Void all the `.container data-two` and `.container data-three` attributes in the HTML document.
$driver->setTimeDependentAttributes(['data-two', 'data-three'], '.container');
$this->assertMatchesSnapshot($renderedHtml, $driver);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.