Skip to content
This repository has been archived by the owner on Apr 20, 2021. It is now read-only.

Commit

Permalink
Merge branch 'jdeniau-feat-headerShouldMatch'
Browse files Browse the repository at this point in the history
  • Loading branch information
sanpii committed Nov 30, 2018
2 parents cbda31e + 7d33a81 commit 8f28369
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
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

0 comments on commit 8f28369

Please sign in to comment.