From caa2078098cd0f91681654a276b4a21034decc1e Mon Sep 17 00:00:00 2001 From: andrei-ghenov Date: Mon, 4 Mar 2024 11:00:07 -0500 Subject: [PATCH] T-004: Integrate and Test Product API Endpoints. --- .env.example | 2 + src/Service/ProductService.php | 2 + tests/Api/ApiClientTest.php | 4 -- tests/Service/ProductServiceTest.php | 63 ++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 tests/Service/ProductServiceTest.php diff --git a/.env.example b/.env.example index 9d95bb4..e324626 100644 --- a/.env.example +++ b/.env.example @@ -2,3 +2,5 @@ API_BASE_URL=your_api_base_url API_USER=your_api_username API_PASSWORD=your_api_password API_SECRET=your_api_secret +API_PRODUCT_ID=your_api_product_id +API_DESTINATION_PHONE_NUMBER=your_api_destination_phone_number \ No newline at end of file diff --git a/src/Service/ProductService.php b/src/Service/ProductService.php index 6fc909d..d095099 100644 --- a/src/Service/ProductService.php +++ b/src/Service/ProductService.php @@ -35,6 +35,7 @@ public function __construct(ApiClient $apiClient) { * * @return array * The products. + * @throws \Exception */ public function getAllProducts(): array { $endpoint = 'WSGetTopUpProducts'; @@ -50,6 +51,7 @@ public function getAllProducts(): array { * * @return array * The product. + * @throws \Exception */ public function getProductById(int $productID): mixed { $endpoint = "WSGetSingleTopUpProduct"; diff --git a/tests/Api/ApiClientTest.php b/tests/Api/ApiClientTest.php index 6a1feab..ec64348 100644 --- a/tests/Api/ApiClientTest.php +++ b/tests/Api/ApiClientTest.php @@ -66,10 +66,6 @@ public function testWSLoginFailure() { 'Password' => 'incorrectPassword', ]); - // Debugging output (use sparingly). - echo "Response: "; - var_dump($response); - // Assert the response indicates a failed login. $this->assertArrayHasKey( 'AccessCode', $response, "Response does not contain AccessCode" diff --git a/tests/Service/ProductServiceTest.php b/tests/Service/ProductServiceTest.php new file mode 100644 index 0000000..4ae393d --- /dev/null +++ b/tests/Service/ProductServiceTest.php @@ -0,0 +1,63 @@ +productService->getProductById($this->apiProductID); + + // Display the response for debugging purposes. + echo "Response: "; + var_dump($product); + + // You might want to adjust these assertions based on + // the expected product structure. + $this->assertIsArray($product); + $this->assertArrayHasKey('Product', $product); + $this->assertEquals($this->apiProductID , $product['Product']); + } + + /** + * Set up the test case. + */ + protected function setUp(): void { + $apiClient = new ApiClient(); + + // Instantiate ProductService with the real ApiClient. + $this->productService = new ProductService($apiClient); + + // Set the API product ID. + $this->apiProductID = $_ENV['API_PRODUCT_ID']; + } + +}