capturePayload(fn (ApiClient $client) => $client->updateProfile($this->user(addressId: 141747, personId: 224526))); $this->assertSame('Adressdaten_Ändern', $payload['art']); $this->assertSame('J', $payload['login']); $this->assertSame(141747, $payload['idadresse']); $this->assertSame(224526, $payload['idadresseperson']); $this->assertArrayNotHasKey('passwort', $payload); $this->assertSame( ['user', 'key', 'satz', 'art', 'email', 'login', 'idadresse', 'idadresseperson', 'adressdaten'], array_keys($payload), ); } /** * The ids are the whole authorisation of the write, so a user missing one is refused before * anything is sent. */ public function testUpdateProfileRefusesAUserWithoutBothIds(): void { $serializer = $this->createMock(SerializerInterface::class); $serializer->expects($this->never())->method('serialize'); $this->expectException(ApiClientException::class); $this->client($serializer)->updateProfile($this->user(addressId: 141747, personId: null)); } /** * @param callable(ApiClient): mixed $request */ private function capturePayload(callable $request): array { $captured = null; $serializer = $this->createMock(SerializerInterface::class); $serializer ->expects($this->once()) ->method('serialize') ->willReturnCallback(function (mixed $data) use (&$captured): never { $captured = $data; throw new \LogicException('Request captured'); }) ; try { $request($this->client($serializer)); } catch (\LogicException) { } $this->assertIsArray($captured); return $captured['anfrage']; } private function client(SerializerInterface $serializer): ApiClient { return new ApiClient( $serializer, $this->createStub(ResponseParser::class), new NullLogger(), $this->createStub(FilesystemOperator::class), [ 'bpn_username' => 'api', 'bpn_password' => 'secret', 'bpn_api_ip' => '127.0.0.1', 'bpn_api_port' => 1, ], ); } private function user(?int $addressId, ?int $personId): User { $teamer = new Teamer(); $teamer ->setFirstName('Anna') ->setLastName('Muster') ->setGender('F') ->setAddress(new Address()) ->setCommunication(new Communication()) ; $user = new User(); $user ->setEmail('anna@example.org') ->setTeamer($teamer) ; if (null !== $addressId) { $user->setBusProAddressId($addressId); } if (null !== $personId) { $user->setBusProPersonId($personId); } return $user; } }