diff --git a/tests/Http/SendInvoicesTest.php b/tests/Http/SendInvoicesTest.php index de27be7..72ef263 100644 --- a/tests/Http/SendInvoicesTest.php +++ b/tests/Http/SendInvoicesTest.php @@ -3,6 +3,7 @@ namespace Tests\Http; use Firebed\AadeMyData\Exceptions\MyDataException; +use Firebed\AadeMyData\Exceptions\TransmissionFailedException; use Firebed\AadeMyData\Factories\ResponseDocXmlFactory; use Firebed\AadeMyData\Http\MyDataRequest; use Firebed\AadeMyData\Http\SendInvoices; @@ -34,14 +35,14 @@ public function test_dev_provider_url_is_correct() $sendInvoices = new SendInvoices(); $this->assertEquals('https://mydataapidev.aade.gr/myDataProvider/SendInvoices', $sendInvoices->getUrl()); } - + public function test_prod_provider_url_is_correct() { MyDataRequest::init('test_user_id', 'test_user_secret', 'prod', true); $sendInvoices = new SendInvoices(); $this->assertEquals('https://mydatapi.aade.gr/myDataProvider/SendInvoices', $sendInvoices->getUrl()); - } - + } + /** * @throws MyDataException */ @@ -59,7 +60,7 @@ public function test_it_sends_single_invoice() $this->assertCount(1, $responseDoc); } - + /** * @throws MyDataException */ @@ -126,4 +127,19 @@ public function test_it_sends_a_single_invoice() $this->assertCount(1, $responseDoc); } + + /** + * @throws MyDataException + */ + public function test_transmission_failure_throws_exception() + { + MyDataRequest::setHandler(new MockHandler([ + new HttpResponse(500), + ])); + + $this->expectException(TransmissionFailedException::class); + + $sendInvoices = new SendInvoices(); + $sendInvoices->handle(new Invoice()); + } } \ No newline at end of file diff --git a/tests/InvoiceTest.php b/tests/InvoiceTest.php index b15cc84..9aeae03 100644 --- a/tests/InvoiceTest.php +++ b/tests/InvoiceTest.php @@ -28,7 +28,7 @@ public function test_invoice_xml() ] ] ]); - + $invoice = Invoice::factory()->make(); $this->assertNotEmpty($invoice->toXml()); } @@ -54,13 +54,13 @@ public function test_invoice_validation() $invoice = Invoice::factory()->make(); $this->assertEmpty($invoice->validate()); } - + public function test_invoice_validation_fail() { $invoice = Invoice::factory()->make(); $invoice->getInvoiceHeader()->setInvoiceType("wrong"); $invoice->getInvoiceSummary()->setTotalGrossValue(-10); - + // "wrong" value will be cast to null because InvoiceType enum does // not have "wrong" value. // Since null values are stripped from the array, we expect a failure