Skip to content

Commit

Permalink
Added the first test
Browse files Browse the repository at this point in the history
  • Loading branch information
Rick in t Veld committed Apr 12, 2024
1 parent f72a817 commit ac26d1d
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 4 deletions.
3 changes: 2 additions & 1 deletion phpstan.dist.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ parameters:
- bin/
- config/
- public/
- src/
- src/
- tests/
3 changes: 2 additions & 1 deletion src/Client/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Client;

use App\Mediator\JsonResponseMediator;
use Symfony\Component\HttpClient\HttpOptions;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;
Expand All @@ -23,7 +24,7 @@ public function get(string $uri): array
/** @var ResponseInterface $response */
$response = $this->client->request('GET', $uri);

return json_decode($response->getContent(), true);
return JsonResponseMediator::content($response);
}

abstract public function getBaseUri(): string;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions src/Mediator/JsonResponseMediator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace App\Mediator;

use Symfony\Contracts\HttpClient\ResponseInterface;

final class JsonResponseMediator
{
/**
* @return array<mixed>
*/
public static function content(ResponseInterface $response): array
{
return json_decode($response->getContent(), true);
}
}
17 changes: 15 additions & 2 deletions tests/Action/Account/FetchAccountsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,25 @@ public function testAction(): void
$accountRepository->expects($this->once())->method('findAll')->willReturn([$account]);

$eventBus = $this->getMockBuilder(EventDispatcherInterface::class)->disableOriginalConstructor()->getMock();
$eventBus->expects($this->once())->method('dispatch')->with(new CreateAccountEvent(['accountId' => 1]));
$eventBus->expects($this->once())->method('dispatch')->with(new UpdateAccountEvent($account, ['accountId' => 1]));
$eventBus->expects($this->exactly(3))->method('dispatch')->with($this->callback(function ($object) {
if ($object instanceof CreateAccountEvent) {
return true;
}
if ($object instanceof UpdateAccountEvent) {
return true;
}

return false;
}));

$myFxBookRepository = $this->getMockBuilder(MyFxBookRepositoryInterface::class)->disableOriginalConstructor()->getMock();
$myFxBookRepository->expects($this->once())->method('accounts')->with('123abc#')->willReturn([['accountId' => 1], ['accountId' => 2]]);

/**
* @var AccountRepository $accountRepository
* @var EventDispatcherInterface $eventBus
* @var MyFxBookRepositoryInterface $myFxBookRepository
*/
$fetchAccounts = new FetchAccounts($accountRepository, $eventBus, $myFxBookRepository);

$aggregator = new AggregateRoot();
Expand Down

0 comments on commit ac26d1d

Please sign in to comment.