Skip to content

Use PHPUnit attributes #187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/MatchesSnapshots.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Spatie\Snapshots;

use PHPUnit\Framework\Attributes\Before;
use PHPUnit\Framework\Attributes\PostCondition;
use PHPUnit\Framework\ExpectationFailedException;
use ReflectionObject;
use Spatie\Snapshots\Concerns\SnapshotDirectoryAware;
Expand All @@ -23,13 +25,13 @@ trait MatchesSnapshots

protected array $snapshotChanges = [];

/** @before */
#[Before]
public function setUpSnapshotIncrementor()
{
$this->snapshotIncrementor = 0;
}

/** @postCondition */
#[PostCondition]
public function markTestIncompleteIfSnapshotsHaveChanged()
{
if (empty($this->snapshotChanges)) {
Expand Down
17 changes: 9 additions & 8 deletions tests/Integration/AssertionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Spatie\Snapshots\Test\Integration;

use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Spatie\Snapshots\MatchesSnapshots;

Expand All @@ -17,63 +18,63 @@ public function setUp(): void
$this->setUpComparesSnapshotFiles();
}

/** @test */
#[Test]
public function can_match_a_string_snapshot()
{
$data = 'Foo';

$this->assertMatchesSnapshot($data);
}

/** @test */
#[Test]
public function can_match_an_html_snapshot()
{
$data = '<!doctype html><html lang="en"><head></head><body><h1>Hello, world!</h1></body></html>';

$this->assertMatchesHtmlSnapshot($data);
}

/** @test */
#[Test]
public function can_match_an_xml_snapshot()
{
$data = '<foo><bar>Baz</bar></foo>';

$this->assertMatchesXmlSnapshot($data);
}

/** @test */
#[Test]
public function can_match_a_json_snapshot()
{
$data = '{"foo":"foo","bar":"bar","baz":"baz"}';

$this->assertMatchesJsonSnapshot($data);
}

/** @test */
#[Test]
public function can_match_an_array_snapshot()
{
$data = ['foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz'];

$this->assertMatchesJsonSnapshot($data);
}

/** @test */
#[Test]
public function can_match_a_file_hash_snapshot()
{
$filePath = __DIR__.'/stubs/example_snapshots/snapshot.json';

$this->assertMatchesFileHashSnapshot($filePath);
}

/** @test */
#[Test]
public function can_match_a_file_snapshot()
{
$filePath = __DIR__.'/stubs/test_files/friendly_man.jpg';

$this->assertMatchesFileSnapshot($filePath);
}

/** @test */
#[Test]
public function can_do_multiple_snapshot_assertions()
{
$this->assertMatchesSnapshot('Foo');
Expand Down
Loading