customers = new InMemoryCustomerRepository; $this->updateCustomer = new UpdateCustomer($this->customers, new FakeTransactionManager); $this->customerId = $this->customers->save( Customer::register(new CustomerName('Mainos Oy'), CustomerType::Company, new BusinessId('0737546-2')), )->id(); }); it('changes the details of a stored customer', function () { $this->updateCustomer->execute($this->customerId, new CustomerDetailsData('Mainos Oyj', CustomerType::Company, '0737546-2')); expect($this->customers->findById($this->customerId)?->name()->value)->toBe('Mainos Oyj'); }); it('turns a company into a consumer when the business id is removed', function () { $this->updateCustomer->execute($this->customerId, new CustomerDetailsData('Maija Meikäläinen', CustomerType::Consumer)); $customer = $this->customers->findById($this->customerId); expect($customer?->type())->toBe(CustomerType::Consumer) ->and($customer?->businessId())->toBeNull(); }); it('rejects a business id that belongs to another customer', function () { $this->customers->save(Customer::register(new CustomerName('Toinen Oy'), CustomerType::Company, new BusinessId('1572860-0'))); expect(fn () => $this->updateCustomer->execute($this->customerId, new CustomerDetailsData('Mainos Oy', CustomerType::Company, '1572860-0'))) ->toThrow(BusinessIdAlreadyInUse::class) ->and($this->customers->findById($this->customerId)?->businessId()?->value)->toBe('0737546-2'); }); it('fails for an unknown customer', function () { $this->updateCustomer->execute(999, new CustomerDetailsData('Mainos Oy', CustomerType::Company)); })->throws(CustomerNotFound::class);