Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.

Commit c492889

Browse files
Refactor test classes and update dependencies
Adjusted test class syntax for consistency and readability. Removed unused helper methods and improved inline documentation. Updated PHP CS Fixer and made adjustments to composer.json scripts for better environment handling.
1 parent f85bdd6 commit c492889

File tree

10 files changed

+99
-37
lines changed

10 files changed

+99
-37
lines changed

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@
1919
],
2020
"scripts": {
2121
"test": [
22-
"composer test:unit",
23-
"composer test:phpstan"
22+
"@test:unit",
23+
"@test:phpstan"
2424
],
2525
"test:unit": "./vendor/bin/pest",
2626
"test:coverage": "./vendor/bin/pest --coverage --coverage-clover coverage.xml",
2727
"test:phpstan": "./vendor/bin/phpstan analyse -c phpstan.neon",
28-
"lint": "./vendor/bin/php-cs-fixer fix --rules=@PSR12 ."
28+
"lint": "PHP_CS_FIXER_IGNORE_ENV=1 ./vendor/bin/php-cs-fixer fix --rules=@PSR12 ."
2929
},
3030
"require": {
3131
"php": "^8.3|^8.4",
32-
"friendsofphp/php-cs-fixer": "^3.65",
32+
"friendsofphp/php-cs-fixer": "^3.68",
3333
"guzzlehttp/guzzle": "^7.9",
3434
"nesbot/carbon": "^3.8",
3535
"doctrine/inflector": "^2.0",

src/Enums/ApiPathEnum.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace UnitPhpSdk\Enums;
4+
5+
enum ApiPathEnum: string
6+
{
7+
case UNIT = '/unit';
8+
case CONFIG = '/config';
9+
case ROUTES = '/config/routes';
10+
case APPLICATIONS = '/config/applications';
11+
case LISTENERS = '/config/listeners';
12+
case UPSTREAMS = '/config/upstreams';
13+
case ROUTE = '/config/routes/{route}';
14+
case APPLICATION = '/config/applications/{application}';
15+
case LISTENER = '/config/listeners/{listener}';
16+
case UPSTREAM = '/config/upstreams/{upstream}';
17+
case CERTIFICATES = '/certificates';
18+
case CERTIFICATE = '/certificates/{certificate}';
19+
case STATUS = '/status';
20+
21+
case ACCESS_LOG = '/config/access_log';
22+
}

src/Http/UnitHttpClient.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace UnitPhpSdk\Http;
4+
5+
use GuzzleHttp\Client;
6+
use GuzzleHttp\ClientInterface;
7+
8+
class UnitHttpClient
9+
{
10+
private ClientInterface $client;
11+
12+
public function __construct(
13+
/**
14+
* Base URL for requests
15+
*
16+
* @var string
17+
*/
18+
private readonly string $baseUrl,
19+
private readonly ?string $socket = null,
20+
?ClientInterface $client = null
21+
) {
22+
$this->client = $client ?? new Client([
23+
'base_uri' => $this->baseUrl,
24+
'curl' => $this->socket ? [
25+
CURLOPT_UNIX_SOCKET_PATH => $this->socket
26+
] : []
27+
]);
28+
}
29+
30+
public function request(string $method, string $uri, array $options = [])
31+
{
32+
33+
}
34+
35+
// /**
36+
// * @param string $address
37+
// * @return string
38+
// */
39+
// private function parseAddress(string $address): string
40+
// {
41+
// $scheme = parse_url($address, PHP_URL_SCHEME);
42+
// $host = parse_url($address, PHP_URL_HOST);
43+
// $port = parse_url($address, PHP_URL_PORT);
44+
//
45+
// $address = "$scheme://$host";
46+
//
47+
// if ($port) {
48+
// $address .= ":$port";
49+
// }
50+
//
51+
// return $address;
52+
// }
53+
}

src/helpers.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,3 @@ function parse_listener_pass(string $string): array
3434
}
3535
}
3636
}
37-
38-
//if (!function_exists('get_unit_endpoint')) {
39-
// /**
40-
// * Get the Unit endpoint from the configuration.
41-
// *
42-
// * @return string The Unit endpoint.
43-
// */
44-
// function get_unit_endpoint($class): string
45-
// {
46-
// return match ($class) {
47-
// Unit::class => '/',
48-
// Config::class => '/config'
49-
// };
50-
// }
51-
//}

