Skip to content

Commit

Permalink
Merge pull request #399 from tienvx/add-content-type-matcher-class
Browse files Browse the repository at this point in the history
refactor: Add ContentType matcher class
  • Loading branch information
tienvx committed Dec 17, 2023
2 parents 1fe6fe4 + 3b3c899 commit fceb35e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/PhpPact/Consumer/Matcher/Matchers/ContentType.php
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;

/**
* Match binary data by its content type (magic file check)
*/
class ContentType implements MatcherInterface
{
public function __construct(private string $contentType)
{
}

/**
* @return array<string, string>
*/
public function jsonSerialize(): array
{
return [
'value' => $this->contentType,
'pact:matcher:type' => $this->getType(),
];
}

public function getType(): string
{
return 'contentType';
}
}
18 changes: 18 additions & 0 deletions tests/PhpPact/Consumer/Matcher/Matchers/ContentTypeTest.php
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\ContentType;
use PHPUnit\Framework\TestCase;

class ContentTypeTest extends TestCase
{
public function testSerialize(): void
{
$contentType = new ContentType('text/csv');
$this->assertSame(
'{"value":"text\/csv","pact:matcher:type":"contentType"}',
json_encode($contentType)
);
}
}

0 comments on commit fceb35e

Please sign in to comment.