Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Amco;
- use Amco\Services\Restful\GuzzleClient;
- /**
- * Test cases for Amco\Services\Restful\GuzzleClient
- */
- class GuzzleClientTest extends \PHPUnit_Framework_TestCase
- {
- private $guzzleClient;
- public function setUp()
- {
- $this->guzzleClient = new GuzzleClient();
- }
- public function testClientConstruct()
- {
- $this->assertNotNull($this->guzzleClient->getClient());
- }
- public function testClientPost()
- {
- $response = $this->guzzleClient->post(
- "https://api.tbxnet.com/v2/UserServices/device",
- ["headers" => ["Authorization" => "IXP4RAI0w7ajTGTan7qlnY32r39BBb3x", "Content-Type" => "application/x-www-form-urlencoded", "Accept" => "application/json"]],
- ["form_params" => ["subscriberId" => "123456", "country" => "CO", "type" => "STB", "description" => "coship"]]
- );
- $this->assertNotNull($response);
- $this->assertArrayHasKey("statusCode", $response);
- $this->assertArrayHasKey("body", $response);
- $this->assertEquals(200, $response["statusCode"]);
- }
- public function testClientPostError()
- {
- $response = $this->guzzleClient->post(
- "https://api.tbxnet.com/v2/UserServices/device",
- ["headers" => ["Authorization" => "", "Content-Type" => "application/x-www-form-urlencoded", "Accept" => "application/json"]],
- ["form_params" => ["subscriberId" => "123456", "country" => "CO", "type" => "STB", "description" => "coship"]]
- );
- $this->assertNotNull($response);
- $this->assertArrayHasKey("statusCode", $response);
- $this->assertArrayHasKey("body", $response);
- $this->assertEquals(400, $response["statusCode"]);
- }
- public function testClientPostNoUrl()
- {
- $response = $this->guzzleClient->post(
- null,
- ["headers" => ["Authorization" => "", "Content-Type" => "application/x-www-form-urlencoded", "Accept" => "application/json"]],
- ["form_params" => ["subscriberId" => "123456", "country" => "CO", "type" => "STB", "description" => "coship"]]
- );
- $this->assertNotNull($response);
- $this->assertArrayHasKey("statusCode", $response);
- $this->assertArrayHasKey("body", $response);
- $this->assertEquals(500, $response["statusCode"]);
- }
- public function testClientPostBadUrl()
- {
- $response = $this->guzzleClient->post(
- "",
- ["headers" => ["Authorization" => "", "Content-Type" => "application/x-www-form-urlencoded", "Accept" => "application/json"]],
- ["form_params" => ["subscriberId" => "123456", "country" => "CO", "type" => "STB", "description" => "coship"]]
- );
- $this->assertNotNull($response);
- $this->assertArrayHasKey("statusCode", $response);
- $this->assertArrayHasKey("body", $response);
- $this->assertEquals(500, $response["statusCode"]);
- }
- public function testClientPut()
- {
- $response = $this->guzzleClient->put(
- "https://jsonplaceholder.typicode.com/posts/1",
- ["headers" => ["Authorization" => "IXP439BBb3x", "Accept" => "application/json"]],
- ["json" => ["id" => "1", "title" => "foo", "body" => "bar", "userId" => "1"]]
- );
- $this->assertNotNull($response);
- $this->assertArrayHasKey("statusCode", $response);
- $this->assertArrayHasKey("body", $response);
- $this->assertEquals(200, $response["statusCode"]);
- }
- public function testClientPutError()
- {
- $response = $this->guzzleClient->put(
- "https://jsonplaceholder.typicode.com/posts/non-existent-id",
- [],
- ["json" => ["id" => "1", "title" => "foo", "body" => "bar", "userId" => "1"]]
- );
- $this->assertNotNull($response);
- $this->assertArrayHasKey("statusCode", $response);
- $this->assertArrayHasKey("body", $response);
- $this->assertEquals(404, $response["statusCode"]);
- }
- public function testClientGet()
- {
- $response = $this->guzzleClient->get(
- "https://jsonplaceholder.typicode.com/posts",
- ["headers" => ["Authorization" => "IXP4RAI0w7ajTGTa", "Accept" => "application/json"]],
- ["query" => ["userId" => "1"]]
- );
- $this->assertNotNull($response);
- $this->assertArrayHasKey("statusCode", $response);
- $this->assertArrayHasKey("body", $response);
- $this->assertEquals(200, $response["statusCode"]);
- }
- public function testClientGetError()
- {
- $response = $this->guzzleClient->get(
- "https://jsonplaceholder.typicode.com/non-existent-url",
- ["headers" => ["Authorization" => "IXP4RAI0w7ajTGTa", "Accept" => "application/json"]],
- ["query" => ["userId" => "1"]]
- );
- $this->assertNotNull($response);
- $this->assertArrayHasKey("statusCode", $response);
- $this->assertArrayHasKey("body", $response);
- $this->assertEquals(404, $response["statusCode"]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement