-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #403 from tienvx/add-includes-matcher-class
refactor: Add Includes matcher class
- Loading branch information
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace PhpPact\Consumer\Matcher\Matchers; | ||
|
||
use PhpPact\Consumer\Matcher\Model\MatcherInterface; | ||
|
||
/** | ||
* This checks if the string representation of a value contains the substring. | ||
*/ | ||
class Includes implements MatcherInterface | ||
{ | ||
public function __construct(private string $value) | ||
{ | ||
} | ||
|
||
/** | ||
* @return array<string, string> | ||
*/ | ||
public function jsonSerialize(): array | ||
{ | ||
return [ | ||
'pact:matcher:type' => $this->getType(), | ||
'value' => $this->value, | ||
]; | ||
} | ||
|
||
public function getType(): string | ||
{ | ||
return 'include'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace PhpPactTest\Consumer\Matcher\Matchers; | ||
|
||
use PhpPact\Consumer\Matcher\Matchers\Includes; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class IncludesTest extends TestCase | ||
{ | ||
public function testSerialize(): void | ||
{ | ||
$string = new Includes('contains this string'); | ||
$this->assertSame( | ||
'{"pact:matcher:type":"include","value":"contains this string"}', | ||
json_encode($string) | ||
); | ||
} | ||
} |