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 9f97e42 commit 712fb26
Show file tree
Hide file tree
Showing 28 changed files with 231 additions and 231 deletions.
22 changes: 11 additions & 11 deletions src/Serializer/ResponseDeserializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,18 @@ protected static function deserializeBreach(array $rawResponse) {
$modifiedDate = DateTime::createFromFormat(ResponseInterface::DATETIME_FORMAT_MODIFIED, ArrayHelper::get($rawResponse, "ModifiedDate", ""), new DateTimeZone("UTC"));

$model = new Breach();
$model->setAddedDate(false !== $addedDate ? $addedDate : null);
$model->setBreachDate(false !== $breachDate ? $breachDate : null);
$model->setDescription(ArrayHelper::get($rawResponse, "Description"));
$model->setName(ArrayHelper::get($rawResponse, "Name"));
$model->setTitle(ArrayHelper::get($rawResponse, "Title"));
$model->setDomain(ArrayHelper::get($rawResponse, "Domain"));
$model->setBreachDate(false !== $breachDate ? $breachDate : null);
$model->setAddedDate(false !== $addedDate ? $addedDate : null);
$model->setModifiedDate(false !== $modifiedDate ? $modifiedDate : null);
$model->setName(ArrayHelper::get($rawResponse, "Name"));
$model->setPwnCount(ArrayHelper::get($rawResponse, "PwnCount", 0));
$model->setRetired(ArrayHelper::get($rawResponse, "IsRetired", false));
$model->setDescription(ArrayHelper::get($rawResponse, "Description"));
$model->setVerified(ArrayHelper::get($rawResponse, "IsVerified", false));
$model->setSensitive(ArrayHelper::get($rawResponse, "IsSensitive", false));
$model->setRetired(ArrayHelper::get($rawResponse, "IsRetired", false));
$model->setSpamList(ArrayHelper::get($rawResponse, "IsSpamList", false));
$model->setTitle(ArrayHelper::get($rawResponse, "Title"));
$model->setVerified(ArrayHelper::get($rawResponse, "IsVerified", false));

foreach (ArrayHelper::get($rawResponse, "DataClasses", []) as $current) {
$model->addDataClass(static::deserializeDataClass($current));
Expand Down Expand Up @@ -153,11 +153,11 @@ protected static function deserializePaste(array $rawResponse) {
$date = DateTime::createFromFormat(ResponseInterface::DATETIME_FORMAT_DATE, ArrayHelper::get($rawResponse, "Date", ""), new DateTimeZone("UTC"));

$model = new Paste();
$model->setDate(false !== $date ? $date : null);
$model->setEmailCount(ArrayHelper::get($rawResponse, "EmailCount", 0));
$model->setId(ArrayHelper::get($rawResponse, "Id"));
$model->setSource(ArrayHelper::get($rawResponse, "Source"));
$model->setId(ArrayHelper::get($rawResponse, "Id"));
$model->setTitle(ArrayHelper::get($rawResponse, "Title"));
$model->setDate(false !== $date ? $date : null);
$model->setEmailCount(ArrayHelper::get($rawResponse, "EmailCount", 0));

return $model;
}
Expand Down Expand Up @@ -199,8 +199,8 @@ protected static function deserializeRange($rawResponse) {
}

$model = new Range();
$model->setCount(intval($response[1]));
$model->setHash(trim($response[0]));
$model->setCount(intval($response[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(1500, RequestInterface::RATE_LIMITING);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/API/ResponseInterfaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ResponseInterfaceTest extends AbstractTestCase {
*
* @return void
*/
public function testConstruct() {
public function test__construct() {

$this->assertEquals("Y-m-d\TH:i\Z", ResponseInterface::DATETIME_FORMAT_ADDED);
$this->assertEquals("Y-m-d", ResponseInterface::DATETIME_FORMAT_BREACH);
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
14 changes: 7 additions & 7 deletions tests/Model/AbstractResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,27 @@
class AbstractResponseTest extends AbstractTestCase {

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

$obj = new TestResponse();

$this->assertNull($obj->getRawResponse());
$obj->setRawResponse("rawResponse");
$this->assertEquals("rawResponse", $obj->getRawResponse());
}

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

$obj = new TestResponse();

$obj->setRawResponse("rawResponse");
$this->assertEquals("rawResponse", $obj->getRawResponse());
$this->assertNull($obj->getRawResponse());
}
}
46 changes: 23 additions & 23 deletions tests/Model/BreachTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,6 @@
*/
class BreachTest extends AbstractTestCase {

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

$obj = new Breach();

$this->assertNull($obj->getAddedDate());
$this->assertNull($obj->getBreachDate());
$this->assertEquals([], $obj->getDataClasses());
$this->assertNull($obj->getDomain());
$this->assertNull($obj->getAddedDate());
$this->assertNull($obj->getName());
$this->assertEquals(0, $obj->getPwnCount());
$this->assertFalse($obj->getRetired());
$this->assertFalse($obj->getSensitive());
$this->assertFalse($obj->getSpamList());
$this->assertNull($obj->getTitle());
$this->assertFalse($obj->getVerified());
}

/**
* Tests the setAddedDate() method.
*
Expand Down Expand Up @@ -211,4 +188,27 @@ public function testSetVerified() {
$obj->setVerified(true);
$this->assertTrue($obj->getVerified());
}

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

$obj = new Breach();

$this->assertNull($obj->getAddedDate());
$this->assertNull($obj->getBreachDate());
$this->assertEquals([], $obj->getDataClasses());
$this->assertNull($obj->getDomain());
$this->assertNull($obj->getAddedDate());
$this->assertNull($obj->getName());
$this->assertEquals(0, $obj->getPwnCount());
$this->assertFalse($obj->getRetired());
$this->assertFalse($obj->getSensitive());
$this->assertFalse($obj->getSpamList());
$this->assertNull($obj->getTitle());
$this->assertFalse($obj->getVerified());
}
}
2 changes: 1 addition & 1 deletion tests/Model/DataClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class DataClassTest extends AbstractTestCase {
*
* @return void
*/
public function testConstruct() {
public function test__construct() {

$obj = new DataClass();

Expand Down
32 changes: 16 additions & 16 deletions tests/Model/PasteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,6 @@
*/
class PasteTest extends AbstractTestCase {

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

$obj = new Paste();

$this->assertNull($obj->getDate());
$this->assertEquals(0, $obj->getEmailCount());
$this->assertNull($obj->getId());
$this->assertNull($obj->getSource());
$this->assertNull($obj->getTitle());
}

/**
* Tests the setDate() method.
*
Expand Down Expand Up @@ -107,4 +91,20 @@ public function testSetTitle() {
$obj->setTitle("title");
$this->assertEquals("title", $obj->getTitle());
}

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

$obj = new Paste();

$this->assertNull($obj->getDate());
$this->assertEquals(0, $obj->getEmailCount());
$this->assertNull($obj->getId());
$this->assertNull($obj->getSource());
$this->assertNull($obj->getTitle());
}
}
24 changes: 12 additions & 12 deletions tests/Model/RangeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,41 +23,41 @@
class RangeTest extends AbstractTestCase {

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

$obj = new Range();

$this->assertEquals(0, $obj->getCount());
$this->assertNull($obj->getHash());
$obj->setCount(1);
$this->assertEquals(1, $obj->getCount());
}

/**
* Tests the setCount() method.
* Tests the setPrefix() method.
*
* @return void
*/
public function testSetCount() {
public function testSetPrefix() {

$obj = new Range();

$obj->setCount(1);
$this->assertEquals(1, $obj->getCount());
$obj->setPrefix("prefix");
$this->assertEquals("prefix", $obj->getPrefix());
}

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

$obj = new Range();

$obj->setPrefix("prefix");
$this->assertEquals("prefix", $obj->getPrefix());
$this->assertEquals(0, $obj->getCount());
$this->assertNull($obj->getHash());
}
}
28 changes: 14 additions & 14 deletions tests/Model/Request/BreachRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,34 @@
class BreachRequestTest extends AbstractTestCase {

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

$this->assertEquals("/breach/{name}", BreachRequest::BREACH_RESOURCE_PATH);
public function testGetSubstituteValue() {

$obj = new BreachRequest();

$this->assertNull($obj->getName());
$this->assertEquals(BreachRequest::BREACH_RESOURCE_PATH, $obj->getResourcePath());

$this->assertInstanceOf(SubstituteRequestInterface::class, $obj);
$this->assertEquals("{name}", $obj->getSubstituteName());
$this->assertNull($obj->getSubstituteValue());
$obj->setName("name");
$this->assertEquals("name", $obj->getSubstituteValue());
}

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

$this->assertEquals("/breach/{name}", BreachRequest::BREACH_RESOURCE_PATH);

$obj = new BreachRequest();

$obj->setName("name");
$this->assertEquals("name", $obj->getSubstituteValue());
$this->assertNull($obj->getName());
$this->assertEquals(BreachRequest::BREACH_RESOURCE_PATH, $obj->getResourcePath());

$this->assertInstanceOf(SubstituteRequestInterface::class, $obj);
$this->assertEquals("{name}", $obj->getSubstituteName());
$this->assertNull($obj->getSubstituteValue());
}
}
44 changes: 22 additions & 22 deletions tests/Model/Request/BreachedAccountRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,6 @@
*/
class BreachedAccountRequestTest extends AbstractTestCase {

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

$this->assertEquals("/breachedaccount/{account}", BreachedAccountRequest::BREACHED_ACCOUNT_RESOURCE_PATH);

$obj = new BreachedAccountRequest();

$this->assertNull($obj->getAccount());
$this->assertNull($obj->getDomain());
$this->assertNull($obj->getIncludeUnverified());
$this->assertEquals(BreachedAccountRequest::BREACHED_ACCOUNT_RESOURCE_PATH, $obj->getResourcePath());
$this->assertNull($obj->getTruncateResponse());

$this->assertInstanceOf(SubstituteRequestInterface::class, $obj);
$this->assertEquals("{account}", $obj->getSubstituteName());
$this->assertNull($obj->getSubstituteValue());
}

/**
* Tests the getSubstituteValue() method.
*
Expand Down Expand Up @@ -83,4 +61,26 @@ public function testSetTruncateResponse() {
$obj->setTruncateResponse(true);
$this->assertTrue($obj->getTruncateResponse());
}

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

$this->assertEquals("/breachedaccount/{account}", BreachedAccountRequest::BREACHED_ACCOUNT_RESOURCE_PATH);

$obj = new BreachedAccountRequest();

$this->assertNull($obj->getAccount());
$this->assertNull($obj->getDomain());
$this->assertNull($obj->getIncludeUnverified());
$this->assertEquals(BreachedAccountRequest::BREACHED_ACCOUNT_RESOURCE_PATH, $obj->getResourcePath());
$this->assertNull($obj->getTruncateResponse());

$this->assertInstanceOf(SubstituteRequestInterface::class, $obj);
$this->assertEquals("{account}", $obj->getSubstituteName());
$this->assertNull($obj->getSubstituteValue());
}
}
Loading

0 comments on commit 712fb26

Please sign in to comment.