Skip to content

Commit

Permalink
Improve unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
webeweb committed Apr 10, 2020
1 parent 86c7cf8 commit f047cf0
Show file tree
Hide file tree
Showing 19 changed files with 231 additions and 231 deletions.
34 changes: 17 additions & 17 deletions src/Serializer/ResponseDeserializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ class ResponseDeserializer {
*/
protected static function deserializeHit(AbstractHit $model, array $response) {

$model->setComments(intval(ArrayHelper::get($response, "comments", -1)));
$model->setDownloads(intval(ArrayHelper::get($response, "downloads", -1)));
$model->setFavorites(intval(ArrayHelper::get($response, "favorites", -1)));
$model->setId(intval(ArrayHelper::get($response, "id", -1)));
$model->setLikes(intval(ArrayHelper::get($response, "likes", -1)));
$model->setPageURL(ArrayHelper::get($response, "pageURL"));
$model->setTags(ArrayHelper::get($response, "tags"));
$model->setType(ArrayHelper::get($response, "type"));
$model->setUser(ArrayHelper::get($response, "user"));
$model->setTags(ArrayHelper::get($response, "tags"));
$model->setViews(intval(ArrayHelper::get($response, "views", -1)));
$model->setDownloads(intval(ArrayHelper::get($response, "downloads", -1)));
$model->setFavorites(intval(ArrayHelper::get($response, "favorites", -1)));
$model->setLikes(intval(ArrayHelper::get($response, "likes", -1)));
$model->setComments(intval(ArrayHelper::get($response, "comments", -1)));
$model->setUserId(intval(ArrayHelper::get($response, "user_id", -1)));
$model->setUser(ArrayHelper::get($response, "user"));
$model->setUserImageURL(ArrayHelper::get($response, "userImageURL"));
$model->setViews(intval(ArrayHelper::get($response, "views", -1)));
}

/**
Expand All @@ -63,18 +63,18 @@ protected static function deserializeImageHit(array $response) {

static::deserializeHit($model, $response);

$model->setFullHDURL(ArrayHelper::get($response, "fullHDURL"));
$model->setImageHeight(intval(ArrayHelper::get($response, "imageHeight", -1)));
$model->setImageSize(intval(ArrayHelper::get($response, "imageSize", -1)));
$model->setImageURL(ArrayHelper::get($response, "imageURL"));
$model->setImageWidth(intval(ArrayHelper::get($response, "imageWidth", -1)));
$model->setLargeImageURL(ArrayHelper::get($response, "largeImageURL"));
$model->setPreviewHeight(intval(ArrayHelper::get($response, "previewHeight", -1)));
$model->setPreviewURL(ArrayHelper::get($response, "previewURL"));
$model->setPreviewWidth(intval(ArrayHelper::get($response, "previewWidth", -1)));
$model->setWebFormatHeight(intval(ArrayHelper::get($response, "webformatHeight", -1)));
$model->setPreviewHeight(intval(ArrayHelper::get($response, "previewHeight", -1)));
$model->setWebFormatURL(ArrayHelper::get($response, "webformatURL"));
$model->setWebFormatWidth(intval(ArrayHelper::get($response, "webformatWidth", -1)));
$model->setWebFormatHeight(intval(ArrayHelper::get($response, "webformatHeight", -1)));
$model->setLargeImageURL(ArrayHelper::get($response, "largeImageURL"));
$model->setFullHDURL(ArrayHelper::get($response, "fullHDURL"));
$model->setImageURL(ArrayHelper::get($response, "imageURL"));
$model->setImageWidth(intval(ArrayHelper::get($response, "imageWidth", -1)));
$model->setImageHeight(intval(ArrayHelper::get($response, "imageHeight", -1)));
$model->setImageSize(intval(ArrayHelper::get($response, "imageSize", -1)));

return $model;
}
Expand Down Expand Up @@ -154,10 +154,10 @@ protected static function deserializeVideo(array $response) {

$model = new Video();

$model->setHeight(intval(ArrayHelper::get($response, "height", -1)));
$model->setSize(intval(ArrayHelper::get($response, "size", -1)));
$model->setUrl(ArrayHelper::get($response, "url"));
$model->setWidth(intval(ArrayHelper::get($response, "width", -1)));
$model->setHeight(intval(ArrayHelper::get($response, "height", -1)));
$model->setSize(intval(ArrayHelper::get($response, "size", -1)));

return $model;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/API/RequestInterfaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class RequestInterfaceTest extends AbstractTestCase {
*
* @return void
*/
public function testConstruct() {
public function test__construct() {

$this->assertEquals("bg", RequestInterface::LANG_BG);
$this->assertEquals("cs", RequestInterface::LANG_CS);
Expand Down
2 changes: 1 addition & 1 deletion tests/API/SearchImagesRequestInterfaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SearchImagesRequestInterfaceTest extends AbstractTestCase {
*
* @return void
*/
public function testConstructor() {
public function test__construct() {

$this->assertEquals("animals", SearchImagesRequestInterface::CATEGORY_ANIMALS);
$this->assertEquals("backgrounds", SearchImagesRequestInterface::CATEGORY_BACKGROUNDS);
Expand Down
2 changes: 1 addition & 1 deletion tests/API/SearchVideosRequestInterfaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SearchVideosRequestInterfaceTest extends AbstractTestCase {
*
* @return void
*/
public function testConstructor() {
public function test__construct() {

$this->assertEquals("all", SearchVideosRequestInterface::VIDEO_TYPE_ALL);
$this->assertEquals("animation", SearchVideosRequestInterface::VIDEO_TYPE_ANIMATION);
Expand Down
2 changes: 1 addition & 1 deletion tests/Exception/APIExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class APIExceptionTest extends AbstractTestCase {
*
* @return void
*/
public function testConstruct() {
public function test__construct() {

// Set an Exception mock.
$throwable = new Exception;
Expand Down
2 changes: 1 addition & 1 deletion tests/Exception/AbstractExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AbstractExceptionTest extends AbstractTestCase {
*
* @return void
*/
public function testConstruct() {
public function test__construct() {

// Set an Exception mock.
$throwable = new Exception("throwable");
Expand Down
44 changes: 22 additions & 22 deletions tests/Model/AbstractHitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,6 @@
*/
class AbstractHitTest extends AbstractTestCase {

/**
* Tests the __construct() method.
*
* @return void
*/
public function testConstruct() {

$obj = new TestHit();

$this->assertNull($obj->getComments());
$this->assertNull($obj->getDownloads());
$this->assertNull($obj->getFavorites());
$this->assertNull($obj->getLikes());
$this->assertNull($obj->getPageURL());
$this->assertNull($obj->getTags());
$this->assertNull($obj->getType());
$this->assertNull($obj->getUser());
$this->assertNull($obj->getUserId());
$this->assertNull($obj->getUserImageURL());
$this->assertNull($obj->getViews());
}

/**
* Tests the setComments() method.
*
Expand Down Expand Up @@ -199,4 +177,26 @@ public function testSetViews() {
$obj->setViews(1);
$this->assertEquals(1, $obj->getViews());
}

/**
* Tests the __construct() method.
*
* @return void
*/
public function test__construct() {

$obj = new TestHit();

$this->assertNull($obj->getComments());
$this->assertNull($obj->getDownloads());
$this->assertNull($obj->getFavorites());
$this->assertNull($obj->getLikes());
$this->assertNull($obj->getPageURL());
$this->assertNull($obj->getTags());
$this->assertNull($obj->getType());
$this->assertNull($obj->getUser());
$this->assertNull($obj->getUserId());
$this->assertNull($obj->getUserImageURL());
$this->assertNull($obj->getViews());
}
}
46 changes: 23 additions & 23 deletions tests/Model/AbstractRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,6 @@
*/
class AbstractRequestTest extends AbstractTestCase {

/**
* Tests the __construct() method.
*
* @return void
*/
public function testConstruct() {

$obj = new TestRequest();

$this->assertNull($obj->getCategory());
$this->assertFalse($obj->getEditorsChoice());
$this->assertNull($obj->getId());
$this->assertEquals(AbstractRequest::LANG_EN, $obj->getLang());
$this->assertEquals(0, $obj->getMinHeight());
$this->assertEquals(0, $obj->getMinWidth());
$this->assertEquals(AbstractRequest::ORDER_POPULAR, $obj->getOrder());
$this->assertEquals(1, $obj->getPage());
$this->assertEquals(AbstractRequest::PER_PAGE_DEFAULT, $obj->getPerPage());
$this->assertFalse($obj->getPretty());
$this->assertNull($obj->getQ());
$this->assertFalse($obj->getSafeSearch());
}

/**
* Tests the enumLang() method.
*
Expand Down Expand Up @@ -343,4 +320,27 @@ public function testSetSafeSearch() {
$obj->setSafeSearch(true);
$this->assertTrue($obj->getSafeSearch());
}

/**
* Tests the __construct() method.
*
* @return void
*/
public function test__construct() {

$obj = new TestRequest();

$this->assertNull($obj->getCategory());
$this->assertFalse($obj->getEditorsChoice());
$this->assertNull($obj->getId());
$this->assertEquals(AbstractRequest::LANG_EN, $obj->getLang());
$this->assertEquals(0, $obj->getMinHeight());
$this->assertEquals(0, $obj->getMinWidth());
$this->assertEquals(AbstractRequest::ORDER_POPULAR, $obj->getOrder());
$this->assertEquals(1, $obj->getPage());
$this->assertEquals(AbstractRequest::PER_PAGE_DEFAULT, $obj->getPerPage());
$this->assertFalse($obj->getPretty());
$this->assertNull($obj->getQ());
$this->assertFalse($obj->getSafeSearch());
}
}
36 changes: 18 additions & 18 deletions tests/Model/AbstractResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,6 @@ public function testAddHit() {
$this->assertSame($hit, $obj->getHits()[0]);
}

/**
* Tests the __construct() method.
*
* @return void
*/
public function testConstruct() {

$obj = new TestResponse();

$this->assertCount(0, $obj->getHits());
$this->assertNull($obj->getLimit());
$this->assertNull($obj->getRawResponse());
$this->assertNull($obj->getRemaining());
$this->assertNull($obj->getReset());
$this->assertNull($obj->getTotal());
$this->assertNull($obj->getTotalHits());
}

/**
* Tests the setRawResponse() method.
*
Expand Down Expand Up @@ -96,4 +78,22 @@ public function testSetTotalHits() {
$obj->setTotalHits(1);
$this->assertEquals(1, $obj->getTotalHits());
}

/**
* Tests the __construct() method.
*
* @return void
*/
public function test__construct() {

$obj = new TestResponse();

$this->assertCount(0, $obj->getHits());
$this->assertNull($obj->getLimit());
$this->assertNull($obj->getRawResponse());
$this->assertNull($obj->getRemaining());
$this->assertNull($obj->getReset());
$this->assertNull($obj->getTotal());
$this->assertNull($obj->getTotalHits());
}
}
46 changes: 23 additions & 23 deletions tests/Model/ImageHitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,6 @@
*/
class ImageHitTest extends AbstractTestCase {

/**
* Tests the __construct() method.
*
* @return void
*/
public function testConstruct() {

$obj = new ImageHit();

$this->assertNull($obj->getFullHDURL());
$this->assertNull($obj->getImageHeight());
$this->assertNull($obj->getImageSize());
$this->assertNull($obj->getImageURL());
$this->assertNull($obj->getImageWidth());
$this->assertNull($obj->getLargeImageURL());
$this->assertNull($obj->getPreviewHeight());
$this->assertNull($obj->getPreviewURL());
$this->assertNull($obj->getPreviewWidth());
$this->assertNull($obj->getWebFormatHeight());
$this->assertNull($obj->getWebFormatURL());
$this->assertNull($obj->getWebFormatWidth());
}

/**
* Tests the setFullHDURL() method.
*
Expand Down Expand Up @@ -200,4 +177,27 @@ public function testSetWebFormatWidth() {
$obj->setWebFormatWidth(1);
$this->assertEquals(1, $obj->getWebFormatWidth());
}

/**
* Tests the __construct() method.
*
* @return void
*/
public function test__construct() {

$obj = new ImageHit();

$this->assertNull($obj->getFullHDURL());
$this->assertNull($obj->getImageHeight());
$this->assertNull($obj->getImageSize());
$this->assertNull($obj->getImageURL());
$this->assertNull($obj->getImageWidth());
$this->assertNull($obj->getLargeImageURL());
$this->assertNull($obj->getPreviewHeight());
$this->assertNull($obj->getPreviewURL());
$this->assertNull($obj->getPreviewWidth());
$this->assertNull($obj->getWebFormatHeight());
$this->assertNull($obj->getWebFormatURL());
$this->assertNull($obj->getWebFormatWidth());
}
}
28 changes: 14 additions & 14 deletions tests/Model/RateLimitTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,6 @@
*/
class RateLimitTraitTest extends AbstractTestCase {

/**
* Tests the __construct() method.
*
* @return void
*/
public function testConstruct() {

$obj = new TestRateLimitTrait();

$this->assertNull($obj->getLimit());
$this->assertNull($obj->getRemaining());
$this->assertNull($obj->getReset());
}

/**
* Tests the setLimit() method.
*
Expand Down Expand Up @@ -80,4 +66,18 @@ public function testSetReset() {
$obj->setReset($reset);
$this->assertSame($reset, $obj->getReset());
}

/**
* Tests the __construct() method.
*
* @return void
*/
public function test__construct() {

$obj = new TestRateLimitTrait();

$this->assertNull($obj->getLimit());
$this->assertNull($obj->getRemaining());
$this->assertNull($obj->getReset());
}
}
Loading

0 comments on commit f047cf0

Please sign in to comment.