From 94875105576c001148056a018024e17671548484 Mon Sep 17 00:00:00 2001 From: Grzegorz Rola <grola@seostudio.pl> Date: Thu, 31 Jan 2019 15:21:52 +0100 Subject: [PATCH] First tests --- tests/unit/Curl/TestCurlClient.php | 50 ++++++++++++++++++++++++++++ tests/unit/TestHttpClientFactory.php | 15 +++++++++ 2 files changed, 65 insertions(+) create mode 100644 tests/unit/Curl/TestCurlClient.php diff --git a/tests/unit/Curl/TestCurlClient.php b/tests/unit/Curl/TestCurlClient.php new file mode 100644 index 0000000..c95b896 --- /dev/null +++ b/tests/unit/Curl/TestCurlClient.php @@ -0,0 +1,50 @@ +<?php + +class TestCurlClient extends \PHPUnit\Framework\TestCase +{ + + /** + * Test get method. + */ + public function testGet() + { + $client = new \WPDesk\HttpClient\Curl\CurlClient(); + $response = $client->get('https://www.google.com', '', array(), 15); + $this->assertInstanceOf(\WPDesk\HttpClient\HttpClientResponse::class, $response); + $this->assertEquals(200, $response->getResponseCode()); + } + + /** + * Test post method. + */ + public function testPost() + { + $client = new \WPDesk\HttpClient\Curl\CurlClient(); + $response = $client->post('https://www.google.com', '', array(), 15); + $this->assertInstanceOf(\WPDesk\HttpClient\HttpClientResponse::class, $response); + $this->assertEquals(405, $response->getResponseCode()); + } + + /** + * Test put method. + */ + public function testPut() + { + $client = new \WPDesk\HttpClient\Curl\CurlClient(); + $response = $client->put('https://www.google.com', '', array(), 15); + $this->assertInstanceOf(\WPDesk\HttpClient\HttpClientResponse::class, $response); + $this->assertEquals(405, $response->getResponseCode()); + } + + /** + * Test delete method. + */ + public function testDelete() + { + $client = new \WPDesk\HttpClient\Curl\CurlClient(); + $response = $client->put('https://www.google.com', '', array(), 15); + $this->assertInstanceOf(\WPDesk\HttpClient\HttpClientResponse::class, $response); + $this->assertEquals(405, $response->getResponseCode()); + } + +} \ No newline at end of file diff --git a/tests/unit/TestHttpClientFactory.php b/tests/unit/TestHttpClientFactory.php index 1b835f8..68efad4 100644 --- a/tests/unit/TestHttpClientFactory.php +++ b/tests/unit/TestHttpClientFactory.php @@ -3,4 +3,19 @@ class TestHttpClientFactory extends \PHPUnit\Framework\TestCase { + /** + * Test createClient method. + */ + public function testCreateClient() + { + $options = Mockery::mock(\WPDesk\HttpClient\HttpClientOptions::class); + $options->shouldReceive('getHttpClientClass') + ->withAnyArgs() + ->andReturn(\WPDesk\HttpClient\Curl\CurlClient::class); + $factory = new \WPDesk\HttpClient\HttpClientFactory(); + $client = $factory->createClient($options); + $this->assertInstanceOf(\WPDesk\HttpClient\Curl\CurlClient::class, $client); + } + + } \ No newline at end of file -- GitLab