Skip to content

Commit

Permalink
Make url() interoperable with PSR7
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed May 7, 2016
1 parent 92081fa commit 2e97ed6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
13 changes: 3 additions & 10 deletions src/Http/Client/Request.php
Expand Up @@ -23,7 +23,6 @@
*
* Used by Cake\Network\Http\Client to contain request information
* for making requests.
*
*/
class Request extends Message implements RequestInterface
{
Expand All @@ -37,13 +36,6 @@ class Request extends Message implements RequestInterface
*/
protected $_body;

/**
* The URL to request.
*
* @var string
*/
protected $_url;

/**
* Constructor
*
Expand Down Expand Up @@ -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;
}

Expand Down
30 changes: 30 additions & 0 deletions tests/TestCase/Network/Http/RequestTest.php
Expand Up @@ -15,6 +15,7 @@

use Cake\Network\Http\Request;
use Cake\TestSuite\TestCase;
use Zend\Diactoros\Uri;

/**
* HTTP request test.
Expand All @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit 2e97ed6

Please sign in to comment.