Skip to content

Commit

Permalink
Merge pull request #187 from simonhammes/phpunit-11
Browse files Browse the repository at this point in the history
Use PHPUnit attributes
  • Loading branch information
freekmurze committed Feb 20, 2024
2 parents 04bab93 + 2d4c036 commit 6d06429
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 92 deletions.
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

0 comments on commit 6d06429

Please sign in to comment.