Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge to 1.1 #42

Merged
merged 4 commits into from Jul 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
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/).

## [1.1.5] - 2017-07-02
## 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
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
@@ -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());
}
}