tests/Unit/Applications/Targets/PhpTargetTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@
2828
$phpTarget = new PhpTarget($data);
2929

3030
expect($phpTarget->toArray())->toBe($data);
31-
});
31+
});

tests/Unit/Applications/Targets/PythonTargetTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@
3737
$pythonTarget = new PythonTarget($data);
3838

3939
expect($pythonTarget->toArray())->toBe($data);
40-
});
40+
});

tests/Unit/ProcessIsolation/ApplicationProcessTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
22

33
use PHPUnit\Framework\TestCase;
4-
54
use UnitPhpSdk\Config\Application\ProcessManagement\ApplicationProcess;
65

76
use function PHPUnit\Framework\assertEquals;

tests/Unit/Settings/TelemetryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@
4545

4646
expect($telemetry->getEndpoint())->toBe($newEndpoint)
4747
->and($telemetry->getProtocol())->toBe($newProtocol);
48-
});
48+
});

tests/Unit/Statistics/ModuleStatisticsTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
});
2323

2424
it(
25-
/**
26-
* @throws InvalidArgumentException
27-
*/
25+
/**
26+
* @throws InvalidArgumentException
27+
*/
2828
'throws InvalidArgumentException when version is missing',
2929
function () {
3030
$data = [
@@ -39,9 +39,9 @@ function () {
3939
);
4040

4141
it(
42-
/**
43-
* @throws InvalidArgumentException
44-
*/
42+
/**
43+
* @throws InvalidArgumentException
44+
*/
4545
'throws InvalidArgumentException when lib is missing',
4646
function () {
4747
$data = [

tests/Unit/Traits/CanUploadTest.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
});
1515

1616
it('sets and gets API endpoint', function () {
17-
$upload = new class { use CanUpload; };
17+
$upload = new class () {
18+
use CanUpload;
19+
};
1820

1921
$apiEndpoint = $this->faker->url();
2022
$upload->setApiEndpoint($apiEndpoint);
@@ -46,9 +48,10 @@
4648
//});
4749

4850
it('throws exception during upload', function () {
49-
$upload = new class {
51+
$upload = new class () {
5052
use CanUpload;
51-
public function toArray() {
53+
public function toArray()
54+
{
5255
return ['key' => 'value'];
5356
}
5457
};
@@ -60,11 +63,11 @@ public function toArray() {
6063
$apiEndpoint = $this->faker->url();
6164
$upload->setApiEndpoint($apiEndpoint);
6265

63-
expect(fn() => $upload->upload($request))->toThrow(UnitException::class, 'Upload failed');
66+
expect(fn () => $upload->upload($request))->toThrow(UnitException::class, 'Upload failed');
6467
});
6568

6669
it('removes data successfully', function () {
67-
$upload = new class {
70+
$upload = new class () {
6871
use CanUpload;
6972
};
7073

@@ -84,7 +87,7 @@ public function toArray() {
8487
});
8588

8689
it('throws exception during remove', function () {
87-
$upload = new class {
90+
$upload = new class () {
8891
use CanUpload;
8992
};
9093

@@ -95,5 +98,5 @@ public function toArray() {
9598
$apiEndpoint = $this->faker->url();
9699
$upload->setApiEndpoint($apiEndpoint);
97100

98-
expect(fn() => $upload->remove($request))->toThrow(UnitException::class, 'Remove failed');
99-
});
101+
expect(fn () => $upload->remove($request))->toThrow(UnitException::class, 'Remove failed');
102+
});

0 commit comments

Comments
 (0)