Skip to content

Commit

Permalink
BRAIN-23 - fix mutations
Browse files Browse the repository at this point in the history
  • Loading branch information
lernhart committed Jan 22, 2024
1 parent f20acc9 commit e36b5d0
Show file tree
Hide file tree
Showing 8 changed files with 260 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
- package.json
- .github/workflows/js.yml
branches:
- main
- trunk

jobs:
eslint:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
- composer.json
- .github/workflows/php.yml
branches:
- main
- trunk
workflow_dispatch:

jobs:
Expand Down Expand Up @@ -73,6 +73,6 @@ jobs:
- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest
- name: Run Infection
run: composer infection
run: composer infection -- --min-msi=95
env:
INFECTION_DASHBOARD_API_KEY: ${{ secrets.INFECTION_DASHBOARD_API_KEY }}
79 changes: 39 additions & 40 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions config/services/braintree.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,19 @@
<service id="Swag\Braintree\Framework\Serializer\EntityNormalizer">
<argument type="service" id="serializer.normalizer.object"/>
</service>

<service id="guzzle.client.report" class="GuzzleHttp\Client">
<factory class="Swag\Braintree\Braintree\Util\ReportClientFactory" method="createClient"/>
<argument type="collection">
<argument key="base_uri">https://api.shopware.com</argument>
</argument>
</service>

<service id="Swag\Braintree\Braintree\Util\ReportService">
<argument type="service" id="doctrine.orm.entity_manager"/>
<argument type="service" id="Swag\Braintree\Repository\TransactionReportRepository"/>
<argument>%env(default::REPORT_IDENTIFIER)%</argument>
<argument type="service" id="guzzle.client.report"/>
</service>
</services>
</container>
16 changes: 16 additions & 0 deletions src/Braintree/Util/ReportClientFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php declare(strict_types=1);

namespace Swag\Braintree\Braintree\Util;

use GuzzleHttp\Client;

class ReportClientFactory
{
/**
* @param array<string, mixed> $config
*/
public static function createClient(array $config = []): Client
{
return new Client($config);
}
}
8 changes: 3 additions & 5 deletions src/Braintree/Util/ReportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@
use GuzzleHttp\Promise\Utils;
use GuzzleHttp\RequestOptions;
use Swag\Braintree\Repository\TransactionReportRepository;
use Symfony\Component\DependencyInjection\Attribute\Autowire;

class ReportService
{
public function __construct(
private readonly EntityManagerInterface $em,
private readonly TransactionReportRepository $transactionReportRepository,
#[Autowire(env: 'REPORT_IDENTIFIER')]
private readonly string $apiIdentifier = '',
private readonly Client $client = new Client(['base_uri' => 'https://api.shopware.com']),
private readonly ?string $apiIdentifier,
private readonly Client $client,
) {
}

Expand All @@ -38,7 +36,7 @@ public function sendTurnoverReports(): array
$requests = [];
foreach ($reports as $currency => $turnover) {
$body = [
'identifier' => $this->apiIdentifier,
'identifier' => $this->apiIdentifier ?? '',
'reportDate' => (new \DateTime())->format(\DateTimeInterface::ATOM),
'reportDataKeys' => ['turnover' => $turnover],
'currency' => $currency,
Expand Down
39 changes: 39 additions & 0 deletions tests/unit/Braintree/Util/ReportClientFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php declare(strict_types=1);

namespace Swag\Braintree\Tests\Unit\Braintree\Util;

use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\UriInterface;
use Swag\Braintree\Braintree\Util\ReportClientFactory;

#[CoversClass(ReportClientFactory::class)]
class ReportClientFactoryTest extends TestCase
{
public function testFactory(): void
{
$clientHistory = [];
$clientHandler = new MockHandler();
$clientHandler->append(new Response());
$clientHandlerStack = HandlerStack::create($clientHandler);
$clientHandlerStack->push(Middleware::history($clientHistory));

$client = ReportClientFactory::createClient(['base_uri' => 'https://example.com', 'handler' => $clientHandlerStack]);
$client->get('/foo/bar');

static::assertCount(1, $clientHistory);

static::assertArrayHasKey('request', $clientHistory[0]);
static::assertInstanceOf(Request::class, $clientHistory[0]['request']);

$uri = $clientHistory[0]['request']->getUri();

static::assertInstanceOf(UriInterface::class, $uri);
static::assertSame('https://example.com/foo/bar', (string) $uri);
}
}
Loading

0 comments on commit e36b5d0

Please sign in to comment.