From 64764fb9fac0227f8e0443e7c7519d73aec275b9 Mon Sep 17 00:00:00 2001 From: Murilo Ijanc Date: Sun, 26 Jul 2026 14:58:55 -0300 Subject: Initial import --- tests/ServerTestCase.php | 106 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 tests/ServerTestCase.php (limited to 'tests/ServerTestCase.php') diff --git a/tests/ServerTestCase.php b/tests/ServerTestCase.php new file mode 100644 index 0000000..d000778 --- /dev/null +++ b/tests/ServerTestCase.php @@ -0,0 +1,106 @@ + '01001000', + 'logradouro' => 'Praça da Sé', + 'complemento' => 'lado ímpar', + 'unidade' => '', + 'bairro' => 'Sé', + 'localidade' => 'São Paulo', + 'uf' => 'SP', + 'estado' => 'São Paulo', + 'regiao' => 'Sudeste', + 'ibge' => '3550308', + 'gia' => '1004', + 'ddd' => '11', + 'siafi' => '7107', + ]; + + protected const CSV_HEADER = 'cep,logradouro,complemento,unidade,bairro,localidade,uf,' + . 'estado,regiao,ibge,gia,ddd,siafi'; + + protected TestServer $server; + + protected Client $client; + + protected function setUp(): void + { + $this->server = new TestServer(); + $this->client = new Client( + baseUrl: $this->server->url, + timeout: 5.0, + backoffBase: 0.001, + backoffMax: 0.01, + ); + } + + protected function tearDown(): void + { + $this->server->stop(); + } + + /** + * @param array $body + * @param array $headers + * + * @return array + */ + protected static function json(array $body, int $status = 200, array $headers = []): array + { + return [ + 'status' => $status, + 'body' => json_encode($body, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE), + 'headers' => $headers, + 'content_type' => 'application/json; charset=utf-8', + ]; + } + + /** + * @param array $headers + * + * @return array + */ + protected static function raw(int $status, string $body, array $headers = []): array + { + return ['status' => $status, 'body' => $body, 'headers' => $headers]; + } + + /** + * @param list $rows + * + * @return array + */ + protected static function csv(array $rows): array + { + return [ + 'status' => 200, + 'body' => self::CSV_HEADER . "\n" . implode("\n", $rows) . "\n", + 'headers' => [], + 'content_type' => 'text/csv; charset=utf-8', + ]; + } + + protected static function monotonic(): float + { + return hrtime(true) / 1_000_000_000; + } +} -- cgit v1.3