Skip to content

Commit

Permalink
tests and static analysis cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Vaughn committed Feb 21, 2019
1 parent 948a525 commit d360c87
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/HttpPlug.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ class HttpPlug {
protected $user;

/**
* @var string - password for basic auth credentials
* @var string|null - password for basic auth credentials
*/
protected $password;
protected $password = null;

/**
* @var IMutableHeaders - stores the headers for the request
Expand Down
28 changes: 28 additions & 0 deletions tests/HttpPlug/MockInvoke/get_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,32 @@ public function Will_throw_if_cannot_unserialize_php() {
$this->assertEquals(200, $maxContentLength);
$this->assertTrue($exceptionThrown);
}

/**
* @test
*/
public function Can_unserialize_empty_php_body() {

// arrange
$uri = XUri::tryParse('test://example.com/foo');
MockPlug::register(
$this->newDefaultMockRequestMatcher(HttpPlug::METHOD_GET, $uri),
(new HttpResult())
->withStatus(200)
->withHeaders(Headers::newFromHeaderNameValuePairs([
[Headers::HEADER_CONTENT_TYPE, ContentType::PHP],
[Headers::HEADER_CONTENT_LENGTH, '0']
]))
->withBody('')
);
$plug = new HttpPlug($uri);

// act
$parser = (new SerializedPhpArrayParser())->withMaxContentLength(50000);
$result = $plug->withHttpResultParser($parser)->get();

// assert
$this->assertEquals(200, $result->getStatus());
$this->assertEquals('', $result->getBody()->getVal('body'));
}
}
16 changes: 16 additions & 0 deletions tests/HttpPlug/getUri_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@ public function Can_get_uri_with_credentials() {
$this->assertEquals('http://aaa:[email protected]/bar/baz?a=b&c=d', $result->toString());
}

/**
* @test
*/
public function Can_get_uri_with_username_credential() {

// arrange
$plug = (new HttpPlug(XUri::tryParse('http://foo.com/bar/baz?a=b&c=d')))
->withCredentials('aaa', null);

// act
$result = $plug->getUri(true);

// assert
$this->assertEquals('http://aaa:@foo.com/bar/baz?a=b&c=d', $result->toString());
}

/**
* @test
*/
Expand Down

0 comments on commit d360c87

Please sign in to comment.