Skip to content

Commit

Permalink
Merge cdc0817 into b96044b
Browse files Browse the repository at this point in the history
  • Loading branch information
fcastilloes committed Jul 1, 2017
2 parents b96044b + cdc0817 commit 6ed4172
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## Upcoming
## Fixed
- Fixed url methods return type when a part is not found

## [1.1.4] - 2017-06-28
## Added
- Pass component to `setResource()` callback
Expand Down
26 changes: 13 additions & 13 deletions src/Api/Protocol/Http/HttpRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ class HttpRequest
* @param File[] $files
*/
public function __construct(
$version,
$method,
$url,
string $version,
string $method,
string $url,
array $query = [],
array $postData = [],
array $headers = [],
$body = '',
string $body = '',
array $files = []
) {
$this->version = $version;
Expand All @@ -98,49 +98,49 @@ public function __construct(
* @param string $method
* @return bool
*/
public function isMethod($method)
public function isMethod(string $method): bool
{
return $this->method === $method;
}

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

/**
* @return string
*/
public function getUrl()
public function getUrl(): string
{
return $this->url;
}

/**
* @return string
*/
public function getUrlScheme()
public function getUrlScheme(): string
{
return parse_url($this->url, PHP_URL_SCHEME);
return parse_url($this->url, PHP_URL_SCHEME) ?: '';
}

/**
* @return string
*/
public function getUrlHost()
public function getUrlHost(): string
{
return parse_url($this->url, PHP_URL_HOST);
return parse_url($this->url, PHP_URL_HOST) ?: '';
}

/**
* @return string
*/
public function getUrlPath()
public function getUrlPath(): string
{
return parse_url($this->url, PHP_URL_PATH);
return parse_url($this->url, PHP_URL_PATH) ?: '';
}

/**
Expand Down
57 changes: 57 additions & 0 deletions tests/Api/Protocol/Http/HttpRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/**
* PHP 7 SDK for the KATANA(tm) Framework (http://katana.kusanagi.io)
* Copyright (c) 2016-2017 KUSANAGI S.L. All rights reserved.
*
* Distributed under the MIT license
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code
*
* @link https://github.com/kusanagi/katana-sdk-php7
* @license http://www.opensource.org/licenses/mit-license.php MIT License
* @copyright Copyright (c) 2016-2017 KUSANAGI S.L. (http://kusanagi.io)
*/

namespace Katana\Sdk\Tests\Api\Protocol\Http;

use Katana\Sdk\Api\Protocol\Http\HttpRequest;
use PHPUnit\Framework\TestCase;

class HttpRequestTest extends TestCase
{
public function testHttpMethod()
{
$httpRequest = new HttpRequest('', 'get', '');
$this->assertFalse($httpRequest->isMethod('post'));
$this->assertTrue($httpRequest->isMethod('get'));
$this->assertEquals('get', $httpRequest->getMethod());
}

public function testEmptyUrl()
{
$httpRequest = new HttpRequest('', '', '');
$this->assertEquals('', $httpRequest->getUrl());
$this->assertEquals('', $httpRequest->getUrlScheme());
$this->assertEquals('', $httpRequest->getUrlHost());
$this->assertEquals('', $httpRequest->getUrlPath());
}

public function testUrlWithNoPath()
{
$httpRequest = new HttpRequest('', '', 'https://example.com');
$this->assertEquals('https://example.com', $httpRequest->getUrl());
$this->assertEquals('https', $httpRequest->getUrlScheme());
$this->assertEquals('example.com', $httpRequest->getUrlHost());
$this->assertEquals('', $httpRequest->getUrlPath());
}

public function testFullUrl()
{
$httpRequest = new HttpRequest('', '', 'https://example.com/path');
$this->assertEquals('https://example.com/path', $httpRequest->getUrl());
$this->assertEquals('https', $httpRequest->getUrlScheme());
$this->assertEquals('example.com', $httpRequest->getUrlHost());
$this->assertEquals('/path', $httpRequest->getUrlPath());
}
}

0 comments on commit 6ed4172

Please sign in to comment.