SuperSeller3000/tests/Unit/Infrastructure/Order/CustomerResolverTest.php
Simon Kuehn a79791a972
Some checks are pending
CI / test (push) Waiting to run
style: apply CS Fixer formatting across codebase
Consistent brace style, spacing, and method expansion throughout
domain, infrastructure, and test files.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-19 10:56:37 +00:00

89 lines
3.3 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Tests\Unit\Infrastructure\Order;
use App\Application\Order\ErpAdapterInterface;
use App\Domain\Order\Customer;
use App\Domain\Order\Repository\CustomerRepositoryInterface;
use App\Infrastructure\Order\CustomerResolver;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
final class CustomerResolverTest extends TestCase
{
private CustomerRepositoryInterface&MockObject $customerRepo;
private ErpAdapterInterface&MockObject $erp;
private CustomerResolver $resolver;
protected function setUp(): void
{
$this->customerRepo = $this->createMock(CustomerRepositoryInterface::class);
$this->erp = $this->createMock(ErpAdapterInterface::class);
$this->resolver = new CustomerResolver($this->customerRepo, $this->erp);
}
public function testStage1PlatformIdMatchReturnsExistingCustomerWithoutErpCall(): void
{
$existing = new Customer('Max Mustermann', 'max@test.de', ['street' => 'Musterstr 1', 'city' => 'Berlin', 'zip' => '10115']);
$existing->addPlatformId('ebay', 'buyer123');
$this->customerRepo
->method('findByPlatformId')
->with('ebay', 'buyer123')
->willReturn($existing);
$this->erp->expects($this->never())->method('createCustomer');
$this->customerRepo->expects($this->never())->method('save');
$result = $this->resolver->resolve(
'ebay', 'buyer123',
'Max Mustermann', 'max@test.de',
['street' => 'Musterstr 1', 'city' => 'Berlin', 'zip' => '10115'],
);
$this->assertSame($existing, $result);
}
public function testStage2AddressMatchAddsPlatformIdAndSaves(): void
{
$existing = new Customer('Max Mustermann', 'max@test.de', ['street' => 'Musterstr 1', 'city' => 'Berlin', 'zip' => '10115']);
$this->customerRepo->method('findByPlatformId')->willReturn(null);
$this->customerRepo
->method('findByMatchingKey')
->with($existing->getMatchingKey())
->willReturn($existing);
$this->customerRepo->expects($this->once())->method('save')->with($existing);
$this->erp->expects($this->never())->method('createCustomer');
$result = $this->resolver->resolve(
'ebay', 'buyer456',
'Max Mustermann', 'max@test.de',
['street' => 'Musterstr 1', 'city' => 'Berlin', 'zip' => '10115'],
);
$this->assertSame($existing, $result);
$this->assertSame('buyer456', $result->getPlatformId('ebay'));
}
public function testNoMatchCreatesNewCustomerViaErp(): void
{
$this->customerRepo->method('findByPlatformId')->willReturn(null);
$this->customerRepo->method('findByMatchingKey')->willReturn(null);
$this->customerRepo->expects($this->once())->method('save');
$this->erp->method('createCustomer')->willReturn('CUST-99999');
$result = $this->resolver->resolve(
'ebay', 'newbuyer',
'Neue Käuferin', 'neu@test.de',
['street' => 'Neustr 5', 'city' => 'München', 'zip' => '80333'],
);
$this->assertSame('CUST-99999', $result->getFrappeCustomerId());
$this->assertSame('newbuyer', $result->getPlatformId('ebay'));
$this->assertSame('Neue Käuferin', $result->getName());
}
}