Skip to content

Commit 328188f

Browse files
committed
Tests de FACeB2B (josemmo#47)
Añadida subida y cancelación de factura a FACeB2B
1 parent 291ef88 commit 328188f

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

tests/WebservicesTest.php

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ public function testFace() {
105105
// Get invoice status
106106
$res = $face->getInvoices($res->factura->numeroRegistro);
107107
$this->assertEquals(intval($res->resultado->codigo), 0);
108-
109108
}
110109

111110

@@ -115,12 +114,47 @@ public function testFace() {
115114
public function testFaceb2b() {
116115
$this->checkEnv();
117116

118-
$face = new Faceb2bClient(self::CERTS_DIR . "/webservices.p12", null, self::WEBSERVICES_CERT_PASS);
119-
$face->setProduction(false);
120-
$res = $face->getCodes();
117+
$faceb2b = new Faceb2bClient(self::CERTS_DIR . "/webservices.p12", null, self::WEBSERVICES_CERT_PASS);
118+
$faceb2b->setProduction(false);
121119

122-
$success = isset($res->codes);
123-
$this->assertTrue($success);
120+
// Test misc. methods
121+
$this->assertFalse(empty($faceb2b->getCodes()->codes));
122+
$this->assertEquals(intval($faceb2b->getRegisteredInvoices()->resultStatus->code), 0);
123+
$this->assertEquals(intval($faceb2b->getInvoiceCancellations()->resultStatus->code), 0);
124+
125+
// Generate invoice
126+
$fac = $this->getBaseInvoice();
127+
$fac->setBuyer(new FacturaeParty([
128+
"taxNumber" => "A78923125",
129+
"name" => "Teléfonica Móviles España, S.A.U.",
130+
"address" => "Calle Gran Vía, 28",
131+
"postCode" => "28013",
132+
"town" => "Madrid",
133+
"province" => "Madrid"
134+
]));
135+
$fac->getExtension('Fb2b')->setReceiver(new FacturaeCentre([
136+
"code" => "ESA789231250000",
137+
"name" => "Centro administrativo receptor"
138+
]));
139+
$fac->sign(self::CERTS_DIR . "/webservices.p12", null, self::WEBSERVICES_CERT_PASS);
140+
141+
// Send invoice
142+
$invoiceFile = new FacturaeFile();
143+
$invoiceFile->loadData($fac->export(), "factura-de-prueba.xsig");
144+
$res = $faceb2b->sendInvoice($invoiceFile);
145+
$this->assertEquals(intval($res->resultStatus->code), 0);
146+
$this->assertFalse(empty($res->invoiceDetail->registryNumber));
147+
$registryNumber = $res->invoiceDetail->registryNumber;
148+
149+
// Cancel invoice
150+
$res = $faceb2b->requestInvoiceCancellation($registryNumber,
151+
"C002", "Factura de prueba autogenerada por " . Facturae::USER_AGENT);
152+
$this->assertEquals(intval($res->resultStatus->code), 0);
153+
154+
// Confirm cancellation
155+
$res = $faceb2b->getInvoiceDetails($registryNumber);
156+
$this->assertEquals(intval($res->resultStatus->code), 0);
157+
$this->assertEquals(strval($res->invoiceDetail->cancellationInfo->reason), "C002");
124158
}
125159

126160
}

0 commit comments

Comments
 (0)