Created
March 29, 2026 08:52
-
-
Save mlebkowski/ccc7c6bf92d04d619a310c865024f96e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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