Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ jobs:
composer config prefer-stable true
composer config repositories.runtime '{"type":"path","url":"../runtime","options":{"symlink":false}}' --json
composer config repositories.client '{"type":"path","url":"../client","options":{"symlink":false}}' --json
composer require php-skir/client:dev-main --no-interaction --no-progress
composer require "php-skir/client:*@dev" --no-interaction --no-progress
composer require laravel/boost:^2.4 --dev --no-interaction --no-progress
test ! -L vendor/php-skir/client

Expand Down
10 changes: 3 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@
"php": "^8.3",
"illuminate/contracts": "^10.0|^11.0|^12.0|^13.0",
"illuminate/support": "^10.0|^11.0|^12.0|^13.0",
"php-skir/runtime": "^0.1@dev",
"php-skir/runtime": "^0.1@dev|^0.2@dev",
"saloonphp/saloon": "^4.0",
"symfony/process": "^6.4|^7.0|^8.0"
},
"require-dev": {
"laravel/pint": "^1.29",
"orchestra/testbench": "^8.0|^9.0|^10.0|^11.0",
"phpunit/phpunit": "^10.5|^11.5|^12.5",
"spomky-labs/cbor-php": "^3.2"
"phpunit/phpunit": "^10.5|^11.5|^12.5"
},
"autoload": {
"psr-4": {
Expand Down Expand Up @@ -62,16 +61,13 @@
]
},
"branch-alias": {
"dev-main": "0.1.x-dev"
"dev-main": "0.2.x-dev"
}
},
"scripts": {
"format": "pint",
"test": "phpunit"
},
"suggest": {
"spomky-labs/cbor-php": "Required when using SkirClientCodecs::cbor() or SKIR_CLIENT_CODEC=cbor."
},
"config": {
"sort-packages": true
},
Expand Down
14 changes: 1 addition & 13 deletions docs/configuration-and-codecs.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ $base64DenseJson = new SkirClient(
endpoint: '/api/skir',
codec: SkirClientCodecs::base64DenseJson(),
);
$cbor = new SkirClient(
baseUrl: 'https://api.example.test',
endpoint: '/api/skir',
codec: SkirClientCodecs::cbor(),
);
```

The first two clients use the same dense JSON codec; the second selects its factory explicitly.
Expand All @@ -68,14 +63,7 @@ The configured codec must match the codec exposed by the server endpoint.
| `dense_json` | Compact, descriptor-driven JSON values; structs use positional arrays. |
| `standard_json` | Readable JSON where structs use named object fields and primitives remain primitive values. |
| `base64_dense_json` | A dense JSON payload carried inside a base64-encoded JSON string. |
| `cbor` | Binary request and response bodies using `application/cbor`. |

CBOR support is optional. Install its dependency before selecting `cbor`:

```bash
composer require spomky-labs/cbor-php
```

Selecting `cbor` without that package throws a `SkirClientException`. An unknown configured codec value also throws `SkirClientException` when Laravel resolves the client.
An unknown configured codec value throws `SkirClientException` when Laravel resolves the client.

See [Generating clients](generating-clients.md) for the typed generation workflow and [Error handling and testing](error-handling-and-testing.md) for transport failure handling and mocks.
4 changes: 1 addition & 3 deletions docs/error-handling-and-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The exception boundary is deliberately narrow:
- Only a codec-thrown `SkirRuntimeException` during response decoding is wrapped as an invalid-response `SkirClientException`.
- A `SkirRuntimeException` thrown while encoding the request propagates directly.
- DNS, connection, and TLS failures propagate as `Saloon\Exceptions\Request\FatalRequestException` and do not have a response.
- An unsupported configured codec or a missing optional CBOR dependency throws `SkirClientException` with both `method` and `response` set to `null`.
- An unsupported configured codec throws `SkirClientException` with both `method` and `response` set to `null`.

The following handler is specifically for the `SkirClientException` paths. It does not catch direct request-encoding or Saloon fatal-request exceptions:

Expand Down Expand Up @@ -152,6 +152,4 @@ final class SkirRpcClientTest extends TestCase

`MockClient` matches the configured response to `SkirRpcRequest`, records the outgoing request, and lets `assertSent()` verify the request class, endpoint, method name, and encoded body. `assertSentCount(1)` also guards against duplicate calls. No network call is made.

When the application selects the binary CBOR codec, mock and assert `Skir\Client\Http\SkirBinaryRpcRequest` instead. Return an actual CBOR-encoded value in the `MockResponse`, such as one produced by `Skir\Runtime\Cbor::encodeValue()` for the generated method's response type. Assert that the request body is a CBOR binary string, decode it when the envelope needs inspection, and assert that both `Accept` and `Content-Type` are `application/cbor` rather than applying the JSON array assertion shown above.

See [Configuration and codecs](configuration-and-codecs.md) for transport setup and codec selection, and [Generating clients](generating-clients.md) for the schema and generated classes used above.
2 changes: 1 addition & 1 deletion resources/boost/guidelines/core.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Prefer the generated typed client for application code. Use `Skir\Client\SkirClient::invoke()` only
for debugging or custom transport integrations. Keep the base URL, endpoint, and codec aligned with
the server. CBOR is a compact serialization format, not encryption or confidentiality.
the server.

Use the `skir-client-development` skill whenever generating or configuring a client, diagnosing
transport failures, choosing a codec, or writing client tests. Client tests must use Saloon mocks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ The client and server must use the same codec:
- `dense_json`: descriptor-driven JSON; structs are positional arrays.
- `standard_json`: readable JSON objects with named struct fields.
- `base64_dense_json`: dense JSON inside a base64-encoded JSON string.
- `cbor`: binary `application/cbor`; requires `spomky-labs/cbor-php`.

CBOR is serialization, not privacy or encryption. A missing CBOR dependency or unsupported configured
codec throws `SkirClientException` while Laravel resolves the transport.
An unsupported configured codec throws `SkirClientException` while Laravel resolves the transport.

## Distinguish failures

Expand All @@ -25,7 +23,7 @@ codec throws `SkirClientException` while Laravel resolves the transport.
| Successful HTTP response cannot be decoded | `SkirClientException` with method, null response, previous `SkirRuntimeException` | Verify response shape and matching codec |
| Request encoding fails | `SkirRuntimeException` propagates directly | Verify generated request values and codec input |
| DNS, connection, or TLS fails | Saloon `FatalRequestException` propagates with no response | Inspect URL, DNS, TLS, and connectivity |
| Codec is unsupported or optional CBOR support is absent | `SkirClientException` with null method and response | Correct config or install the optional dependency |
| Codec is unsupported | `SkirClientException` with null method and response | Correct the configured codec |

Responses Saloon does not classify as failed, including redirects by default, continue to decoding.
Catching only `SkirClientException` does not catch encoding or network failures.
Expand Down Expand Up @@ -54,5 +52,4 @@ $mockClient->assertSentCount(1);

Cover the typed happy path, failed HTTP response, malformed successful response, and any
application-specific encoding/network policy. Assert request class, endpoint, RPC method, encoded
body, and send count. JSON codecs use `SkirRpcRequest`; CBOR uses `SkirBinaryRpcRequest`, genuine
CBOR-encoded mock bodies, and `Accept` plus `Content-Type` assertions for `application/cbor`.
body, and send count. Mock and assert `SkirRpcRequest`.
31 changes: 0 additions & 31 deletions src/Codecs/CborCodec.php

This file was deleted.

12 changes: 0 additions & 12 deletions src/Codecs/SkirClientCodecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,8 @@

namespace Skir\Client\Codecs;

use Skir\Client\Exceptions\SkirClientException;
use Skir\Runtime\Cbor;

final class SkirClientCodecs
{
public static function cbor(): SkirClientCodec
{
if (! Cbor::available()) {
throw SkirClientException::missingCborDependency();
}

return new CborCodec;
}

public static function denseJson(): SkirClientCodec
{
return new DenseJsonCodec;
Expand Down
14 changes: 0 additions & 14 deletions src/Codecs/SkirClientHttpCodec.php

This file was deleted.

5 changes: 0 additions & 5 deletions src/Exceptions/SkirClientException.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,4 @@ public static function unsupportedCodec(string $codec): self
{
return new self("Skir client codec [{$codec}] is not supported.");
}

public static function missingCborDependency(): self
{
return new self('Skir client CBOR support requires the [spomky-labs/cbor-php] Composer package.');
}
}
50 changes: 0 additions & 50 deletions src/Http/SkirBinaryRpcRequest.php

This file was deleted.

10 changes: 3 additions & 7 deletions src/SkirClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
use Saloon\Http\Faking\MockClient;
use Skir\Client\Codecs\DenseJsonCodec;
use Skir\Client\Codecs\SkirClientCodec;
use Skir\Client\Codecs\SkirClientHttpCodec;
use Skir\Client\Exceptions\SkirClientException;
use Skir\Client\Http\SkirBinaryRpcRequest;
use Skir\Client\Http\SkirConnector;
use Skir\Client\Http\SkirRpcRequest;
use Skir\Runtime\Exceptions\SkirRuntimeException;
Expand All @@ -36,11 +34,9 @@ public function withMockClient(MockClient $mockClient): self

public function invoke(MethodDescriptor $descriptor, mixed $request): mixed
{
$rpcRequest = $this->codec instanceof SkirClientHttpCodec
? new SkirBinaryRpcRequest($descriptor, $request, $this->codec, $this->endpoint)
: new SkirRpcRequest($descriptor, $request, $this->codec, $this->endpoint);

$response = $this->connector->send($rpcRequest);
$response = $this->connector->send(
new SkirRpcRequest($descriptor, $request, $this->codec, $this->endpoint),
);

if ($response->failed()) {
throw SkirClientException::failedResponse($descriptor, $response);
Expand Down
1 change: 0 additions & 1 deletion src/SkirClientServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public function boot(): void
private function codecFromConfig(string $codec): SkirClientCodec
{
return match ($codec) {
'cbor' => SkirClientCodecs::cbor(),
'dense_json' => SkirClientCodecs::denseJson(),
'standard_json' => SkirClientCodecs::standardJson(),
'base64_dense_json' => SkirClientCodecs::base64DenseJson(),
Expand Down
4 changes: 0 additions & 4 deletions tests/Feature/BoostAssetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ public function it_keeps_client_guidance_anchored_to_the_released_package(): voi
'dense_json',
'standard_json',
'base64_dense_json',
'cbor',
'SkirClientException',
'SkirRuntimeException',
'FatalRequestException',
Expand All @@ -121,14 +120,11 @@ public function it_keeps_client_guidance_portable_and_non_executable(): void
'make composer',
'make npm',
'make test',
'CBOR encrypts',
'CBOR is secure',
'edit generated',
] as $forbiddenGuidance) {
$this->assertStringNotContainsStringIgnoringCase($forbiddenGuidance, $guidance);
}

$this->assertStringContainsString('serialization', $guidance);
$this->assertStringContainsString('Do not edit', $guidance);
$this->assertSame(
[self::GUIDELINE, self::SKILL, ...self::REFERENCES],
Expand Down
27 changes: 0 additions & 27 deletions tests/Feature/SkirClientServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@

namespace Skir\Client\Tests\Feature;

use CBOR\Encoder;
use PHPUnit\Framework\Attributes\Test;
use Saloon\Http\Faking\MockClient;
use Saloon\Http\Faking\MockResponse;
use Skir\Client\Exceptions\SkirClientException;
use Skir\Client\Http\SkirRpcRequest;
use Skir\Client\SkirClient;
use Skir\Client\Tests\TestCase;
use Skir\Runtime\DenseJson;
use Skir\Runtime\MethodDescriptor;
use Skir\Runtime\Type;

Expand Down Expand Up @@ -79,31 +77,6 @@ public function it_resolves_a_configured_standard_json_client_from_the_container
});
}

#[Test]
public function it_resolves_a_configured_cbor_client_from_the_container(): void
{
config()->set('skir-client.base_url', 'https://example.com/api');
config()->set('skir-client.codec', 'cbor');

$mockClient = new MockClient([
MockResponse::make((new Encoder)->encode(DenseJson::encode(Type::float32(), 25.0)), 200),
]);

$client = app(SkirClient::class);
$client->withMockClient($mockClient);

$result = $client->invoke(
new MethodDescriptor('Square', 1001, Type::float32(), Type::float32()),
5.0,
);

$this->assertSame(25.0, $result);

$mockClient->assertSent(function ($request): bool {
return $request->headers()->get('Content-Type') === 'application/cbor';
});
}

#[Test]
public function it_fails_with_a_package_exception_for_unknown_configured_codecs(): void
{
Expand Down
Loading