Skip to content

Commit

Permalink
add ObjectOrNullWildcard (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
bitladen-jw authored May 5, 2021
1 parent c86c2ec commit 6b772b5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ The library currently supports the following wildcards:
- DateTimeWildcard
- DateTimeOrNullWildcard
- StringWildcard
- ObjectOrNullWildcard

### Usage in CI
When running your tests in Continuous Integration you would possibly want to disable the creation of snapshots.
Expand Down
42 changes: 42 additions & 0 deletions src/Wildcard/ObjectOrNullWildcard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace KigaRoo\SnapshotTesting\Wildcard;

use InvalidArgumentException;
use Webmozart\Assert\Assert;

final class ObjectOrNullWildcard implements Wildcard
{
/** @var string */
private $path;

public function __construct(string $path)
{
$this->path = $path;
}

public function atPath() : string
{
return $this->path;
}

/**
* @param mixed $mixed
*/
public function match($mixed) : bool
{
if (null === $mixed) {
return true;
}

try {
Assert::object($mixed);

return true;
} catch (InvalidArgumentException $exception) {
return false;
}
}
}

0 comments on commit 6b772b5

Please sign in to comment.