Skip to content

Commit

Permalink
feat: move logger and client to constructor in factory
Browse files Browse the repository at this point in the history
  • Loading branch information
shyim committed May 11, 2023
1 parent 3197619 commit c378f88
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions src/HttpClient/ClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@

class ClientFactory
{
public function __construct(private readonly CacheInterface $cache = new NullCache())
{
public function __construct(
private readonly CacheInterface $cache = new NullCache(),
private readonly ClientInterface $client = new Psr18Client(),
private readonly LoggerInterface $logger = new NullLogger()
) {
}

public function createClient(ShopInterface $shop, ClientInterface $client = new Psr18Client(), LoggerInterface $logger = new NullLogger()): ClientInterface
public function createClient(ShopInterface $shop): ClientInterface
{
return new AuthenticatedClient(new LoggerClient($client, $logger), $shop, $this->cache);
return new AuthenticatedClient(new LoggerClient($this->client, $this->logger), $shop, $this->cache);
}
}
4 changes: 2 additions & 2 deletions tests/HttpClient/ClientFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public function testFactoryOwnClient(): void
->method('sendRequest')
->willReturn(new Response(200, [], '{"access_token": "a", "expires_in": 3600}'));

$factory = new ClientFactory();
$client = $factory->createClient(new MockShop('shop-id', 'shop-secret', ''), $testClient);
$factory = new ClientFactory(new NullCache(), $testClient);
$client = $factory->createClient(new MockShop('shop-id', 'shop-secret', ''));

$client->sendRequest(new Request('GET', 'https://example.com'));
}
Expand Down

0 comments on commit c378f88

Please sign in to comment.