Skip to content

Commit e259ec3

Browse files
committed
test(client): cover config contract handling
Signed-off-by: Vitor Mattos <vitor@php.rio>
1 parent 37867a5 commit e259ec3

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

tests/Unit/Http/NfseClientTest.php

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,15 @@ public function sign(string $xml, string $cnpj): string
5757
public function testEmitReturnsReceiptDataOnSuccess(): void
5858
{
5959
$payload = json_encode([
60-
'nNFSe' => '42',
61-
'chaveAcesso' => 'abc-123',
62-
'dhEmi' => '2026-01-01T12:00:00',
60+
'nNFSe' => '42',
61+
'chaveAcesso' => 'abc-123',
62+
'dataHoraProcessamento' => '2026-01-01T12:00:00',
63+
'nfseXmlGZipB64' => base64_encode(gzencode('<NFS-e>ok</NFS-e>')),
6364
], JSON_THROW_ON_ERROR);
6465

6566
self::$server->setResponseOfPath(
66-
'/NFS-e/api/v1/dps',
67-
new Response($payload, ['Content-Type' => 'application/json'], 200)
67+
'/SefinNacional/nfse',
68+
new Response($payload, ['Content-Type' => 'application/json'], 201)
6869
);
6970

7071
$client = $this->makeClient($this->signer);
@@ -75,6 +76,7 @@ public function testEmitReturnsReceiptDataOnSuccess(): void
7576
self::assertSame('42', $receipt->nfseNumber);
7677
self::assertSame('abc-123', $receipt->chaveAcesso);
7778
self::assertSame('2026-01-01T12:00:00', $receipt->dataEmissao);
79+
self::assertSame('<NFS-e>ok</NFS-e>', $receipt->rawXml);
7880
}
7981

8082
public function testQueryReturnsReceiptDataOnSuccess(): void
@@ -86,7 +88,7 @@ public function testQueryReturnsReceiptDataOnSuccess(): void
8688
], JSON_THROW_ON_ERROR);
8789

8890
self::$server->setResponseOfPath(
89-
'/NFS-e/api/v1/dps/xyz-456',
91+
'/SefinNacional/nfse/xyz-456',
9092
new Response($payload, ['Content-Type' => 'application/json'], 200)
9193
);
9294

@@ -100,7 +102,7 @@ public function testQueryReturnsReceiptDataOnSuccess(): void
100102
public function testCancelReturnsTrueOnSuccess(): void
101103
{
102104
self::$server->setResponseOfPath(
103-
'/NFS-e/api/v1/dps/abc-123',
105+
'/SefinNacional/dps/abc-123',
104106
new Response('{}', ['Content-Type' => 'application/json'], 200)
105107
);
106108

@@ -118,7 +120,7 @@ public function testEmitThrowsIssuanceExceptionWhenGatewayRejects(): void
118120
$payload = json_encode(['codigo' => 'E422', 'mensagem' => 'CNPJ inválido'], JSON_THROW_ON_ERROR);
119121

120122
self::$server->setResponseOfPath(
121-
'/NFS-e/api/v1/dps',
123+
'/SefinNacional/nfse',
122124
new Response($payload, ['Content-Type' => 'application/json'], 422),
123125
);
124126

@@ -133,7 +135,7 @@ public function testIssuanceExceptionCarriesErrorCodeHttpStatusAndUpstreamPayloa
133135
$errorData = ['codigo' => 'E422', 'mensagem' => 'CNPJ inválido'];
134136

135137
self::$server->setResponseOfPath(
136-
'/NFS-e/api/v1/dps',
138+
'/SefinNacional/nfse',
137139
new Response(json_encode($errorData, JSON_THROW_ON_ERROR), ['Content-Type' => 'application/json'], 422),
138140
);
139141

@@ -152,7 +154,7 @@ public function testIssuanceExceptionCarriesErrorCodeHttpStatusAndUpstreamPayloa
152154
public function testQueryThrowsQueryExceptionWhenGatewayReturnsError(): void
153155
{
154156
self::$server->setResponseOfPath(
155-
'/NFS-e/api/v1/dps/missing-key',
157+
'/SefinNacional/nfse/missing-key',
156158
new Response('{"error":"not found"}', ['Content-Type' => 'application/json'], 404),
157159
);
158160

@@ -165,7 +167,7 @@ public function testQueryThrowsQueryExceptionWhenGatewayReturnsError(): void
165167
public function testQueryExceptionCarriesErrorCodeAndHttpStatus(): void
166168
{
167169
self::$server->setResponseOfPath(
168-
'/NFS-e/api/v1/dps/missing-key',
170+
'/SefinNacional/nfse/missing-key',
169171
new Response('{"error":"not found"}', ['Content-Type' => 'application/json'], 404),
170172
);
171173

@@ -183,7 +185,7 @@ public function testQueryExceptionCarriesErrorCodeAndHttpStatus(): void
183185
public function testCancelThrowsCancellationExceptionWhenGatewayReturnsError(): void
184186
{
185187
self::$server->setResponseOfPath(
186-
'/NFS-e/api/v1/dps/blocked-key',
188+
'/SefinNacional/dps/blocked-key',
187189
new Response('{"error":"cannot cancel"}', ['Content-Type' => 'application/json'], 409),
188190
);
189191

@@ -196,7 +198,7 @@ public function testCancelThrowsCancellationExceptionWhenGatewayReturnsError():
196198
public function testCancellationExceptionCarriesErrorCodeAndHttpStatus(): void
197199
{
198200
self::$server->setResponseOfPath(
199-
'/NFS-e/api/v1/dps/blocked-key',
201+
'/SefinNacional/dps/blocked-key',
200202
new Response('{"error":"cannot cancel"}', ['Content-Type' => 'application/json'], 409),
201203
);
202204

@@ -217,12 +219,14 @@ private function makeClient(?XmlSignerInterface $signer = null): NfseClient
217219
{
218220
return new NfseClient(
219221
environment: new EnvironmentConfig(
220-
baseUrl: self::$server->getServerRoot() . '/NFS-e/api/v1',
222+
baseUrl: self::$server->getServerRoot() . '/SefinNacional',
221223
),
222224
cert: new CertConfig(
223225
cnpj: '29842527000145',
224226
pfxPath: '/dev/null',
225227
vaultPath: 'secret/nfse/29842527000145',
228+
transportCertificatePath: '/tmp/client.crt.pem',
229+
transportPrivateKeyPath: '/tmp/client.key.pem',
226230
),
227231
secretStore: new NoOpSecretStore(),
228232
signer: $signer,

0 commit comments

Comments
 (0)