diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7e0b238..31f02d2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 diff --git a/composer.json b/composer.json index 417ca6d..13602e5 100644 --- a/composer.json +++ b/composer.json @@ -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": { @@ -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 }, diff --git a/docs/configuration-and-codecs.md b/docs/configuration-and-codecs.md index 88f5c5e..599b3e3 100644 --- a/docs/configuration-and-codecs.md +++ b/docs/configuration-and-codecs.md @@ -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. @@ -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. diff --git a/docs/error-handling-and-testing.md b/docs/error-handling-and-testing.md index 6bed410..ccf3c30 100644 --- a/docs/error-handling-and-testing.md +++ b/docs/error-handling-and-testing.md @@ -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: @@ -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. diff --git a/resources/boost/guidelines/core.blade.php b/resources/boost/guidelines/core.blade.php index 77ce068..8934a6e 100644 --- a/resources/boost/guidelines/core.blade.php +++ b/resources/boost/guidelines/core.blade.php @@ -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 diff --git a/resources/boost/skills/skir-client-development/references/invocation-errors-and-testing.md b/resources/boost/skills/skir-client-development/references/invocation-errors-and-testing.md index e67f732..94807f3 100644 --- a/resources/boost/skills/skir-client-development/references/invocation-errors-and-testing.md +++ b/resources/boost/skills/skir-client-development/references/invocation-errors-and-testing.md @@ -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 @@ -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. @@ -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`. diff --git a/src/Codecs/CborCodec.php b/src/Codecs/CborCodec.php deleted file mode 100644 index dc37f1f..0000000 --- a/src/Codecs/CborCodec.php +++ /dev/null @@ -1,31 +0,0 @@ -requestType, $request); - } - - public function encodeRequestBody(MethodDescriptor $descriptor, mixed $request): string - { - return Cbor::encodeEnvelope($descriptor, $request); - } - - public function decodeResponse(MethodDescriptor $descriptor, string $response): mixed - { - return Cbor::decodeValue($descriptor->responseType, $response); - } - - public function contentType(): string - { - return 'application/cbor'; - } -} diff --git a/src/Codecs/SkirClientCodecs.php b/src/Codecs/SkirClientCodecs.php index ca65bb3..721cf8e 100644 --- a/src/Codecs/SkirClientCodecs.php +++ b/src/Codecs/SkirClientCodecs.php @@ -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; diff --git a/src/Codecs/SkirClientHttpCodec.php b/src/Codecs/SkirClientHttpCodec.php deleted file mode 100644 index e0b19c9..0000000 --- a/src/Codecs/SkirClientHttpCodec.php +++ /dev/null @@ -1,14 +0,0 @@ -endpoint; - } - - /** - * @return array{ - * Accept: string, - * Content-Type: string - * } - */ - protected function defaultHeaders(): array - { - return [ - 'Accept' => $this->codec->contentType(), - 'Content-Type' => $this->codec->contentType(), - ]; - } - - protected function defaultBody(): string - { - return $this->codec->encodeRequestBody($this->descriptor, $this->request); - } -} diff --git a/src/SkirClient.php b/src/SkirClient.php index 58e15d2..c71be3c 100644 --- a/src/SkirClient.php +++ b/src/SkirClient.php @@ -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; @@ -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); diff --git a/src/SkirClientServiceProvider.php b/src/SkirClientServiceProvider.php index 7b94c5d..4a4eb80 100644 --- a/src/SkirClientServiceProvider.php +++ b/src/SkirClientServiceProvider.php @@ -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(), diff --git a/tests/Feature/BoostAssetsTest.php b/tests/Feature/BoostAssetsTest.php index 498bb2c..0e72360 100644 --- a/tests/Feature/BoostAssetsTest.php +++ b/tests/Feature/BoostAssetsTest.php @@ -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', @@ -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], diff --git a/tests/Feature/SkirClientServiceProviderTest.php b/tests/Feature/SkirClientServiceProviderTest.php index 6658a7f..c752b80 100644 --- a/tests/Feature/SkirClientServiceProviderTest.php +++ b/tests/Feature/SkirClientServiceProviderTest.php @@ -4,7 +4,6 @@ namespace Skir\Client\Tests\Feature; -use CBOR\Encoder; use PHPUnit\Framework\Attributes\Test; use Saloon\Http\Faking\MockClient; use Saloon\Http\Faking\MockResponse; @@ -12,7 +11,6 @@ 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; @@ -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 { diff --git a/tests/Feature/SkirClientTest.php b/tests/Feature/SkirClientTest.php index 1cdcb87..155e4b0 100644 --- a/tests/Feature/SkirClientTest.php +++ b/tests/Feature/SkirClientTest.php @@ -4,9 +4,6 @@ namespace Skir\Client\Tests\Feature; -use CBOR\Decoder; -use CBOR\Encoder; -use CBOR\StringStream; use PHPUnit\Framework\Attributes\Test; use Saloon\Http\Faking\MockClient; use Saloon\Http\Faking\MockResponse; @@ -185,58 +182,6 @@ public function it_can_use_base64_encoded_dense_json_payloads(): void }); } - #[Test] - public function it_can_use_cbor_payloads(): void - { - $userType = Type::struct([ - Field::value('id', 0, Type::int32()), - Field::value('name', 1, Type::string()), - ]); - - $mockClient = new MockClient([ - MockResponse::make( - (new Encoder)->encode(DenseJson::encode($userType, [ - 'id' => 42, - 'name' => 'Ruben', - ])), - 200, - [ - 'Content-Type' => 'application/cbor', - ], - ), - ]); - - $client = new SkirClient('https://example.com/api', codec: SkirClientCodecs::cbor()); - $client->withMockClient($mockClient); - - $result = $client->invoke( - new MethodDescriptor('RenameUser', 1002, $userType, $userType), - [ - 'id' => 42, - 'name' => 'Maxim', - ], - ); - - $this->assertSame([ - 'id' => 42, - 'name' => 'Ruben', - ], $result); - - $mockClient->assertSent(function (Request $request) use ($userType): bool { - $payload = Decoder::create() - ->decode(StringStream::create($request->body()->all())) - ->normalize(); - - return $request->resolveEndpoint() === '/' - && $request->headers()->get('Content-Type') === 'application/cbor' - && $payload['method'] === 'RenameUser' - && DenseJson::decode($userType, $payload['request']) === [ - 'id' => 42, - 'name' => 'Maxim', - ]; - }); - } - #[Test] public function it_localises_failed_rpc_responses(): void { @@ -302,16 +247,6 @@ public function it_localises_invalid_base64_dense_json_responses(): void ); } - #[Test] - public function it_localises_invalid_cbor_responses(): void - { - $this->assertInvalidResponseIsLocalised( - SkirClientCodecs::cbor(), - "\xff", - 'Invalid CBOR:', - ); - } - private function assertInvalidResponseIsLocalised( SkirClientCodec $codec, string $responseBody,