From ab0c606a15f8cef5ee40a20fbeb571f8d9c66cf7 Mon Sep 17 00:00:00 2001
From: Grzegorz Rola <grola@seostudio.pl>
Date: Thu, 31 Jan 2019 17:26:56 +0100
Subject: [PATCH] Some tests

---
 tests/unit/Client/TestClientFactory.php | 67 +++++++++++++++++++++++++
 1 file changed, 67 insertions(+)
 create mode 100644 tests/unit/Client/TestClientFactory.php

diff --git a/tests/unit/Client/TestClientFactory.php b/tests/unit/Client/TestClientFactory.php
new file mode 100644
index 0000000..83dc5a9
--- /dev/null
+++ b/tests/unit/Client/TestClientFactory.php
@@ -0,0 +1,67 @@
+<?php
+
+use WPDesk\ApiClient\Client\ClientFactory;
+
+class TestClientFactory extends \PHPUnit\Framework\TestCase
+{
+
+    /**
+     * Prepare client options.
+     *
+     * @param bool $isCachedClient
+     *
+     * @return \Mockery\MockInterface|\WPDesk\ApiClient\Client\ApiClientOptions
+     */
+    private function prepareOptions($isCachedClient = false)
+    {
+        $options = Mockery::mock(\WPDesk\ApiClient\Client\ApiClientOptions::class);
+        $options->shouldReceive('getHttpClientClass')
+                ->withAnyArgs()
+                ->andReturn(\WPDesk\HttpClient\Curl\CurlClient::class);
+
+        $options->shouldReceive('getSerializerClass')
+                ->withAnyArgs()
+                ->andReturn(\WPDesk\ApiClient\Serializer\JsonSerializer::class);
+
+        $options->shouldReceive('getLogger')
+                ->withAnyArgs()
+                ->andReturn(new \Psr\Log\NullLogger());
+
+        $options->shouldReceive('getApiUrl')
+                ->withAnyArgs()
+                ->andReturn('https://app.flexibleshipping.com/api/v1');
+
+        $options->shouldReceive('getDefaultRequestHeaders')
+                ->withAnyArgs()
+                ->andReturn(array());
+
+        $options->shouldReceive('isCachedClient')
+                ->withAnyArgs()
+                ->andReturn($isCachedClient);
+
+        return $options;
+    }
+
+    /**
+     * Test createClient method.
+     */
+    public function testCreateClient()
+    {
+
+        $clientFactory = new ClientFactory();
+        $client = $clientFactory->createClient($this->prepareOptions());
+        $this->assertInstanceOf(\WPDesk\ApiClient\Client\ClientImplementation::class, $client);
+    }
+
+    /**
+     * Test createClient method.
+     */
+    public function testCreateClientCached()
+    {
+
+        $clientFactory = new ClientFactory();
+        $client = $clientFactory->createClient($this->prepareOptions(true));
+        $this->assertInstanceOf(\WPDesk\ApiClient\Client\CachedClient::class, $client);
+    }
+
+}
\ No newline at end of file
-- 
GitLab