-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from piotrbelina/feature/fix-invalid-sort-value
Fixed invalid sort value type error
- Loading branch information
Showing
6 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace WoohooLabs\Yin\JsonApi\Exception; | ||
|
||
use WoohooLabs\Yin\JsonApi\Schema\Error; | ||
use WoohooLabs\Yin\JsonApi\Schema\ErrorSource; | ||
|
||
class QueryParamMalformed extends JsonApiException | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $malformedQueryParam; | ||
|
||
/** | ||
* @var mixed | ||
*/ | ||
protected $malformedQueryParamValue; | ||
|
||
/** | ||
* QueryParamMalformed constructor. | ||
* @param string $malformedQueryParam | ||
* @param mixed $malformedQueryParamValue | ||
*/ | ||
public function __construct(string $malformedQueryParam, $malformedQueryParamValue) | ||
{ | ||
parent::__construct("Query parameter '$malformedQueryParam' is malformed!"); | ||
$this->malformedQueryParam = $malformedQueryParam; | ||
$this->malformedQueryParamValue = $malformedQueryParamValue; | ||
} | ||
|
||
protected function getErrors(): array | ||
{ | ||
return [ | ||
Error::create() | ||
->setStatus("400") | ||
->setCode("QUERY_PARAM_MALFORMED") | ||
->setTitle("Query parameter is malformed") | ||
->setDetail("Query parameter '$this->malformedQueryParam' is malformed!") | ||
->setSource(ErrorSource::fromParameter($this->malformedQueryParam)) | ||
]; | ||
} | ||
|
||
public function getMalformedQueryParam(): string | ||
{ | ||
return $this->malformedQueryParam; | ||
} | ||
|
||
public function getMalformedQueryParamValue() | ||
{ | ||
return $this->malformedQueryParamValue; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace WoohooLabs\Yin\Tests\JsonApi\Exception; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use WoohooLabs\Yin\JsonApi\Exception\QueryParamMalformed; | ||
|
||
class QueryParamMalformedTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function getQueryParam() | ||
{ | ||
$queryParam = "sort"; | ||
$queryParamValue = ["field" => "asc"]; | ||
|
||
$exception = $this->createException($queryParam, $queryParamValue); | ||
$this->assertEquals($queryParam, $exception->getMalformedQueryParam()); | ||
$this->assertEquals($queryParamValue, $exception->getMalformedQueryParamValue()); | ||
} | ||
|
||
private function createException($queryParam, $queryParamValue): QueryParamMalformed | ||
{ | ||
return new QueryParamMalformed($queryParam, $queryParamValue); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters