Skip to content
Snippets Groups Projects
Select Git revision
  • ddcc242a15a36c606e35c1747cd6a38a1736b426
  • master default protected
  • 1.2.3
  • 1.2.2
  • 1.2.1
  • 1.2.0
  • 1.1.0
  • 1.0.2
  • 1.0.1
  • 1.0
10 results

TestClientFactory.php

Blame
  • TestClientFactory.php 2.10 KiB
    <?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('getApiClientClass')
                    ->withAnyArgs()
                    ->andReturn(\WPDesk\ApiClient\Client\ClientImplementation::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);
        }