Skip to content

Commit

Permalink
add handle_response test to HTTPTest.php
Browse files Browse the repository at this point in the history
  • Loading branch information
amalfra committed Aug 24, 2022
1 parent 5b59350 commit aad8b10
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/HTTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use \InvalidArgumentException;
use WpOrg\Requests\Requests;
use Amalfra\GiantBomb\Exceptions\HTTPException as HTTPException;
use Amalfra\GiantBomb\Exceptions\HTTPException;

/**
* Class HTTP
Expand Down
46 changes: 46 additions & 0 deletions tests/GiantBomb/Tests/HTTPTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use \ReflectionMethod;
use \InvalidArgumentException;
use Amalfra\GiantBomb\HTTP;
use Amalfra\GiantBomb\Exceptions\HTTPException;

class HTTPTest extends TestCase {
private function getProtectedProperty($object, $property, $args = []) {
Expand Down Expand Up @@ -70,6 +71,20 @@ public function validatetf_to_string() {
}
}

/** @test */
public function validatetf_to_stringValueFalse() {
$api = new HTTP();
$var = false;

$this->getProtectedProperty($api, 'tf_to_string', [&$var, &$var]);

if (gettype($var) === 'string') {
$this->assertTrue(true);
} else {
$this->fail();
}
}

// tf_to_string() tests end

// inject() tests start
Expand All @@ -90,4 +105,35 @@ public function validateInject() {
}

// inject() tests end

// handle_response() tests start

/** @test */
public function validateHandle_response() {
$api = new HTTP();
$mock = $this->getMockBuilder('Response')
->disableOriginalConstructor()
->getMock();
$mock->status_code = 204;

$this->assertTrue($this->getProtectedProperty($api, 'handle_response', [&$mock]));
}

/** @test */
public function validateHandle_responseInvalid() {
$api = new HTTP();
$mock = $this->getMockBuilder('Response')
->disableOriginalConstructor()
->getMock();
$mock->status_code = 400;
$mock->body = 'abcd';

try {
$this->assertTrue($this->getProtectedProperty($api, 'handle_response', [&$mock]));
} catch (HTTPException $e) {
$this->assertStringContainsStringIgnoringCase('An HTTP error with status code', $e->getMessage());
}
}

// handle_response() tests end
}

0 comments on commit aad8b10

Please sign in to comment.