Skip to content
Permalink
Browse files

Make url() interoperable with PSR7

  • Loading branch information...
markstory committed May 7, 2016
1 parent 92081fa commit 2e97ed6c621e3de25e0f1bbc1ee4bcb8dd1a41eb
Showing with 33 additions and 10 deletions.
  1. +3 −10 src/Http/Client/Request.php
  2. +30 −0 tests/TestCase/Network/Http/RequestTest.php
@@ -23,7 +23,6 @@
*
* Used by Cake\Network\Http\Client to contain request information
* for making requests.
*
*/
class Request extends Message implements RequestInterface
{
@@ -37,13 +36,6 @@ class Request extends Message implements RequestInterface
*/
protected $_body;
/**
* The URL to request.
*
* @var string
*/
protected $_url;
/**
* Constructor
*
@@ -92,13 +84,14 @@ public function method($method = null)
*
* @param string|null $url The url for the request. Leave null for get
* @return $this|string Either $this or the url value.
* @deprecated 3.3.0 Use getUri() and withUri() instead.
*/
public function url($url = null)
{
if ($url === null) {
return $this->_url;
return '' . $this->getUri();
}
$this->_url = $url;
$this->uri = $this->createUri($url);
return $this;
}
@@ -15,6 +15,7 @@
use Cake\Network\Http\Request;
use Cake\TestSuite\TestCase;
use Zend\Diactoros\Uri;
/**
* HTTP request test.
@@ -35,6 +36,25 @@ public function testUrl()
$this->assertEquals('http://example.com', $request->url());
}
/**
* Test that url() modifies the PSR7 stream
*
* @return void
*/
public function testUrlInteroperability()
{
$request = new Request();
$request->url('http://example.com');
$this->assertSame('http://example.com', $request->url());
$this->assertSame('http://example.com', $request->getUri()->__toString());
$uri = 'http://example.com/test';
$request = new Request();
$request = $request->withUri(new Uri($uri));
$this->assertSame($uri, $request->url());
$this->assertSame($uri, $request->getUri()->__toString());
}
/**
* test method method.
*
@@ -91,6 +111,16 @@ public function testBody()
$this->assertEquals($data, $request->body());
}
/**
* Test that body() modifies the PSR7 stream
*
* @return void
*/
public function testBodyInteroperability()
{
$this->markTestIncomplete();
}
/**
* test header method.
*

0 comments on commit 2e97ed6

Please sign in to comment.
You can’t perform that action at this time.