Skip to content

Commit

Permalink
Merge pull request #9 from n4ss1m/ci_tests_improve
Browse files Browse the repository at this point in the history
improve composer test scripts
  • Loading branch information
n4ss1m authored Feb 2, 2025
2 parents 4fe37b9 + a8aadf6 commit 933757f
Show file tree
Hide file tree
Showing 15 changed files with 87 additions and 96 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Path-based git attributes
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html

# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto

# Ignore all test and documentation with "export-ignore".
/.github export-ignore
/.gitattributes export-ignore
Expand Down
28 changes: 0 additions & 28 deletions .github/workflows/fix-php-code-style-issues.yml

This file was deleted.

28 changes: 14 additions & 14 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
name: Tests

on:
push:
paths:
- '**.php'
- '.github/workflows/run-tests.yml'
- 'phpunit.xml.dist'
- 'composer.json'
- 'composer.lock'
pull_request:
branches: [ "*" ]
branches: [ "main" ]
push:
branches: [ "main" ]

jobs:
test:
Expand All @@ -18,7 +13,7 @@ jobs:
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
os: [ubuntu-latest]
php: [8.2, 8.3, 8.4]
stability: [prefer-lowest, prefer-stable]

Expand All @@ -33,7 +28,10 @@ jobs:
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
coverage: none
coverage: xdebug

- name: Validate composer.json
run: composer validate --strict

- name: Setup problem matchers
run: |
Expand All @@ -46,8 +44,10 @@ jobs:
- name: List Installed Dependencies
run: composer show -D

- name: PHPStan Analyse
run: composer analyse

- name: Execute tests
run: vendor/bin/pest
run: composer test

- name: Upload coverage results to Coveralls
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: vendor/bin/php-coveralls -v --coverage_clover=build/logs/clover.xml
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ testbench.yaml
/docs
/coverage
/demo
.coveralls.yml
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<img src="https://banners.beyondco.de/CourierDZ.png?theme=light&packageManager=composer+require&packageName=piteurstudio%2Fcourierdz&pattern=architect&style=style_1&description=Simplify+the+integration+of+Algerian+shipping+providers+into+your+applications&md=1&showWatermark=1&fontSize=100px&images=https%3A%2F%2Fwww.php.net%2Fimages%2Flogos%2Fnew-php-logo.svg&widths=300&heights=auto" alt="CourierDZ Banner" />

[![Latest Version on Packagist](https://img.shields.io/packagist/v/piteurstudio/courierdz.svg?style=flat-square)](https://packagist.org/packages/piteurstudio/courierdz)
[![Tests](https://img.shields.io/github/actions/workflow/status/piteurstudio/courierdz/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/piteurstudio/courierdz/actions/workflows/run-tests.yml)
[![Total Downloads](https://img.shields.io/packagist/dt/piteurstudio/courierdz.svg?style=flat-square)](https://packagist.org/packages/piteurstudio/courierdz)
<p align="center">
<a href="https://php.net"><img src="https://img.shields.io/badge/PHP-8.2-777BB4?logo=php" alt="PHP 8.2"></a>
<a href="https://packagist.org/packages/piteurstudio/courierdz"><img src="https://img.shields.io/packagist/v/piteurstudio/courierdz.svg?style=flat-square" alt="Latest Version on Packagist"></a>
<a href="https://github.com/piteurstudio/courierdz/actions/workflows/run-tests.yml"><img src="https://img.shields.io/github/actions/workflow/status/piteurstudio/courierdz/run-tests.yml?branch=main&amp;label=tests&amp;style=flat-square" alt="Tests"></a>
<a href="https://coveralls.io/github/PiteurStudio/CourierDZ?branch=main"><img src="https://coveralls.io/repos/github/PiteurStudio/CourierDZ/badge.svg?branch=main" alt="Coverage Status"></a>
<a href="https://packagist.org/packages/piteurstudio/courierdz"><img src="https://img.shields.io/packagist/dt/piteurstudio/courierdz.svg?style=flat-square" alt="Total Downloads"></a>
</p>

# CourierDZ

Expand Down
22 changes: 16 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
"illuminate/validation": "^9|^10|^11"
},
"require-dev": {
"laravel/pint": "^1.0",
"laravel/pint": "^1.20.0",
"mockery/mockery": "^1.6",
"pestphp/pest": "^1.0|^2.0|^3.0",
"pestphp/pest": "^2.20 || ^3.0",
"php-coveralls/php-coveralls": "^2.7.0",
"phpstan/phpstan": "^2.0",
"rector/rector": "^2.0",
"spatie/ray": "^1.28"
},
"autoload": {
Expand All @@ -51,10 +53,18 @@
}
},
"scripts": {
"test": "vendor/bin/pest",
"test-coverage": "vendor/bin/pest --coverage",
"analyse": "vendor/bin/phpstan",
"format": "vendor/bin/pint"
"lint": "pint",
"refactor": "rector",
"test:unit": "pest --coverage --min=25",
"test:lint": "pint --test",
"test:refactor": "rector --dry-run",
"test:types": "phpstan",
"test": [
"@test:unit",
"@test:lint",
"@test:types",
"@test:refactor"
]
},
"config": {
"sort-packages": true,
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
backupStaticProperties="false"
>
<testsuites>
<testsuite name="PiteurStudio Test Suite">
<testsuite name="Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
Expand Down
12 changes: 12 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;

return RectorConfig::configure()
->withPaths([
__DIR__.'/src',
__DIR__.'/tests',
])
->withPhpSets();
28 changes: 12 additions & 16 deletions src/ProviderIntegrations/EcotrackProviderIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,20 @@ public function testCredentials(): bool
];

// Make the GET request
$response = $client->request('GET', $this->apiDomain().'api/v1/get/wilayas', [
$response = $client->request('GET', static::apiDomain().'api/v1/get/wilayas', [
'headers' => $headers,
'Content-Type' => 'application/json',
]);

// Check the status code
switch ($response->getStatusCode()) {
case 200:
// If the request is successful, return true
return true;
case 401:
case 403:
// If the request returns a 401 or 403 status code, return false
return false;
default:
// If the request returns any other status code, throw an HttpException
throw new HttpException('Ecotrack '.$this->metadata()['name'].', Unexpected error occurred.');
}
return match ($response->getStatusCode()) {
// If the request is successful, return true
200 => true,
// If the request returns a 401 or 403 status code, return false
401, 403 => false,
// If the request returns any other status code, throw an HttpException
default => throw new HttpException('Ecotrack '.static::metadata()['name'].', Unexpected error occurred.'),
};
} catch (GuzzleException $e) {
// Handle exceptions
throw new HttpException($e->getMessage());
Expand All @@ -134,7 +130,7 @@ public function getRates(?int $from_wilaya_id, ?int $to_wilaya_id): array
];

// Make the GET request
$response = $client->request('GET', $this->apiDomain().'api/v1/get/fees', [
$response = $client->request('GET', static::apiDomain().'api/v1/get/fees', [
'headers' => $headers,
'Content-Type' => 'application/json',
]);
Expand Down Expand Up @@ -200,7 +196,7 @@ public function createOrder(array $orderData): array
];

// Make the POST request
$request = new Request('POST', $this->apiDomain().'api/v1/create/order', $headers, $requestBody);
$request = new Request('POST', static::apiDomain().'api/v1/create/order', $headers, $requestBody);

$response = $client->send($request);

Expand Down Expand Up @@ -239,7 +235,7 @@ public function orderLabel(string $orderId): array
];

// Make the GET request
$response = $client->request('GET', $this->apiDomain().'api/v1/get/order/label?tracking='.$orderId, [
$response = $client->request('GET', static::apiDomain().'api/v1/get/order/label?tracking='.$orderId, [
'headers' => $headers,
'Content-Type' => 'application/json',
]);
Expand Down
19 changes: 8 additions & 11 deletions src/ProviderIntegrations/ProcolisProviderIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,14 @@ public function testCredentials(): bool
$data = json_decode($body, true);

// Check the status code
switch ($response->getStatusCode()) {
case 200:
// If the request is successful, return true
return $data['Statut'] === 'Accès activé';
case 401:
// If the request returns a 401 status code, return false
return false;
default:
// If the request returns any other status code, throw an HttpException
throw new HttpException('Procolis, Unexpected error occurred.');
}
return match ($response->getStatusCode()) {
// If the request is successful, return true
200 => $data['Statut'] === 'Accès activé',
// If the request returns a 401 status code, return false
401 => false,
// If the request returns any other status code, throw an HttpException
default => throw new HttpException('Procolis, Unexpected error occurred.'),
};
} catch (GuzzleException $e) {
// Handle exceptions
throw new HttpException($e->getMessage());
Expand Down
6 changes: 3 additions & 3 deletions src/ProviderIntegrations/YalidineProviderIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function testCredentials(): bool
];

// Make the GET request
$response = $client->request('GET', $this->apiDomain().'/v1/wilayas/', [
$response = $client->request('GET', static::apiDomain().'/v1/wilayas/', [
'headers' => $headers,
]);

Expand Down Expand Up @@ -149,7 +149,7 @@ public function getRates($from_wilaya_id, $to_wilaya_id): array
];

// Make the GET request
$response = $client->request('GET', $this->apiDomain().'/v1/fees/?from_wilaya_id='.$from_wilaya_id.'&to_wilaya_id='.$to_wilaya_id, [
$response = $client->request('GET', static::apiDomain().'/v1/fees/?from_wilaya_id='.$from_wilaya_id.'&to_wilaya_id='.$to_wilaya_id, [
'headers' => $headers,
]);

Expand Down Expand Up @@ -191,7 +191,7 @@ public function createOrder(array $orderData): array
throw new CreateOrderException('Create Order failed : JSON encoding error');
}

$request = new Request('POST', $this->apiDomain().'/v1/parcels/', $headers, $requestBody);
$request = new Request('POST', static::apiDomain().'/v1/parcels/', $headers, $requestBody);

$response = $client->send($request);

Expand Down
2 changes: 1 addition & 1 deletion src/Services/ShippingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class ShippingService
{
private ShippingProviderContract $provider;
private readonly ShippingProviderContract $provider;

/**
* Create a new ShippingService instance for the given provider.
Expand Down
20 changes: 8 additions & 12 deletions src/ShippingProviders/MaystroDeliveryProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,14 @@ public function testCredentials(): bool
]);

// Check the status code
switch ($response->getStatusCode()) {
case 200:
// If the request is successful, return true
return true;
case 401:
case 403:
// If the request returns a 401 or 403 status code, return false
return false;
default:
// If the request returns any other status code, throw an HttpException
throw new HttpException($this->metadata()['name'].', Unexpected error occurred.');
}
return match ($response->getStatusCode()) {
// If the request is successful, return true
200 => true,
// If the request returns a 401 or 403 status code, return false
401, 403 => false,
// If the request returns any other status code, throw an HttpException
default => throw new HttpException(static::metadata()['name'].', Unexpected error occurred.'),
};
} catch (GuzzleException $e) {
// Handle exceptions
throw new HttpException($e->getMessage());
Expand Down
2 changes: 1 addition & 1 deletion src/Support/ValidatorSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ValidatorSetup
public static function makeValidator(?string $langPath = null, string $locale = 'fr'): ValidatorFactory
{
// Step 1: Set default language files directory
$langPath = $langPath ?? __DIR__.'/lang';
$langPath ??= __DIR__.'/lang';

// Step 2: Create a FileLoader instance to load language files
// The FileLoader is responsible for loading language files from the specified directory
Expand Down
File renamed without changes.

0 comments on commit 933757f

Please sign in to comment.