Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

binary output checks for REST module #3993

Merged
merged 2 commits into from
Feb 4, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
28 changes: 28 additions & 0 deletions src/Codeception/Module/REST.php
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,34 @@ public function dontSeeXmlResponseIncludes($xml)
);
}

/**
* Checks if the hash of a binary response is exactly the same as provided.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a code example would be very helpful here. You can take one from your tests and add here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done (3 of them!)

*
* @param $hash the hashed data response expected
* @param $algo the hash algorithm to use. Default md5.
* @part json
* @part xml
*/
public function seeBinaryResponseEquals($hash, $algo = 'md5')
{
$responseHash = hash($algo, $this->connectionModule->_getResponseContent());
$this->assertEquals($hash, $responseHash);
}

/**
* Checks if the hash of a binary response is not the same as provided.
*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and one example here, please :)

* @param $hash the hashed data response expected
* @param $algo the hash algorithm to use. Default md5.
* @part json
* @part xml
*/
public function dontSeeBinaryResponseEquals($hash, $algo = 'md5')
{
$responseHash = hash($algo, $this->connectionModule->_getResponseContent());
$this->assertNotEquals($hash, $responseHash);
}

/**
* Deprecated since 2.0.9 and removed since 2.1.0
*
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/Codeception/Module/RestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,19 @@ public function testSeeResponseJsonMatchesXpathCanHandleResponseWithOneSubArray(
$this->module->seeResponseJsonMatchesXpath('//array/success');
}

public function testSeeBinaryResponseEquals()
{
$data = base64_decode('/9j/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkICQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD/yQALCAABAAEBAREA/8wABgAQEAX/2gAIAQEAAD8A0s8g/9k=');
$this->setStubResponse($data);
$this->module->seeBinaryResponseEquals(md5($data));
}

public function testDontSeeBinaryResponseEquals()
{
$data = base64_decode('/9j/2wBDAAMCAgICAgMCAgIDAwMDBAYEBAQEBAgGBgUGCQgKCgkICQkKDA8MCgsOCwkJDRENDg8QEBEQCgwSExIQEw8QEBD/yQALCAABAAEBAREA/8wABgAQEAX/2gAIAQEAAD8A0s8g/9k=');
$this->setStubResponse($data);
$this->module->dontSeeBinaryResponseEquals('024f615102cdb3c8c7cf75cdc5a83d15');
}

protected function shouldFail()
{
Expand Down