Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save mlebkowski/ccc7c6bf92d04d619a310c865024f96e to your computer and use it in GitHub Desktop.

Select an option

Save mlebkowski/ccc7c6bf92d04d619a310c865024f96e to your computer and use it in GitHub Desktop.
<?php
final class ChargebeeCustomerEndpointTestDouble {
private array $customers = [];
public function givenCustomerExists(Customer $customer): void {
$this->customers[$customer->id] = $customer;
}
public function updateCustomer(CustomerId $id, CustomerChangePayload $change): void {
$this->customers[$id->value] = $this->get($id)->withName($change->name);
}
public function get(CustomerId $id): Customer {
return $this->customers[$id->value] ?? throw new CustomerNotFoundException();
}
}
<?php
#[Test]
function companyNameChangeIsReflectedInChargebee(): void {
// given we set up the pre-existing context:
$companyScenario = $this->companyUseCase->givenCompanyExists("Evil Corp");
$this->chargebeeUseCase->givenCustomerExists(
new Customer(
id: $companyScenario->companyId,
name: "Evil Corp",
),
);
// when the API is called
$companyScenario->changeCompanyName("Acme");
// then expect the side-effect was produced by inspecting our test double
$actual = $this->chargebeeUseCase->getCustomer($customer->companyId);
self::assertSame("Acme", $actual->name);
}
<?php
function changeCompanyName(string $name): void {
$response = PatchCompanyEndpointAssertion::of(
$this->httpClient->patch('/api/company', ['name' => $name]),
);
$response->assertSuccessful();
$response->assertName($name);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment