From bc16f6fc5ae3f12ccffa4d5283e660de12ca4613 Mon Sep 17 00:00:00 2001 From: Jay-Ponda-Improwised Date: Sat, 15 Feb 2025 23:07:03 +0530 Subject: [PATCH 01/17] default object attributes --- src/ApiResponse.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ApiResponse.php b/src/ApiResponse.php index 3a1718f..f3e9449 100644 --- a/src/ApiResponse.php +++ b/src/ApiResponse.php @@ -6,5 +6,7 @@ class ApiResponse extends Response { - + public $success = false; + public $body = null; + public $meta = null; } From efcd1dcb029a43f9c3f2add0c50e288094944d4b Mon Sep 17 00:00:00 2001 From: Jay-Ponda-Improwised Date: Sat, 15 Feb 2025 23:30:38 +0530 Subject: [PATCH 02/17] rename project --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f066b3b..27e22bc 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "lde/api-helper", + "name": "lde/api-helper-demo", "description": "Laravel package to help consume REST and XML APIs with little effort.", "license": "MIT", "keywords": [ From 2cc0f94c7b1ec574332d8d06a15567252e798b7d Mon Sep 17 00:00:00 2001 From: Jay-Ponda-Improwised Date: Sat, 15 Feb 2025 23:43:55 +0530 Subject: [PATCH 03/17] added error attribute --- src/ApiResponse.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ApiResponse.php b/src/ApiResponse.php index f3e9449..bb3c872 100644 --- a/src/ApiResponse.php +++ b/src/ApiResponse.php @@ -9,4 +9,5 @@ class ApiResponse extends Response public $success = false; public $body = null; public $meta = null; + public $error = null; } From f708fda6ee71e6e73c80f50d928a4a76a69180ff Mon Sep 17 00:00:00 2001 From: Jay-Ponda-Improwised Date: Sun, 16 Feb 2025 01:26:03 +0530 Subject: [PATCH 04/17] Revert "rename project" This reverts commit efcd1dcb029a43f9c3f2add0c50e288094944d4b. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 27e22bc..f066b3b 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "lde/api-helper-demo", + "name": "lde/api-helper", "description": "Laravel package to help consume REST and XML APIs with little effort.", "license": "MIT", "keywords": [ From 51097bfdfe27159873860ab800c9266d6a3d3fb9 Mon Sep 17 00:00:00 2001 From: Jay-Ponda-Improwised Date: Sun, 16 Feb 2025 18:14:23 +0530 Subject: [PATCH 05/17] mock xml api call --- dev-docker-compose.yaml | 9 +++++++++ src/ApiBuilder.php | 22 ++++++++++++---------- tests/ApiBuilderTest.php | 28 ++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 dev-docker-compose.yaml diff --git a/dev-docker-compose.yaml b/dev-docker-compose.yaml new file mode 100644 index 0000000..60954e5 --- /dev/null +++ b/dev-docker-compose.yaml @@ -0,0 +1,9 @@ + +services: + api-helper: + image: circleci/php:7.4 + container_name: api-helper + working_dir: /app + command: sleep infinity + volumes: + - .:/app \ No newline at end of file diff --git a/src/ApiBuilder.php b/src/ApiBuilder.php index ee01aad..237c0eb 100644 --- a/src/ApiBuilder.php +++ b/src/ApiBuilder.php @@ -28,6 +28,8 @@ class ApiBuilder public $sensitiveFields = []; + public $client; + /** * Sets API connection * @@ -67,6 +69,8 @@ public function api($connection) // Set the base url $this->baseUrl = config('api_helper.connections.' . $this->connection . '.base_url'); + $this->client = new Client(); + return $this; } @@ -188,7 +192,7 @@ public function __call($name, $arguments) break; case 'xml': - + switch ($method) { // only post and put have a body case 'PATCH': @@ -258,7 +262,7 @@ public function __call($name, $arguments) } StatsHelper::incHistogram($bucketName, (float) (microtime(true) - $startTime), [$this->connection, $name, $object->meta->status_code], "Response time for external API calls.", ['destination', 'endpoint', 'status']); } - + return $object; } else { @@ -290,20 +294,18 @@ public function call($method, $uri, $params = []) while ($success == false && $tries <= $retries) { $tries++; - $client = new Client(); + if (is_null($this->client)) { + $this->client = new Client(); + } + + $client = $this->client; try { // Merge params $params = array_merge($this->requestOptions, $params); if ($this->type == "xml") { - Log::debug('Headers data: ', [ - 'data' => $uri, - ]); - - // Send request - $response = $client->request($method, $uri, $params); - + $response = $client->request($method, $uri, $params); // If we got this far, we have a response. // convert xml string into an object diff --git a/tests/ApiBuilderTest.php b/tests/ApiBuilderTest.php index b01d42f..82cacc0 100644 --- a/tests/ApiBuilderTest.php +++ b/tests/ApiBuilderTest.php @@ -2,7 +2,12 @@ namespace Lde\ApiHelper\Tests; +use GuzzleHttp\Client; +use GuzzleHttp\HandlerStack; +use GuzzleHttp\Psr7\Response; use Lde\ApiHelper\ApiBuilder; +use GuzzleHttp\Handler\MockHandler; +use Symfony\Component\HttpFoundation\Response as HTTPStatus; class ApiBuilderTest extends TestCase { @@ -72,8 +77,31 @@ public function testMagicDelete() public function testHttpBinPostXml() { + // mock api call as URL not working + $xml = + ' + + + + Barbarian + + John + Dagger + + '; + + $mock = new MockHandler([ + new Response(HTTPStatus::HTTP_OK, ['Content-Type' => 'application/xml'], $xml), + ]); + + $handlerStack = HandlerStack::create($mock); + $client = new Client(['handler' => $handlerStack]); + + // Bind the mock to Laravel's container + $apibuilder = new ApiBuilder(); $api = $apibuilder->api('mockbin'); + $api->client = $client; $response = $api->echo(['request' => ['name' => 'John', 'class' => 'Barbarian', 'weapon' => 'Dagger']]); $val = $response->body['request']; self::assertTrue($response->success); From 53ab0255089be1147b46e8cbfcbc47c63b4372fd Mon Sep 17 00:00:00 2001 From: Jay-Ponda-Improwised Date: Mon, 17 Feb 2025 10:58:51 +0530 Subject: [PATCH 06/17] fix whitespace probleam and typos and put log --- dev-docker-compose.yaml | 4 ++-- src/ApiBuilder.php | 27 ++++++++++++++++----------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/dev-docker-compose.yaml b/dev-docker-compose.yaml index 60954e5..f438436 100644 --- a/dev-docker-compose.yaml +++ b/dev-docker-compose.yaml @@ -1,4 +1,3 @@ - services: api-helper: image: circleci/php:7.4 @@ -6,4 +5,5 @@ services: working_dir: /app command: sleep infinity volumes: - - .:/app \ No newline at end of file + - .:/app + \ No newline at end of file diff --git a/src/ApiBuilder.php b/src/ApiBuilder.php index 237c0eb..b45d80b 100644 --- a/src/ApiBuilder.php +++ b/src/ApiBuilder.php @@ -2,17 +2,18 @@ namespace Lde\ApiHelper; +use Adbar\Dot; use GuzzleHttp\Client; -use GuzzleHttp\Exception\RequestException; -use Illuminate\Support\Facades\Log; +use Illuminate\Support\Arr; use Lde\ApiHelper\ApiResponse; -use Lde\ApiHelper\Events\ApiCallCompleted; +use Spatie\ArrayToXml\ArrayToXml; +use Illuminate\Support\Facades\Log; +use Lde\ApiHelper\Helpers\StatsHelper; use Lde\ApiHelper\Events\ApiCallStarting; +use GuzzleHttp\Exception\RequestException; +use Lde\ApiHelper\Events\ApiCallCompleted; use Lde\ApiHelper\Helpers\HelperException; use Lde\ApiHelper\Helpers\ObfuscationHelper; -use Lde\ApiHelper\Helpers\StatsHelper; -use Spatie\ArrayToXml\ArrayToXml; -use Illuminate\Support\Arr; class ApiBuilder { @@ -28,7 +29,7 @@ class ApiBuilder public $sensitiveFields = []; - public $client; + public $client = null; /** * Sets API connection @@ -54,7 +55,7 @@ public function api($connection) throw new HelperException("Connection '$connection' not found!"); } - // Set the request options if provided for this conenction. Else use default ones. + // Set the request options if provided for this connection. Else use default ones. if (Arr::get($conn, 'default_request_options')) { $additionalHeaders = $this->requestOptions['headers']; $default = Arr::get($conn, 'default_request_options.headers'); @@ -276,7 +277,7 @@ public function __call($name, $arguments) * @param $params * * @link http://docs.guzzlephp.org/en/stable/request-options.html - * @return array + * @return object * @throws \GuzzleHttp\Exception\GuzzleException */ public function call($method, $uri, $params = []) @@ -305,6 +306,10 @@ public function call($method, $uri, $params = []) $params = array_merge($this->requestOptions, $params); if ($this->type == "xml") { + Log::debug('Headers data: ', [ + 'data' => $uri, + ]); + $response = $client->request($method, $uri, $params); // If we got this far, we have a response. @@ -625,7 +630,7 @@ protected function processXmlMappings($arguments, $api): string * @param String $string * * @return String $string - * Remove special characters fomr xml string before request to the api + * Remove special characters form xml string before request to the api */ private function escapeSpecialCharacters(String $string): String @@ -665,7 +670,7 @@ private function checkBool($string) */ protected function maskFieldValues(array &$data, array $paths) { - $dot = new \Adbar\Dot($data); + $dot = new Dot($data); foreach ($paths as $field) { From aa454218d1ee8f643a5c18bc80c58a537fb6287b Mon Sep 17 00:00:00 2001 From: Jay-Ponda-Improwised Date: Mon, 17 Feb 2025 11:04:35 +0530 Subject: [PATCH 07/17] fix whitespace probleam --- dev-docker-compose.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/dev-docker-compose.yaml b/dev-docker-compose.yaml index f438436..f8d35c5 100644 --- a/dev-docker-compose.yaml +++ b/dev-docker-compose.yaml @@ -6,4 +6,3 @@ services: command: sleep infinity volumes: - .:/app - \ No newline at end of file From 6e78a3fc9a0590e60a8e765eeef1ecec5a0cb0ac Mon Sep 17 00:00:00 2001 From: Jay-Ponda-Improwised Date: Mon, 8 Sep 2025 17:24:15 +0530 Subject: [PATCH 08/17] remove deprication warning --- src/ApiBuilder.php | 2 +- src/Helpers/ObfuscationHelper.php | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/ApiBuilder.php b/src/ApiBuilder.php index b45d80b..73f9eab 100644 --- a/src/ApiBuilder.php +++ b/src/ApiBuilder.php @@ -676,7 +676,7 @@ protected function maskFieldValues(array &$data, array $paths) $string = Arr::get($data, $field); - if (stripos($string, '@') !== false) { + if ($string !== null && stripos($string, '@') !== false) { $obfuscatedString = ObfuscationHelper::obfuscate($string, 4); } else { $obfuscatedString = ObfuscationHelper::obfuscate($string, 4); diff --git a/src/Helpers/ObfuscationHelper.php b/src/Helpers/ObfuscationHelper.php index 71df2dc..8e3aeaa 100644 --- a/src/Helpers/ObfuscationHelper.php +++ b/src/Helpers/ObfuscationHelper.php @@ -7,6 +7,11 @@ class ObfuscationHelper public static function obfuscate($string, $visibleChars = 4) { + // Handle null input + if ($string === null) { + return ''; + } + $len = strlen($string); $visible = substr($string, ($visibleChars * -1)); return str_pad($visible, $len, '*', STR_PAD_LEFT); @@ -14,6 +19,11 @@ public static function obfuscate($string, $visibleChars = 4) public static function obfuscateEmail($email) { + // Handle null input + if ($email === null) { + return ''; + } + $em = explode("@", $email); $name = implode('@', array_slice($em, 0, (count($em) - 1))); $len = (strlen($name) - 1); From 42b1ce765ace3df69b114e3daa2b13facd3c56a9 Mon Sep 17 00:00:00 2001 From: Jay-Ponda-Improwised Date: Mon, 8 Sep 2025 17:23:47 +0530 Subject: [PATCH 09/17] fix docker file --- .dockerignore | 6 ++ .gitignore | 3 +- README.md | 10 +-- dev-docker-compose.yaml | 6 +- dev.phpunit.xml | 25 ++++++ develop.Dockerfile | 56 ++++++++++++ developer.README.md | 183 ++++++++++++++++++++++++++++++++++++++++ 7 files changed, 278 insertions(+), 11 deletions(-) create mode 100644 .dockerignore create mode 100644 dev.phpunit.xml create mode 100644 develop.Dockerfile create mode 100644 developer.README.md diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..469cc03 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +vendor/ +Dockerfile +docker-compose.override.yaml +.git +.gitignore +coverage \ No newline at end of file diff --git a/.gitignore b/.gitignore index b5791de..0cbf00c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .DS_Store .phpunit.result.cache -vendor/ \ No newline at end of file +vendor/ +coverage \ No newline at end of file diff --git a/README.md b/README.md index 2bf59bf..cc163ba 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,3 @@ - - - -

@@ -34,12 +30,10 @@ * [Installation](#installation) * [Configuration](#configuration) * [Usage](#usage) - * [Methods](#methods) + * [Methods](#methods) * [Response](#response) - - ## Getting Started This package is useful to consume API's, here is the instruction for installation and usage. @@ -53,7 +47,7 @@ This package is useful to consume API's, here is the instruction for installatio composer require lde/api-helper 3. This command will install package with dependency - + ## Configuration - To use this apihelper need to export config file to do so run the following command in your terminal to publish config file to config folder. diff --git a/dev-docker-compose.yaml b/dev-docker-compose.yaml index f8d35c5..0a1134a 100644 --- a/dev-docker-compose.yaml +++ b/dev-docker-compose.yaml @@ -1,8 +1,10 @@ services: api-helper: - image: circleci/php:7.4 + build: + context: . + dockerfile: develop.Dockerfile container_name: api-helper working_dir: /app - command: sleep infinity volumes: - .:/app + - /app/vendor diff --git a/dev.phpunit.xml b/dev.phpunit.xml new file mode 100644 index 0000000..c594cf9 --- /dev/null +++ b/dev.phpunit.xml @@ -0,0 +1,25 @@ + + + + + tests + + + + + src + + src/Config + + + + \ No newline at end of file diff --git a/develop.Dockerfile b/develop.Dockerfile new file mode 100644 index 0000000..c292b5e --- /dev/null +++ b/develop.Dockerfile @@ -0,0 +1,56 @@ +FROM circleci/php:7.4-cli + +# Install system dependencies +USER root +RUN apt-get update && apt-get install -y \ + git \ + curl \ + libxml2-dev \ + zip \ + unzip + +# Install PHP extensions including PCOV for code coverage +RUN pecl install pcov && \ + docker-php-ext-enable pcov && \ + docker-php-ext-install xml + +# Install Composer +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer + +# Set working directory +WORKDIR /app + +# Copy all files (excluding vendor directory due to .dockerignore) +COPY . . + +# Install dependencies (update if lock file is out of sync) +RUN composer update --no-scripts --prefer-dist --no-autoloader + +# Generate autoload files +RUN composer dump-autoload --optimize + +# Create a script to run composer install when container starts +RUN echo '#!/bin/bash\n\ +echo "Running startup script..."\n\ +git config --global --add safe.directory /app\n\ +composer install\n\ +echo "Starting container..."\n\ +sleep infinity' > /start.sh && chmod +x /start.sh + +# Create a wrapper script for running tests with coverage +RUN echo '#!/bin/bash\n\ +# Disable Xdebug by default for better performance\n\ +export PHP_IDE_CONFIG=\n\ +\n\ +# Enable Xdebug only when needed for coverage\n\ +if [ "$1" = "coverage" ]; then\n\ + echo "Enabling Xdebug for coverage report..."\n\ + php -d xdebug.mode=coverage ./vendor/bin/phpunit --configuration dev.phpunit.xml --coverage-html=coverage\n\ +else\n\ + # Run tests without Xdebug for better performance\n\ + echo "Running tests without Xdebug for better performance..."\n\ + php -n -d extension=/usr/local/lib/php/extensions/no-debug-non-zts-20190902/pcov.so ./vendor/bin/phpunit --configuration dev.phpunit.xml\n\ +fi' > /usr/local/bin/run-tests.sh && chmod +x /usr/local/bin/run-tests.sh + +# Keep container running +CMD ["/start.sh"] \ No newline at end of file diff --git a/developer.README.md b/developer.README.md new file mode 100644 index 0000000..73f3e04 --- /dev/null +++ b/developer.README.md @@ -0,0 +1,183 @@ + +
+

+ + Logo + + +

Api Helper Package - Developer Guide

+ +

+ A package to consume api smoothly +
+ Explore the docs » +
+
+ View Package + · + Report Bug + · + Request Feature +

+

+ + + + +## Table of Contents + +* [Getting Started](#getting-started) +* [Installation](#installation) +* [Configuration](#configuration) +* [Usage](#usage) + * [Methods](#methods) +* [Response](#response) +* [Docker Development Setup](#docker-development-setup) + * [Prerequisites](#prerequisites) + * [Getting Started](#getting-started-1) + * [Volume Mounting](#volume-mounting) + * [Running Tests](#running-tests) + * [Running Tests with Coverage](#running-tests-with-coverage) + * [Development Workflow](#development-workflow) + + +## Getting Started + +This package is useful to consume API's, here is the instruction for installation and usage. + +## Installation + +1. To install this package using [Packagist](https://packagist.org/packages/lde/api-helper) + +2. On the root of your project run following command + + composer require lde/api-helper + +3. This command will install package with dependency + +## Configuration + +- To use this apihelper need to export config file to do so run the following command in your terminal to publish config file to config folder. + + php artisan vendor:publish --provider="Lde\ApiHelper\ApiHelperServiceProvider" + +- This will publish config file naming **api_helper.php** into config folder. + +## Prometheus Configuration +- Prometheus is dependent on your app so you need to provide prometheus configuration and also use below packages on your app. + + - [jimdo/prometheus_client_php](https://github.com/Jimdo/prometheus_client_php) + - [superbalist/laravel-prometheus-exporter](https://github.com/Superbalist/laravel-prometheus-exporter) +- If you want to use prometheus then you should turn it on from config [api_helper](src/Config/api_helper.php) +```php +'log_stats' => true, // If you want to use prometheus then set as true otherwise false + + 'prometheus' => [ + 'labels' => [ + 'client_id' => 10, + 'app' => 'api-helper', + 'source' => 'core', + ], + 'histogram_bucket' => [0.1, 0.25, 0.5, 0.75, 1.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 7.5, 10.0], + ], +``` +- You can configure labels of prometheus inside `prometheus.labels` as per your need. +- `histogram_bucket` you can set inside prometheus config as array. + +## Usage + +- To use this package you need to add following class where you want to use this package. + + use Lde\ApiHelper\ApiBuilder; + + +### Methods + +#### addHeaders($headers) + +- This method is use to add headers. + +- It accept name and value as parameter, Here you can set only one header at a time. + + + $headers['Accept'] = "application/json"; + $headers['Content-Type'] = "application/json"; + app(ApiBuilder::class)->addHeaders($headers); + +- We will get response in form of object of ApiBuilder. + + +#### api($connection) + +- This method is use to set api that we are going to use from *api_helper.php* , there is httpbin and mokbin is define so you have to pass the name that you want to use. + +- You can also define your own api end point at *api_helper.php* in config file. + + app(ApiBuilder::class)->api('httpbin')->method_to_call(); + +- The snippet indicates how you can connect particular api and access their method. + +- method_to_call() is the function that you have specified inside *api_helper* connection array. + +- This will return object of ApiResponse. + +### Response + +- Here you will get object in response, In each response you will get success either true or false +- You will also get status code for more information about response please check below doc. +- http://docs.guzzlephp.org/en/latest/psr7.html#responses + +## Docker Development Setup + +This package includes a Docker development environment for easier testing and development. + +### Prerequisites + +- Docker and Docker Compose installed on your system + +### Getting Started + +1. Build and start the Docker container: + ```bash + docker-compose -f dev-docker-compose.yaml up -d + ``` + +2. Enter the container to work with the code: + ```bash + docker exec -it api-helper bash + ``` + +3. Inside the container, the package will automatically install dependencies using Composer on first run. + +### Volume Mounting + +The current directory is mounted to `/app` in the container. The `vendor` directory is excluded from the volume mount to prevent conflicts between host and container dependencies. + +### Running Tests + +You can run the PHPUnit tests using our optimized wrapper script: + +```bash +docker exec api-helper /usr/local/bin/run-tests.sh +``` + +The tests run without Xdebug by default for better performance. PCOV is used for code coverage collection when needed. +The tests use the `dev.phpunit.xml` configuration file which is optimized for the Docker development environment. + +### Running Tests with Coverage + +To run tests with code coverage reporting: + +```bash +docker exec api-helper /usr/local/bin/run-tests.sh coverage +``` + +This will generate an HTML coverage report in the `coverage` directory, which you can view by opening `coverage/index.html` in a web browser. + +Note: Coverage reports require Xdebug to be enabled, which will slow down test execution. For regular development, use the standard test command for better performance. + +### Development Workflow + +1. Make changes to the code on your host machine +2. The changes will be immediately reflected in the container +3. Run tests or other commands inside the container as needed \ No newline at end of file From 4844dd8b12d3915aa1ed3a3e482a110e488283e5 Mon Sep 17 00:00:00 2001 From: Jay-Ponda-Improwised Date: Mon, 8 Sep 2025 18:45:55 +0530 Subject: [PATCH 10/17] fix whitespace issue --- .dockerignore | 2 +- .gitignore | 2 +- dev.phpunit.xml | 2 +- develop.Dockerfile | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.dockerignore b/.dockerignore index 469cc03..6a0ec2f 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,4 +3,4 @@ Dockerfile docker-compose.override.yaml .git .gitignore -coverage \ No newline at end of file +coverage diff --git a/.gitignore b/.gitignore index 0cbf00c..76c5d31 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ .phpunit.result.cache vendor/ -coverage \ No newline at end of file +coverage diff --git a/dev.phpunit.xml b/dev.phpunit.xml index c594cf9..5877a78 100644 --- a/dev.phpunit.xml +++ b/dev.phpunit.xml @@ -22,4 +22,4 @@ - \ No newline at end of file + diff --git a/develop.Dockerfile b/develop.Dockerfile index c292b5e..585eed7 100644 --- a/develop.Dockerfile +++ b/develop.Dockerfile @@ -53,4 +53,4 @@ else\n\ fi' > /usr/local/bin/run-tests.sh && chmod +x /usr/local/bin/run-tests.sh # Keep container running -CMD ["/start.sh"] \ No newline at end of file +CMD ["/start.sh"] From fc15a23e7bd701bea64c3190baf0de3177dcabbb Mon Sep 17 00:00:00 2001 From: Jay-Ponda-Improwised Date: Mon, 8 Sep 2025 18:48:03 +0530 Subject: [PATCH 11/17] remove unwanted items from dockerignore --- .dockerignore | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.dockerignore b/.dockerignore index 6a0ec2f..8c80880 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,2 @@ vendor/ -Dockerfile -docker-compose.override.yaml -.git -.gitignore coverage From 1d135623f528047b24e05ea50de9e707dd735a2b Mon Sep 17 00:00:00 2001 From: Jay-Ponda-Improwised Date: Tue, 9 Sep 2025 15:02:48 +0530 Subject: [PATCH 12/17] rename files to have develop prefix --- dev-docker-compose.yaml => develop-docker-compose.yaml | 0 develop.Dockerfile | 4 ++-- dev.phpunit.xml => develop.phpunit.xml | 0 developer.README.md | 4 ++-- 4 files changed, 4 insertions(+), 4 deletions(-) rename dev-docker-compose.yaml => develop-docker-compose.yaml (100%) rename dev.phpunit.xml => develop.phpunit.xml (100%) diff --git a/dev-docker-compose.yaml b/develop-docker-compose.yaml similarity index 100% rename from dev-docker-compose.yaml rename to develop-docker-compose.yaml diff --git a/develop.Dockerfile b/develop.Dockerfile index 585eed7..8558cc4 100644 --- a/develop.Dockerfile +++ b/develop.Dockerfile @@ -45,11 +45,11 @@ export PHP_IDE_CONFIG=\n\ # Enable Xdebug only when needed for coverage\n\ if [ "$1" = "coverage" ]; then\n\ echo "Enabling Xdebug for coverage report..."\n\ - php -d xdebug.mode=coverage ./vendor/bin/phpunit --configuration dev.phpunit.xml --coverage-html=coverage\n\ + php -d xdebug.mode=coverage ./vendor/bin/phpunit --configuration develop.phpunit.xml --coverage-html=coverage\n\ else\n\ # Run tests without Xdebug for better performance\n\ echo "Running tests without Xdebug for better performance..."\n\ - php -n -d extension=/usr/local/lib/php/extensions/no-debug-non-zts-20190902/pcov.so ./vendor/bin/phpunit --configuration dev.phpunit.xml\n\ + php -n -d extension=/usr/local/lib/php/extensions/no-debug-non-zts-20190902/pcov.so ./vendor/bin/phpunit --configuration develop.phpunit.xml\n\ fi' > /usr/local/bin/run-tests.sh && chmod +x /usr/local/bin/run-tests.sh # Keep container running diff --git a/dev.phpunit.xml b/develop.phpunit.xml similarity index 100% rename from dev.phpunit.xml rename to develop.phpunit.xml diff --git a/developer.README.md b/developer.README.md index 73f3e04..f9b5ff3 100644 --- a/developer.README.md +++ b/developer.README.md @@ -139,7 +139,7 @@ This package includes a Docker development environment for easier testing and de 1. Build and start the Docker container: ```bash - docker-compose -f dev-docker-compose.yaml up -d + docker-compose -f develop-docker-compose.yaml up -d ``` 2. Enter the container to work with the code: @@ -162,7 +162,7 @@ docker exec api-helper /usr/local/bin/run-tests.sh ``` The tests run without Xdebug by default for better performance. PCOV is used for code coverage collection when needed. -The tests use the `dev.phpunit.xml` configuration file which is optimized for the Docker development environment. +The tests use the `develop.phpunit.xml` configuration file which is optimized for the Docker development environment. ### Running Tests with Coverage From a515ac5d211f92d44fcdc3304deb714f018c7e33 Mon Sep 17 00:00:00 2001 From: Jay-Ponda-Improwised Date: Tue, 9 Sep 2025 15:17:17 +0530 Subject: [PATCH 13/17] added direct alias for test and coverage, so without going to image; test can run --- develop.Dockerfile | 6 ++++++ developer.README.md | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/develop.Dockerfile b/develop.Dockerfile index 8558cc4..2eb8742 100644 --- a/develop.Dockerfile +++ b/develop.Dockerfile @@ -52,5 +52,11 @@ else\n\ php -n -d extension=/usr/local/lib/php/extensions/no-debug-non-zts-20190902/pcov.so ./vendor/bin/phpunit --configuration develop.phpunit.xml\n\ fi' > /usr/local/bin/run-tests.sh && chmod +x /usr/local/bin/run-tests.sh +# Create executable scripts for easier test command execution +RUN echo '#!/bin/bash\n\ +/usr/local/bin/run-tests.sh "$@"' > /usr/local/bin/test && chmod +x /usr/local/bin/test && \ +echo '#!/bin/bash\n\ +/usr/local/bin/run-tests.sh coverage "$@"' > /usr/local/bin/test-coverage && chmod +x /usr/local/bin/test-coverage + # Keep container running CMD ["/start.sh"] diff --git a/developer.README.md b/developer.README.md index f9b5ff3..3e7e8d8 100644 --- a/developer.README.md +++ b/developer.README.md @@ -176,6 +176,28 @@ This will generate an HTML coverage report in the `coverage` directory, which yo Note: Coverage reports require Xdebug to be enabled, which will slow down test execution. For regular development, use the standard test command for better performance. +### Using Test Aliases + +For convenience, the Docker container includes executable scripts for running tests: + +```bash +# Run tests without coverage (faster) +docker-compose -f develop-docker-compose.yaml exec api-helper test + +# Run tests with coverage report +docker-compose -f develop-docker-compose.yaml exec api-helper test-coverage +``` + +These commands can be run directly from your host machine without entering the container. + +You can also use them inside the container: + +```bash +docker exec -it api-helper bash +test # Run tests without coverage +test-coverage # Run tests with coverage +``` + ### Development Workflow 1. Make changes to the code on your host machine From 9d6d219fb881ea2fbbed2169e2c95d08460d90cd Mon Sep 17 00:00:00 2001 From: Jay-Ponda-Improwised Date: Wed, 12 Nov 2025 13:39:52 +0530 Subject: [PATCH 14/17] feat: make install at build time --- developer.README.md => CODE_OF_CODNUCT.md | 0 develop.Dockerfile | 5 +++-- 2 files changed, 3 insertions(+), 2 deletions(-) rename developer.README.md => CODE_OF_CODNUCT.md (100%) diff --git a/developer.README.md b/CODE_OF_CODNUCT.md similarity index 100% rename from developer.README.md rename to CODE_OF_CODNUCT.md diff --git a/develop.Dockerfile b/develop.Dockerfile index 2eb8742..56768d0 100644 --- a/develop.Dockerfile +++ b/develop.Dockerfile @@ -1,4 +1,4 @@ -FROM circleci/php:7.4-cli +FROM cimg/php:8.3 # Install system dependencies USER root @@ -33,7 +33,6 @@ RUN composer dump-autoload --optimize RUN echo '#!/bin/bash\n\ echo "Running startup script..."\n\ git config --global --add safe.directory /app\n\ -composer install\n\ echo "Starting container..."\n\ sleep infinity' > /start.sh && chmod +x /start.sh @@ -58,5 +57,7 @@ RUN echo '#!/bin/bash\n\ echo '#!/bin/bash\n\ /usr/local/bin/run-tests.sh coverage "$@"' > /usr/local/bin/test-coverage && chmod +x /usr/local/bin/test-coverage +RUN composer install + # Keep container running CMD ["/start.sh"] From 0f5b1844e586f5a8922f96f095a31dc93a4a9867 Mon Sep 17 00:00:00 2001 From: Jay-Ponda-Improwised Date: Wed, 12 Nov 2025 16:16:29 +0530 Subject: [PATCH 15/17] feat: added fix version, remove update --- .vscode/settings.json | 8 ++++++++ develop.Dockerfile | 11 ++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..95df7fe --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,8 @@ +{ + "cSpell.words": [ + "cimg", + "PCOV", + "pecl", + "phpunit" + ] +} \ No newline at end of file diff --git a/develop.Dockerfile b/develop.Dockerfile index 56768d0..057385b 100644 --- a/develop.Dockerfile +++ b/develop.Dockerfile @@ -15,20 +15,23 @@ RUN pecl install pcov && \ docker-php-ext-install xml # Install Composer -COPY --from=composer:latest /usr/bin/composer /usr/bin/composer +COPY --from=composer:2.8.12 /usr/bin/composer /usr/bin/composer # Set working directory WORKDIR /app # Copy all files (excluding vendor directory due to .dockerignore) -COPY . . +COPY composer.json composer.lock ./ # Install dependencies (update if lock file is out of sync) -RUN composer update --no-scripts --prefer-dist --no-autoloader +RUN composer install --no-dev --optimize-autoloader --no-scripts # Generate autoload files RUN composer dump-autoload --optimize +# Copy other files and directories +COPY . . + # Create a script to run composer install when container starts RUN echo '#!/bin/bash\n\ echo "Running startup script..."\n\ @@ -57,7 +60,5 @@ RUN echo '#!/bin/bash\n\ echo '#!/bin/bash\n\ /usr/local/bin/run-tests.sh coverage "$@"' > /usr/local/bin/test-coverage && chmod +x /usr/local/bin/test-coverage -RUN composer install - # Keep container running CMD ["/start.sh"] From 89bfd7132d3cd4e0ef4c62f4b6f83e3041bb5a0d Mon Sep 17 00:00:00 2001 From: Jay-Ponda-Improwised Date: Wed, 12 Nov 2025 16:27:46 +0530 Subject: [PATCH 16/17] feat: update main config to run php 8.1 --- .circleci/config.yml | 6 +++--- .vscode/settings.json | 1 + develop.Dockerfile | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 90bab92..520e76e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -19,12 +19,12 @@ workflows: version: 2 build: jobs: - - php74-laravel80 + - php81-laravel9 jobs: - php74-laravel80: + php81-laravel9: docker: - - image: circleci/php:7.4 + - image: cimg/php:8.1 steps: - install_and_test: laravel: 8.0.* diff --git a/.vscode/settings.json b/.vscode/settings.json index 95df7fe..f2d64f1 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,7 @@ { "cSpell.words": [ "cimg", + "laravel", "PCOV", "pecl", "phpunit" diff --git a/develop.Dockerfile b/develop.Dockerfile index 057385b..a454691 100644 --- a/develop.Dockerfile +++ b/develop.Dockerfile @@ -1,4 +1,4 @@ -FROM cimg/php:8.3 +FROM cimg/php:8.1 # Install system dependencies USER root From 7932cf9c1b7eda8f6b96cbf301a42a700af9af78 Mon Sep 17 00:00:00 2001 From: Jay-Ponda-Improwised Date: Wed, 12 Nov 2025 16:32:40 +0530 Subject: [PATCH 17/17] feat: change larabel version --- .circleci/config.yml | 3 ++- .vscode/settings.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 520e76e..deb42e8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -27,4 +27,5 @@ jobs: - image: cimg/php:8.1 steps: - install_and_test: - laravel: 8.0.* + laravel: 9.0.* + diff --git a/.vscode/settings.json b/.vscode/settings.json index f2d64f1..3bde711 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,4 +6,4 @@ "pecl", "phpunit" ] -} \ No newline at end of file +}