• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PiteurStudio / CourierDZ / 13101540250

02 Feb 2025 06:49PM UTC coverage: 26.042%. First build
13101540250

push

github

web-flow
Merge pull request #9 from n4ss1m/ci_tests_improve

improve composer test scripts

1 of 23 new or added lines in 5 files covered. (4.35%)

100 of 384 relevant lines covered (26.04%)

3.42 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

28.57
/src/ShippingProviders/MaystroDeliveryProvider.php
1
<?php
2

3
namespace CourierDZ\ShippingProviders;
4

5
use CourierDZ\Contracts\ShippingProviderContract;
6
use CourierDZ\Exceptions\CredentialsException;
7
use CourierDZ\Exceptions\HttpException;
8
use CourierDZ\Exceptions\NotImplementedException;
9
use CourierDZ\Support\ShippingProviderValidation;
10
use GuzzleHttp\Client;
11
use GuzzleHttp\Exception\GuzzleException;
12

13
class MaystroDeliveryProvider implements ShippingProviderContract
14
{
15
    use ShippingProviderValidation;
16

17
    /**
18
     * Provider credentials
19
     */
20
    protected array $credentials;
21

22
    /**
23
     * Validation rules for creating an order
24
     */
25
    public array $getCreateOrderValidationRules = [
26

27
    ];
28

29
    /**
30
     * Constructor
31
     *
32
     * @throws CredentialsException
33
     */
34
    public function __construct(array $credentials)
35
    {
36
        // Get the provider name from the metadata
37
        $provider_name = static::metadata()['name'];
×
38

39
        // Check if the credentials are valid
40
        if (! isset($credentials['token'])) {
×
41
            throw new CredentialsException($provider_name.' credentials must "token".');
×
42
        }
43

44
        // Set the credentials
45
        $this->credentials = $credentials;
×
46
    }
47

48
    /**
49
     * The metadata for the provider.
50
     */
51
    public static function metadata(): array
52
    {
53
        return [
12✔
54
            'name' => 'MaystroDelivery',
12✔
55
            'title' => 'Maystro Delivery',
12✔
56
            'logo' => 'https://maystro-delivery.com/img/Maystro-blue-extonly.svg',
12✔
57
            'description' => 'Maystro Delivery société de livraison en Algérie offre un service de livraison rapide et sécurisé .',
12✔
58
            'website' => 'https://maystro-delivery.com/',
12✔
59
            'api_docs' => null,
12✔
60
            'support' => 'https://maystro-delivery.com/ContactUS.html',
12✔
61
            'tracking_url' => 'https://maystro-delivery.com/trackingSD.html',
12✔
62
        ];
12✔
63
    }
64

65
    /**
66
     * Test the credentials
67
     *
68
     * This method tests the credentials by making a GET request
69
     * to the Maystro Delivery API to retrieve the list of wilayas.
70
     *
71
     * If the request is successful, the method returns true.
72
     * If the request returns a 401 or 403 status code, the method returns false.
73
     * If the request returns any other status code, the method throws an HttpException.
74
     *
75
     * @throws HttpException If the request fails
76
     */
77
    public function testCredentials(): bool
78
    {
79
        try {
80
            // Initialize Guzzle client
81
            $client = new Client(['http_errors' => false]);
×
82

83
            // Define the headers
84
            $headers = [
×
85
                'Authorization' => "Token {$this->credentials['token']}",
×
86
            ];
×
87

88
            // Make the GET request
89
            $response = $client->request('GET', 'https://b.maystro-delivery.com/api/base/wilayas/?country=1', [
×
90
                'headers' => $headers,
×
91
                'Content-Type' => 'application/json',
×
92
            ]);
×
93

94
            // Check the status code
NEW
95
            return match ($response->getStatusCode()) {
×
96
                // If the request is successful, return true
NEW
97
                200 => true,
×
98
                // If the request returns a 401 or 403 status code, return false
NEW
99
                401, 403 => false,
×
100
                // If the request returns any other status code, throw an HttpException
NEW
101
                default => throw new HttpException(static::metadata()['name'].', Unexpected error occurred.'),
×
NEW
102
            };
×
103
        } catch (GuzzleException $e) {
×
104
            // Handle exceptions
105
            throw new HttpException($e->getMessage());
×
106
        }
107
    }
108

109
    public function getRates(?int $from_wilaya_id, ?int $to_wilaya_id): array
110
    {
111
        throw new NotImplementedException('Not implemented');
×
112
    }
113

114
    public function getCreateOrderValidationRules(): array
115
    {
116
        return $this->getCreateOrderValidationRules;
×
117
    }
118

119
    public function createOrder(array $orderData): array
120
    {
121
        throw new NotImplementedException('Not implemented');
×
122
    }
123

124
    public function getOrder(string $trackingId): array
125
    {
126
        throw new NotImplementedException('Not implemented');
×
127
    }
128

129
    public function orderLabel(string $orderId): array
130
    {
131
        throw new NotImplementedException('Not implemented');
×
132
    }
133

134
    public function validateCreate(array $data): bool
135
    {
136
        throw new NotImplementedException('Not implemented');
×
137
    }
138
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc