Skip to content
This repository was archived by the owner on Apr 20, 2021. It is now read-only.
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
31 changes: 29 additions & 2 deletions src/Context/RestContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Behatch\Context;

use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
use Behat\Mink\Exception\ExpectationException;
use Behatch\HttpCall\Request;
use Behat\Gherkin\Node\TableNode;
use Behat\Gherkin\Node\PyStringNode;

class RestContext extends BaseContext
{
Expand Down Expand Up @@ -181,6 +181,33 @@ protected function theHeaderShouldExist($name)
return $this->request->getHttpHeader($name);
}

/**
* @Then the header :name should match :regex
*/
public function theHeaderShouldMatch($name, $regex)
{
$actual = $this->request->getHttpHeader($name);

$this->assertEquals(
1,
preg_match($regex, $actual),
"The header '$name' should match '$regex', but it is: '$actual'"
);
}

/**
* @Then the header :name should not match :regex
*/
public function theHeaderShouldNotMatch($name, $regex)
{
$this->not(
function () use ($name, $regex) {
$this->theHeaderShouldMatch($name, $regex);
},
"The header '$name' should not match '$regex'"
);
}

/**
* Checks, that the response header expire is in the future
*
Expand Down
2 changes: 2 additions & 0 deletions tests/features/rest.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Feature: Testing RESTContext
And the header "Content-Type" should be equal to "text/html; charset=UTF-8"
And the header "Content-Type" should not be equal to "x-test/no-such-type"
And the header "Content-Type" should not contain "text/json"
And the header "Content-Type" should match "@^text/html; [a-zA-Z=-]+@"
And the header "Content-Type" should not match "/^no-such-type$/"
And the header "xxx" should not exist
And the response should expire in the future
And the response should be encoded in "UTF-8"
Expand Down