customerRepo = $this->createMock(CustomerRepositoryInterface::class); $this->erp = $this->createMock(ErpAdapterInterface::class); $this->resolver = new CustomerResolver($this->customerRepo, $this->erp); } public function test_stage_1_platform_id_match_returns_existing_customer_without_erp_call(): 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 test_stage_2_address_match_adds_platform_id_and_saves(): 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 test_no_match_creates_new_customer_via_erp(): 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()); } }