Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge branch 'prototype/mvc-module' of github.com:weierophinney/zf2 i…
Browse files Browse the repository at this point in the history
…nto prototype/mvc-module
  • Loading branch information
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,20 @@ protected function parseUserInfo()
$this->setUser($user);
$this->setPassword($password);
}


/**
* Return the URI port
*
* If no port is set, will return the default port according to the scheme
*
* @return integer
* @see Zend\Uri\Uri::getPort()
*/
public function getPort()
{
if (empty($this->port)) {
if (array_key_exists($this->scheme, self::$defaultPorts)) {
$this->port= self::$defaultPorts[$this->scheme];
return self::$defaultPorts[$this->scheme];
}
}
return $this->port;
Expand Down
27 changes: 27 additions & 0 deletions test/HttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,32 @@ public function testUserInfoCanOmitPassword()
$this->assertEquals('example.com', $uri->getHost());
}

public function testGetPortReturnsDefaultPortHttp()
{
$uri = new HttpUri('http://www.example.com/');
$this->assertEquals(80, $uri->getPort());
}

public function testGetPortReturnsDefaultPortHttps()
{
$uri = new HttpUri('https://www.example.com/');
$this->assertEquals(443, $uri->getPort());
}

public function testGetPortDoesntModifyUrlHttp()
{
$origUri = 'http://www.example.com/foo';
$uri = new HttpUri($origUri);
$uri->getPort();
$this->assertEquals($origUri, $uri->toString());
}

public function testGetPortDoesntModifyUrlHttps()
{
$origUri = 'https://www.example.com/foo';
$uri = new HttpUri($origUri);
$uri->getPort();
$this->assertEquals($origUri, $uri->toString());
}
}

0 comments on commit 384145a

Please sign in to comment.