Skip to content

Commit

Permalink
Update Search images request:
Browse files Browse the repository at this point in the history
- add serializeRequest()
  • Loading branch information
webeweb committed Feb 5, 2023
1 parent ac267ea commit 88cfad9
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Request/SearchImagesRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use InvalidArgumentException;
use WBW\Library\Pixabay\Api\SearchImagesRequestInterface;
use WBW\Library\Pixabay\Serializer\RequestSerializer;

/**
* Search images request.
Expand Down Expand Up @@ -209,6 +210,13 @@ public function removeColor(string $color): SearchImagesRequest {
return $this;
}

/**
* {@inheritdoc}
*/
public function serializeRequest(): array {
return RequestSerializer::serializeSearchImagesRequest($this);
}

/**
* Set the colors.
*
Expand Down
47 changes: 47 additions & 0 deletions tests/Request/SearchImagesRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use InvalidArgumentException;
use Throwable;
use WBW\Library\Pixabay\Api\RequestInterface;
use WBW\Library\Pixabay\Api\SearchImagesRequestInterface;
use WBW\Library\Pixabay\Request\SearchImagesRequest;
use WBW\Library\Pixabay\Tests\AbstractTestCase;
Expand All @@ -25,6 +26,52 @@
*/
class SearchImagesRequestTest extends AbstractTestCase {

/**
* Tests serializeRequest()
*
* @return void
*/
public function testSerializeRequest(): void {

$obj = new SearchImagesRequest();
$obj->setCategory("category");
$obj->setEditorsChoice(true);
$obj->setId(1234);
$obj->setLang("fr");
$obj->setMinHeight(720);
$obj->setMinWidth(1280);
$obj->setOrder(RequestInterface::ORDER_LATEST);
$obj->setPage(2);
$obj->setPerPage(15);
$obj->setPretty(true);
$obj->setQ("github");
$obj->setSafeSearch(true);

$obj->addColor(RequestInterface::COLOR_BLACK);
$obj->setImageType(RequestInterface::IMAGE_TYPE_PHOTO);
$obj->setOrientation(RequestInterface::ORIENTATION_HORIZONTAL);

$res = $obj->serializeRequest();
$this->assertCount(15, $res);

$this->assertEquals("category", $res["category"]);
$this->assertEquals("true", $res["editors_choice"]);
$this->assertEquals(1234, $res["id"]);
$this->assertEquals("fr", $res["lang"]);
$this->assertEquals(720, $res["min_height"]);
$this->assertEquals(1280, $res["min_width"]);
$this->assertEquals(RequestInterface::ORDER_LATEST, $res["order"]);
$this->assertEquals(2, $res["page"]);
$this->assertEquals(15, $res["per_page"]);
$this->assertEquals("true", $res["pretty"]);
$this->assertEquals("github", $res["q"]);
$this->assertEquals("true", $res["safesearch"]);

$this->assertEquals(RequestInterface::COLOR_BLACK, $res["colors"]);
$this->assertEquals(RequestInterface::IMAGE_TYPE_PHOTO, $res["image_type"]);
$this->assertEquals(RequestInterface::ORIENTATION_HORIZONTAL, $res["orientation"]);
}

/**
* Tests addColor()
*
Expand Down

0 comments on commit 88cfad9

Please sign in to comment.