diff --git a/src/Client.php b/src/Client.php index 93147e9..b9f7e26 100644 --- a/src/Client.php +++ b/src/Client.php @@ -34,7 +34,7 @@ class Client { */ public function __construct( $token = '' ) { $config = Configuration::getDefaultConfiguration()->setUsername( 'WordPress' )->setPassword( - $token ?: Helpers::get_settings()[ 'api_token' ] + $token )->setHost( Helpers::get_hosted_domain_url() ); $this->api_instance = new DefaultApi( new GuzzleClient(), $config ); } diff --git a/src/ClientFactory.php b/src/ClientFactory.php index ab33cb3..f52c1b4 100644 --- a/src/ClientFactory.php +++ b/src/ClientFactory.php @@ -34,6 +34,14 @@ public function build() { return false; // @codeCoverageIgnore } + if ( ! $this->token ) { + $this->token = Helpers::get_settings()[ 'api_token' ]; + } + + if ( ! $this->token ) { + return false; + } + return new Client( $this->token ); } diff --git a/tests/unit/ClientFactoryTest.php b/tests/unit/ClientFactoryTest.php index 06d1211..7448604 100644 --- a/tests/unit/ClientFactoryTest.php +++ b/tests/unit/ClientFactoryTest.php @@ -17,6 +17,11 @@ public function testBuild() { $clientFactory = new ClientFactory(); $client = $clientFactory->build(); + $this->assertFalse( $client ); + + $clientFactory = new ClientFactory( 'test' ); + $client = $clientFactory->build(); + $this->assertInstanceOf( Client::class, $client ); } }