Skip to content

Commit

Permalink
Added method and content parameters to HttpOptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul committed Aug 11, 2016
1 parent 9aa5bd4 commit 54413a4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/Porter/Net/Http/HttpOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ public function setQueryParameters(array $queryParameters)
return $this->set('queryParameters', $queryParameters);
}

/**
* @return string
*/
public function getMethod()
{
return $this->get('method');
}

/**
* @param string $method
*
* @return $this
*/
public function setMethod($method)
{
return $this->set('method', "$method");
}

/**
* @return array
*/
Expand Down Expand Up @@ -97,10 +115,30 @@ public function findHeaders($name)
});
}

/**
* @return string
*/
public function getContent()
{
return $this->get('content');
}

/**
* @param string $content
*
* @return $this
*/
public function setContent($content)
{
return $this->set('content', "$content");
}

/**
* Extracts a list of HTTP context options only.
*
* @return array HTTP context options.
*
* @see http://php.net/manual/en/context.http.php
*/
public function extractHttpContextOptions()
{
Expand Down
18 changes: 18 additions & 0 deletions test/Unit/Porter/Net/Http/HttpOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ public function testOptionDefaults()
self::assertSame([], $options->getHeaders());
}

public function testQueryParameters()
{
self::assertSame(
$query = ['foo' => 'bar'],
(new HttpOptions)->setQueryParameters($query)->getQueryParameters()
);
}

public function testMethod()
{
self::assertSame('foo', (new HttpOptions)->setMethod('foo')->getMethod());
}

public function testFindHeader()
{
$options = (new HttpOptions)->addHeader('Foo: bar')->addHeader($baz = 'Baz: bat');
Expand Down Expand Up @@ -55,4 +68,9 @@ public function testExtractHttpContextOptions()

self::assertSame(['header' => ['foo']], $options->extractHttpContextOptions());
}

public function testContent()
{
self::assertSame($content = "foo\nbar", (new HttpOptions)->setContent($content)->getContent());
}
}

0 comments on commit 54413a4

Please sign in to comment.