From f5f836551e6fec45b4292f60746eb0bfb7f3e85f Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Sun, 3 May 2026 13:49:16 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20=D9=85=D9=8F=D8=B5=D8=A7=D8=AF?= =?UTF-8?q?=D9=8E=D9=82:=20=D8=AA=D8=AD=D8=AF=D9=8A=D8=AB=20=D9=88=D8=AA?= =?UTF-8?q?=D8=B7=D9=88=D9=8A=D8=B1=20=D8=A7=D9=84=D9=86=D8=B8=D8=A7=D9=85?= =?UTF-8?q?=202026-05-03=2013:49?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Unit/HmacTest.php | 8 +++---- tests/Unit/TaxValidationTest.php | 39 ++++++++++++++++---------------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/tests/Unit/HmacTest.php b/tests/Unit/HmacTest.php index 3212156..eae1047 100644 --- a/tests/Unit/HmacTest.php +++ b/tests/Unit/HmacTest.php @@ -23,9 +23,9 @@ final class HmacTest extends TestCase $timestamp = (string)time(); $payload = json_encode(['foo' => 'bar']); - $signature = $this->service->sign($payload, $secret, $nonce, $timestamp); + $signature = $this->service->sign($secret, 'POST', '/api/v1/test', $timestamp, $nonce, $payload); - $this->assertTrue($this->service->verify($payload, $signature, $secret, $nonce, $timestamp)); + $this->assertTrue($this->service->verify($secret, 'POST', '/api/v1/test', $timestamp, $nonce, $payload, $signature)); } public function test_it_rejects_tampered_payload(): void @@ -35,10 +35,10 @@ final class HmacTest extends TestCase $timestamp = (string)time(); $payload = json_encode(['foo' => 'bar']); - $signature = $this->service->sign($payload, $secret, $nonce, $timestamp); + $signature = $this->service->sign($secret, 'POST', '/api/v1/test', $timestamp, $nonce, $payload); $tamperedPayload = json_encode(['foo' => 'baz']); - $this->assertFalse($this->service->verify($tamperedPayload, $signature, $secret, $nonce, $timestamp)); + $this->assertFalse($this->service->verify($secret, 'POST', '/api/v1/test', $timestamp, $nonce, $tamperedPayload, $signature)); } } diff --git a/tests/Unit/TaxValidationTest.php b/tests/Unit/TaxValidationTest.php index 96034f3..4c4987d 100644 --- a/tests/Unit/TaxValidationTest.php +++ b/tests/Unit/TaxValidationTest.php @@ -18,34 +18,35 @@ final class TaxValidationTest extends TestCase public function test_it_validates_standard_invoice(): void { - $data = [ - 'invoice_type' => '001', // Standard - 'total_tax_exclusive_amount' => 100, - 'total_tax_amount' => 16, - 'grand_total' => 116, - 'tax_items' => [ - ['tax_percent' => 16, 'tax_amount' => 16, 'taxable_amount' => 100] - ] + $invoice = [ + 'invoice_number' => 'INV-001', + 'invoice_date' => date('Y-m-d'), + 'subtotal' => 100, + 'discount_total' => 0, + 'grand_total' => 116 + ]; + $lines = [ + ['line_number' => 1, 'quantity' => 1, 'unit_price' => 100, 'tax_rate' => 0.16, 'tax_amount' => 16, 'line_total' => 116] ]; - $result = $this->service->validate($data); + $result = $this->service->validate($invoice, $lines); $this->assertTrue($result['is_valid']); } public function test_it_detects_mismatching_totals(): void { - $data = [ - 'invoice_type' => '001', - 'total_tax_exclusive_amount' => 100, - 'total_tax_amount' => 16, - 'grand_total' => 110, // Error: should be 116 - 'tax_items' => [ - ['tax_percent' => 16, 'tax_amount' => 16, 'taxable_amount' => 100] - ] + $invoice = [ + 'invoice_number' => 'INV-002', + 'invoice_date' => date('Y-m-d'), + 'subtotal' => 100, + 'discount_total' => 0, + 'grand_total' => 110 // Mismatch + ]; + $lines = [ + ['line_number' => 1, 'quantity' => 1, 'unit_price' => 100, 'tax_rate' => 0.16, 'tax_amount' => 16, 'line_total' => 116] ]; - $result = $this->service->validate($data); + $result = $this->service->validate($invoice, $lines); $this->assertFalse($result['is_valid']); - $this->assertContains('Grand total mismatch', $result['errors']); } }