Skip to content

Commit

Permalink
Fix tests because of undefined index
Browse files Browse the repository at this point in the history
  • Loading branch information
kocsismate committed Dec 6, 2017
1 parent 1cf5c61 commit bb4238c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
14 changes: 7 additions & 7 deletions src/JsonApi/Request/JsonApiRequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,23 +134,23 @@ public function setUri(string $uri): JsonApiRequestBuilder
return $this;
}

if ($this->isBlank($parsedUrl["scheme"]) === false) {
if ($this->isBlankKey($parsedUrl, "scheme") === false) {
$this->scheme = $parsedUrl["scheme"];
}

if (empty((int) $parsedUrl["port"]) === false) {
if ($this->isBlankKey($parsedUrl, "port") === false) {
$this->port = (int) $parsedUrl["port"];
}

if ($this->isBlank($parsedUrl["host"]) === false) {
if ($this->isBlankKey($parsedUrl, "host") === false) {
$this->host = $parsedUrl["host"];
}

if ($this->isBlank($parsedUrl["path"]) === false) {
if ($this->isBlankKey($parsedUrl, "path") === false) {
$this->path = $parsedUrl["path"];
}

if ($this->isBlank($parsedUrl["query"]) === false) {
if ($this->isBlankKey($parsedUrl, "query") === false) {
parse_str($parsedUrl["query"], $this->queryString);
}

Expand Down Expand Up @@ -309,8 +309,8 @@ private function setListQueryParam(string $name, $queryParam): void
}
}

private function isBlank($value): bool
private function isBlankKey(array $array, string $key): bool
{
return empty($value) && !is_numeric($value);
return empty($array[$key]) && !is_numeric($array[$key]);
}
}
8 changes: 4 additions & 4 deletions src/JsonApi/Schema/Relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private static function createToOneFromArray(
$resourceMap = [];
$isToOneRelationship = true;

if (self::isBlank($data["type"]) === false && self::isBlank($data["id"]) === false) {
if (self::isBlankKey($data, "type") === false && self::isBlankKey($data, "id") === false) {
$resourceMap = [
[
"type" => $data["type"],
Expand All @@ -105,7 +105,7 @@ private static function createToManyFromArray(
$resourceMap = [];

foreach ($data as $item) {
if (self::isBlank($item["type"]) === false && self::isBlank($item["id"]) === false) {
if (self::isBlankKey($item, "type") === false && self::isBlankKey($item, "id") === false) {
$resource = [
"type" => $item["type"],
"id" => $item["id"],
Expand Down Expand Up @@ -293,8 +293,8 @@ private static function isArrayKey(array $array, string $key): bool
return isset($array[$key]) && is_array($array[$key]);
}

private static function isBlank($value): bool
private static function isBlankKey(array $array, string $key): bool
{
return empty($value) && !is_numeric($value);
return empty($array[$key]) && !is_numeric($array[$key]);
}
}
14 changes: 13 additions & 1 deletion tests/JsonApi/Request/JsonApiRequestBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,19 @@ public function setUri()
/**
* @test
*/
public function setUriWithZero()
public function setUriWithoutPath()
{
$requestBuilder = $this->createRequestBuilder();

$requestBuilder->setUri("http://example.com");

$this->assertSame("http://example.com", $requestBuilder->getRequest()->getUri()->__toString());
}

/**
* @test
*/
public function setUriWithQueryParamAsZero()
{
$requestBuilder = $this->createRequestBuilder();

Expand Down

0 comments on commit bb4238c

Please sign in to comment.