From c5bce8026d7d97801fbe2c8dc5c15d0475c52bff Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Wed, 18 Sep 2024 20:31:42 +0400 Subject: [PATCH 01/58] Implement GetFollowers request and resource --- .../Requests/App/Bsky/Graph/GetFollowers.php | 41 +++++++++++++++++++ .../App/Bsky/Graph/GetFollowersResource.php | 28 +++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 src/HTTP/API/Requests/App/Bsky/Graph/GetFollowers.php create mode 100644 src/Resources/App/Bsky/Graph/GetFollowersResource.php diff --git a/src/HTTP/API/Requests/App/Bsky/Graph/GetFollowers.php b/src/HTTP/API/Requests/App/Bsky/Graph/GetFollowers.php new file mode 100644 index 0000000..aea6468 --- /dev/null +++ b/src/HTTP/API/Requests/App/Bsky/Graph/GetFollowers.php @@ -0,0 +1,41 @@ +prefix()); + + if (! $client->authenticated()) { + return; + } + + try { + $this->header('Authorization', 'Bearer ' . $client->authenticated()->accessJwt()); + $this->queryParameter('actor', $client->authenticated()->did()); + } catch (AuthRequired $e) {} + } + + public function resource(array $data): ResourceContract + { + return new GetFollowersResource($data); + } + + public function build(): RequestContract + { + return $this; + } +} \ No newline at end of file diff --git a/src/Resources/App/Bsky/Graph/GetFollowersResource.php b/src/Resources/App/Bsky/Graph/GetFollowersResource.php new file mode 100644 index 0000000..e97c562 --- /dev/null +++ b/src/Resources/App/Bsky/Graph/GetFollowersResource.php @@ -0,0 +1,28 @@ +content = $content; + } + + protected function casts(): array + { + return [ + 'followers' => FollowersAsset::class, + ]; + } +} From 94324e70cc38ea69aa496d7b9dd944a6b2e4b8b0 Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Fri, 20 Sep 2024 17:25:18 +0400 Subject: [PATCH 02/58] Update GetFollowers Request and add Unit Tests - Added parameter setters for `actor`, `limit`, and `cursor` with validation for `limit`. - Implemented error handling with `AuthMissingException` and `MissingFieldProvidedException` during request building. - Enhanced `Authentication` trait with token management. - Added comprehensive unit tests for `GetFollowers` to ensure proper parameter handling, validation, and response. --- src/Exceptions/InvalidArgumentException.php | 10 ++ .../Requests/App/Bsky/Actor/GetProfile.php | 7 +- .../Requests/App/Bsky/Graph/GetFollowers.php | 65 +++++++-- src/HTTP/Traits/Authentication.php | 12 ++ src/HTTP/Traits/RequestBuilder.php | 8 +- .../App/Bsky/Graph/GetFollowersTest.php | 124 ++++++++++++++++++ 6 files changed, 210 insertions(+), 16 deletions(-) create mode 100644 src/Exceptions/InvalidArgumentException.php create mode 100644 tests/Unit/HTTP/API/Requests/App/Bsky/Graph/GetFollowersTest.php diff --git a/src/Exceptions/InvalidArgumentException.php b/src/Exceptions/InvalidArgumentException.php new file mode 100644 index 0000000..7c06522 --- /dev/null +++ b/src/Exceptions/InvalidArgumentException.php @@ -0,0 +1,10 @@ +headers(), 'Authorization')) { + throw new AuthMissingException(); + } + $missing = []; if (! $this->queryParameter('actor')) { diff --git a/src/HTTP/API/Requests/App/Bsky/Graph/GetFollowers.php b/src/HTTP/API/Requests/App/Bsky/Graph/GetFollowers.php index aea6468..d53bef8 100644 --- a/src/HTTP/API/Requests/App/Bsky/Graph/GetFollowers.php +++ b/src/HTTP/API/Requests/App/Bsky/Graph/GetFollowers.php @@ -2,31 +2,58 @@ namespace Atproto\HTTP\API\Requests\App\Bsky\Graph; -use Atproto\Client; use Atproto\Contracts\HTTP\Resources\ResourceContract; use Atproto\Contracts\RequestContract; -use Atproto\Exceptions\Auth\AuthRequired; +use Atproto\Exceptions\Http\MissingFieldProvidedException; +use Atproto\Exceptions\Http\Response\AuthMissingException; +use Atproto\Exceptions\InvalidArgumentException; +use Atproto\Helpers\Arr; use Atproto\HTTP\API\APIRequest; +use Atproto\HTTP\Traits\Authentication; use Atproto\Resources\App\Bsky\Graph\GetFollowersResource; class GetFollowers extends APIRequest { - public function __construct(Client $client = null) + use Authentication; + + public function actor(string $actor = null) + { + if (is_null($actor)) { + return $this->queryParameter('actor'); + } + + $this->queryParameter('actor', $actor); + + return $this; + } + + /** + * @throws InvalidArgumentException + */ + public function limit(int $limit = null) { - if (! $client) { - return; + if (is_null($limit)) { + return (int) $this->queryParameter('limit') ?: null; + } + + if (! ($limit >= 1 && $limit <= 100)) { + throw new InvalidArgumentException("Limit must be between 1 and 100."); } - parent::__construct($client->prefix()); + $this->queryParameter('limit', $limit); - if (! $client->authenticated()) { - return; + return $this; + } + + public function cursor(string $cursor = null) + { + if (is_null($cursor)) { + return $this->queryParameter('cursor'); } - try { - $this->header('Authorization', 'Bearer ' . $client->authenticated()->accessJwt()); - $this->queryParameter('actor', $client->authenticated()->did()); - } catch (AuthRequired $e) {} + $this->queryParameter('cursor', $cursor); + + return $this; } public function resource(array $data): ResourceContract @@ -34,8 +61,20 @@ public function resource(array $data): ResourceContract return new GetFollowersResource($data); } + /** + * @throws MissingFieldProvidedException + * @throws AuthMissingException + */ public function build(): RequestContract { + if (! Arr::exists($this->headers(false), 'Authorization')) { + throw new AuthMissingException(); + } + + if (! $this->queryParameter('actor')) { + throw new MissingFieldProvidedException('actor'); + } + return $this; } -} \ No newline at end of file +} diff --git a/src/HTTP/Traits/Authentication.php b/src/HTTP/Traits/Authentication.php index cef08cc..f1a08b1 100644 --- a/src/HTTP/Traits/Authentication.php +++ b/src/HTTP/Traits/Authentication.php @@ -3,6 +3,7 @@ namespace Atproto\HTTP\Traits; use Atproto\Client; +use Atproto\Contracts\RequestContract; use Atproto\HTTP\API\APIRequest; trait Authentication @@ -19,4 +20,15 @@ public function __construct(Client $client) $this->header("Authorization", "Bearer " . $authenticated->accessJwt()); } } + + public function token(string $token = null) + { + if (is_null($token)) { + return $this->header('Authorization'); + } + + $this->header('Authorization', "Bearer " . $token); + + return $this; + } } diff --git a/src/HTTP/Traits/RequestBuilder.php b/src/HTTP/Traits/RequestBuilder.php index 0f262b7..af3d557 100644 --- a/src/HTTP/Traits/RequestBuilder.php +++ b/src/HTTP/Traits/RequestBuilder.php @@ -134,8 +134,12 @@ public function parameters($parameters = null) public function queryParameters($queryParameters = null) { - if (is_bool($queryParameters) && $queryParameters) { - return http_build_query($this->queryParameters); + if (is_bool($queryParameters)) { + if ($queryParameters) { + return http_build_query($this->queryParameters); + } + + return $this->queryParameters; } if (is_null($queryParameters)) { diff --git a/tests/Unit/HTTP/API/Requests/App/Bsky/Graph/GetFollowersTest.php b/tests/Unit/HTTP/API/Requests/App/Bsky/Graph/GetFollowersTest.php new file mode 100644 index 0000000..4883f9b --- /dev/null +++ b/tests/Unit/HTTP/API/Requests/App/Bsky/Graph/GetFollowersTest.php @@ -0,0 +1,124 @@ +clientMock = $this->createMock(Client::class); + $this->request = new GetFollowers($this->clientMock); + } + + public function testActorSetterAndGetter() + { + $actor = 'testActor'; + $this->request->actor($actor); + $this->assertSame($actor, $this->request->actor(), 'Actor getter should return the value set by the setter.'); + } + + public function testLimitSetterAndGetter() + { + $limit = 50; + $this->request->limit($limit); + $this->assertSame($limit, $this->request->limit(), 'Limit getter should return the value set by the setter.'); + } + + public function testLimitSetterThrowsExceptionForZero() + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Limit must be between 1 and 100.'); + $this->request->limit(0); + } + + public function testLimitSetterThrowsExceptionForNegativeValue() + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Limit must be between 1 and 100.'); + $this->request->limit(-10); + } + + public function testLimitSetterThrowsExceptionForValueAboveMaximum() + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Limit must be between 1 and 100.'); + $this->request->limit(101); + } + + public function testCursorSetterAndGetter() + { + $cursor = 'testCursor'; + $this->request->cursor($cursor); + $this->assertSame($cursor, $this->request->cursor(), 'Cursor getter should return the value set by the setter.'); + } + + public function testBuildThrowsExceptionWhenAuthorizationHeaderMissing() + { + $this->expectException(AuthMissingException::class); + $this->expectExceptionMessage('Authentication Required'); + + // Set required 'actor' parameter + $this->request->actor('testActor'); + + // Do not set 'Authorization' header + $this->request->build(); + } + + public function testBuildThrowsExceptionWhenActorParameterMissing() + { + $this->expectException(MissingFieldProvidedException::class); + $this->expectExceptionMessage("Missing provided fields: actor"); + + // Set 'Authorization' header + $this->request->token('Bearer token'); + + // Do not set 'actor' parameter + $this->request->build(); + } + + public function testBuildSucceedsWithRequiredParameters() + { + // Set required 'Authorization' header and 'actor' parameter + $this->request->token('Bearer token'); + $this->request->actor('testActor'); + + // Should not throw any exceptions + $builtRequest = $this->request->build(); + $this->assertInstanceOf(GetFollowers::class, $builtRequest, 'Build should return an instance of GetFollowers.'); + } + + public function testResourceMethodReturnsCorrectInstance() + { + $data = ['followers' => []]; + $resource = $this->request->resource($data); + $this->assertInstanceOf(ResourceContract::class, $resource, 'Resource method should return an instance of ResourceContract.'); + } + + public function testLimitGetterReturnsNullWhenNotSet() + { + $this->assertNull($this->request->limit(), 'Limit getter should return null when not set.'); + } + + public function testActorGetterReturnsNullWhenNotSet() + { + $this->assertNull($this->request->actor(), 'Actor getter should return null when not set.'); + } + + public function testCursorGetterReturnsNullWhenNotSet() + { + $this->assertNull($this->request->cursor(), 'Cursor getter should return null when not set.'); + } +} From dc6deb156f271e8dd0ec9d5b6898aad74dda272c Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sun, 22 Sep 2024 02:31:23 +0400 Subject: [PATCH 03/58] Add GetProfiles request for fetching multiple user profiles - Implement ProfileAssetType for type validation - Add token method to Authentication trait for easier token handling - Create InvalidArgumentException - Modify MissingFieldProvidedException message - Update .gitignore to exclude PHP-CS-Fixer files - Update RequestContract to allow array query parameters --- .gitignore | 13 +- src/Contracts/RequestContract.php | 4 +- .../Http/MissingFieldProvidedException.php | 2 +- src/Exceptions/InvalidArgumentException.php | 3 +- .../Types/NonPrimitive/ProfileAssetType.php | 14 +++ .../Requests/App/Bsky/Actor/GetProfiles.php | 71 +++++++++++ src/HTTP/Traits/Authentication.php | 3 +- src/HTTP/Traits/RequestBuilder.php | 2 +- .../App/Bsky/Actor/GetProfilesResource.php | 21 ++++ src/Resources/Assets/ProfileAsset.php | 11 ++ src/Resources/Assets/ProfilesAsset.php | 28 +++++ tests/Feature/ClientTest.php | 3 - .../App/Bsky/Actor/GetProfilesTest.php | 116 ++++++++++++++++++ .../App/Bsky/Actor/GetProfileTest.php | 2 +- .../App/Bsky/Actor/GetProfilesTest.php | 94 ++++++++++++++ 15 files changed, 374 insertions(+), 13 deletions(-) create mode 100644 src/GenericCollection/Types/NonPrimitive/ProfileAssetType.php create mode 100644 src/HTTP/API/Requests/App/Bsky/Actor/GetProfiles.php create mode 100644 src/Resources/App/Bsky/Actor/GetProfilesResource.php create mode 100644 src/Resources/Assets/ProfileAsset.php create mode 100644 src/Resources/Assets/ProfilesAsset.php create mode 100644 tests/Feature/HTTP/API/Requests/App/Bsky/Actor/GetProfilesTest.php create mode 100644 tests/Unit/HTTP/API/Requests/App/Bsky/Actor/GetProfilesTest.php diff --git a/.gitignore b/.gitignore index f183cec..206dca0 100644 --- a/.gitignore +++ b/.gitignore @@ -112,4 +112,15 @@ fabric.properties # Build data /build/ -# End of https://www.toptal.com/developers/gitignore/api/phpstorm+all,composer,phpunit +### PHP-CS-Fixer ### +# Covers PHP CS Fixer +# Reference: https://cs.symfony.com/ + +# Generated files +.php-cs-fixer.cache + +# Local config See: https://cs.symfony.com/doc/config.html +.php-cs-fixer.php + +# End of https://www.toptal.com/developers/gitignore/api/php-cs-fixer + diff --git a/src/Contracts/RequestContract.php b/src/Contracts/RequestContract.php index abcdcd1..7d1fea2 100644 --- a/src/Contracts/RequestContract.php +++ b/src/Contracts/RequestContract.php @@ -62,10 +62,10 @@ public function parameter(string $name, $value = null); * Get or set a query parameter in the request. * * @param string $name The query parameter name - * @param string|null $value The query parameter value to set, or null to get the current value. + * @param array|string|null $value The query parameter value to set, or null to get the current value. * @return mixed|string|null The query parameter value or instance for chaining */ - public function queryParameter(string $name, string $value = null); + public function queryParameter(string $name, $value = null); /** * Get or set multiple headers at once. diff --git a/src/Exceptions/Http/MissingFieldProvidedException.php b/src/Exceptions/Http/MissingFieldProvidedException.php index de3f9fe..7e0c342 100644 --- a/src/Exceptions/Http/MissingFieldProvidedException.php +++ b/src/Exceptions/Http/MissingFieldProvidedException.php @@ -8,6 +8,6 @@ class MissingFieldProvidedException extends BlueskyException { public function __construct($message = "", $code = 0, $previous = null) { - parent::__construct("Missing provided fields: $message", $code, $previous); + parent::__construct("Missing fields provided: $message", $code, $previous); } } diff --git a/src/Exceptions/InvalidArgumentException.php b/src/Exceptions/InvalidArgumentException.php index 7c06522..4c80bfc 100644 --- a/src/Exceptions/InvalidArgumentException.php +++ b/src/Exceptions/InvalidArgumentException.php @@ -6,5 +6,4 @@ class InvalidArgumentException extends BlueskyException { - -} \ No newline at end of file +} diff --git a/src/GenericCollection/Types/NonPrimitive/ProfileAssetType.php b/src/GenericCollection/Types/NonPrimitive/ProfileAssetType.php new file mode 100644 index 0000000..6b43ffe --- /dev/null +++ b/src/GenericCollection/Types/NonPrimitive/ProfileAssetType.php @@ -0,0 +1,14 @@ +actors; + } + + if ($actors->gettype() !== StringType::class) { + throw new InvalidArgumentException(sprintf( + "'\$actors' collection must be of type '%s' but is of type '%s'", + StringType::class, + $actors->gettype() + )); + } + + if (! ($actors->count() >= 1 && $actors->count() <= 25)) { + throw new InvalidArgumentException("'\$actors' collection count must be between 1 and 25"); + } + + $this->actors = $actors; + + $this->queryParameter('actors', array_values($this->actors->toArray())); + + return $this; + } + + /** + * @throws AuthRequired + * @throws MissingFieldProvidedException + */ + public function build(): RequestContract + { + if (is_null($this->header('Authorization'))) { + throw new AuthRequired(); + } + + if (is_null($this->actors)) { + throw new MissingFieldProvidedException("actors"); + } + + return $this; + } +} diff --git a/src/HTTP/Traits/Authentication.php b/src/HTTP/Traits/Authentication.php index 94d15d6..69e54ab 100644 --- a/src/HTTP/Traits/Authentication.php +++ b/src/HTTP/Traits/Authentication.php @@ -3,7 +3,6 @@ namespace Atproto\HTTP\Traits; use Atproto\Client; -use Atproto\Contracts\RequestContract; use Atproto\HTTP\API\APIRequest; use SplSubject; @@ -35,7 +34,7 @@ public function token(string $token = null) return $this->header('Authorization'); } - $this->header('Authorization', "Bearer " . $token); + $this->header('Authorization', "Bearer $token"); return $this; } diff --git a/src/HTTP/Traits/RequestBuilder.php b/src/HTTP/Traits/RequestBuilder.php index af3d557..e0ab102 100644 --- a/src/HTTP/Traits/RequestBuilder.php +++ b/src/HTTP/Traits/RequestBuilder.php @@ -79,7 +79,7 @@ public function parameter(string $name, $value = null) return $this; } - public function queryParameter(string $name, string $value = null) + public function queryParameter(string $name, $value = null) { if (is_null($value)) { return $this->queryParameters[$name] ?? null; diff --git a/src/Resources/App/Bsky/Actor/GetProfilesResource.php b/src/Resources/App/Bsky/Actor/GetProfilesResource.php new file mode 100644 index 0000000..3c35c4f --- /dev/null +++ b/src/Resources/App/Bsky/Actor/GetProfilesResource.php @@ -0,0 +1,21 @@ + ProfilesAsset::class + ]; + } +} diff --git a/src/Resources/Assets/ProfileAsset.php b/src/Resources/Assets/ProfileAsset.php new file mode 100644 index 0000000..9f45a39 --- /dev/null +++ b/src/Resources/Assets/ProfileAsset.php @@ -0,0 +1,11 @@ +send(); } - /** - * @throws BlueskyException - */ public function testObserverNotificationOnAuthentication(): void { $request = $this->client->app() diff --git a/tests/Feature/HTTP/API/Requests/App/Bsky/Actor/GetProfilesTest.php b/tests/Feature/HTTP/API/Requests/App/Bsky/Actor/GetProfilesTest.php new file mode 100644 index 0000000..4d18679 --- /dev/null +++ b/tests/Feature/HTTP/API/Requests/App/Bsky/Actor/GetProfilesTest.php @@ -0,0 +1,116 @@ +client = new Client(); + + $this->request = $this->client + ->app() + ->bsky() + ->actor() + ->getProfiles() + ->forge(); + } + + /** + * @throws BlueskyException + */ + private function authenticate(): void + { + $username = $_ENV['BLUESKY_IDENTIFIER']; + $password = $_ENV['BLUESKY_PASSWORD']; + + $this->assertIsString($username); + $this->assertIsString($password); + + $this->client->authenticate($username, $password); + } + + /** + * @throws InvalidArgumentException + * @throws \Atproto\Exceptions\InvalidArgumentException + * @throws BlueskyException + */ + public function testGettingProfiles(): void + { + $this->authenticate(); + + $profiles = new GenericCollection(new StringType(), [ + $this->client->authenticated()->did() + ]); + + $response = $this->client + ->app() + ->bsky() + ->actor() + ->getProfiles() + ->forge() + ->actors($profiles) + ->build() + ->send(); + + $this->assertInstanceOf(GetProfilesResource::class, $response); + $this->assertSame($profiles->count(), $response->profiles()->count()); + + $actualDidArr = array_map(fn (ProfileAsset $profile) => $profile->did(), $response->profiles()->toArray()); + + $this->assertSame($profiles->toArray(), $actualDidArr); + } + + public function testGettingProfilesThrowsExceptionWhenAuthTokenIsMissing(): void + { + $this->expectException(BlueskyException::class); + $this->expectException(AuthMissingException::class); + $this->expectExceptionMessage("Authentication Required"); + + $this->request->send(); + } + + public function testGettingProfilesThrowsExceptionWhenAuthTokenIsInvalid(): void + { + $this->expectException(BlueskyException::class); + $this->expectException(InvalidTokenException::class); + $this->expectExceptionMessage("Malformed authorization header"); + $this->expectExceptionCode(400); + + $this->request->token('Bearer token')->send(); + } + + public function testGettingProfilesThrowsExceptionWhenActorsMissing(): void + { + $this->expectException(BlueskyException::class); + $this->expectException(MissingFieldProvidedException::class); + $this->expectExceptionMessage("Missing fields provided: actors"); + + $this->authenticate(); + + $request = (new GetProfiles($this->client))->build(); + + $request->send(); + } +} diff --git a/tests/Unit/HTTP/API/Requests/App/Bsky/Actor/GetProfileTest.php b/tests/Unit/HTTP/API/Requests/App/Bsky/Actor/GetProfileTest.php index 6302cfa..6b842ac 100644 --- a/tests/Unit/HTTP/API/Requests/App/Bsky/Actor/GetProfileTest.php +++ b/tests/Unit/HTTP/API/Requests/App/Bsky/Actor/GetProfileTest.php @@ -91,7 +91,7 @@ public function testBuildReturnsSameInterface(): void public function testBuildThrowsAnExceptionWhenActorDoesNotExist(): void { $this->expectException(MissingFieldProvidedException::class); - $this->expectExceptionMessage("Missing provided fields: actor, token"); + $this->expectExceptionMessage("Missing fields provided: actor, token"); $this->request->build(); } diff --git a/tests/Unit/HTTP/API/Requests/App/Bsky/Actor/GetProfilesTest.php b/tests/Unit/HTTP/API/Requests/App/Bsky/Actor/GetProfilesTest.php new file mode 100644 index 0000000..6bc3a4e --- /dev/null +++ b/tests/Unit/HTTP/API/Requests/App/Bsky/Actor/GetProfilesTest.php @@ -0,0 +1,94 @@ +client = $this->createMock(Client::class); + $this->request = new GetProfiles($this->client); + } + + /** + * @throws InvalidArgumentException + * @throws \GenericCollection\Exceptions\InvalidArgumentException + */ + public function testActorsSetterAndGetter(): void + { + $actors = new GenericCollection(new StringType(), ['actor1', 'actor2']); + $this->request->actors($actors); + $this->assertSame($actors, $this->request->actors(), 'Actors getter should return the value set by the setter.'); + } + + public function testActorsSetterThrowsExceptionForInvalidType(): void + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage("'\$actors' collection must be of type 'GenericCollection\Types\Primitive\StringType'"); + $this->request->actors(new GenericCollection(\stdClass::class)); + } + + public function testActorsSetterThrowsExceptionForTooFewActors(): void + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage("'\$actors' collection count must be between 1 and 25"); + $this->request->actors(new GenericCollection(StringType::class)); + } + + /** + * @throws \GenericCollection\Exceptions\InvalidArgumentException + */ + public function testActorsSetterThrowsExceptionForTooManyActors(): void + { + $actors = new GenericCollection(new StringType()); + for ($i = 0; $i <= 25; $i++) { + $actors->add($i, "actor$i"); + } + + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage("'\$actors' collection count must be between 1 and 25"); + $this->request->actors($actors); + } + + public function testBuildThrowsAuthRequiredException(): void + { + $this->expectException(AuthRequired::class); + $this->request->build(); + } + + public function testBuildThrowsMissingFieldProvidedException(): void + { + $this->request->token('Bearer token'); + $this->expectException(MissingFieldProvidedException::class); + $this->expectExceptionMessage('actors'); + $this->request->build(); + } + + public function testBuildSucceeds(): void + { + $actors = new GenericCollection(new StringType(), ['actor1']); + $this->request->token('Bearer token')->actors($actors); + + $this->assertInstanceOf(GetProfiles::class, $this->request->build(), 'Build should return an instance of GetProfiles.'); + } + + public function testResourceMethodReturnsCorrectInstance(): void + { + $data = ['actors' => []]; + $resource = $this->request->resource($data); + $this->assertInstanceOf(GetProfilesResource::class, $resource, 'Resource method should return an instance of GetProfilesResource.'); + } +} From 52d51f35d4fa5acd600744fdc5f2b55a269155f8 Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sun, 22 Sep 2024 02:39:26 +0400 Subject: [PATCH 04/58] FIX: Refactor GetProfile request and update related tests --- .../API/Requests/App/Bsky/Actor/GetProfile.php | 14 ++------------ .../API/Requests/App/Bsky/Actor/GetProfileTest.php | 4 +++- .../Requests/App/Bsky/Graph/GetFollowersTest.php | 2 +- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/HTTP/API/Requests/App/Bsky/Actor/GetProfile.php b/src/HTTP/API/Requests/App/Bsky/Actor/GetProfile.php index c5b3fe1..954ac2f 100644 --- a/src/HTTP/API/Requests/App/Bsky/Actor/GetProfile.php +++ b/src/HTTP/API/Requests/App/Bsky/Actor/GetProfile.php @@ -49,22 +49,12 @@ public function token(string $token = null) */ public function build(): RequestContract { - if (! Arr::exists($this->headers(), 'Authorization')) { + if (! $this->header('Authorization')) { throw new AuthMissingException(); } - $missing = []; - if (! $this->queryParameter('actor')) { - $missing[] = 'actor'; - } - - if (! $this->header('Authorization')) { - $missing[] = 'token'; - } - - if (! empty($missing)) { - throw new MissingFieldProvidedException(implode(", ", $missing)); + throw new MissingFieldProvidedException('actor'); } return $this; diff --git a/tests/Unit/HTTP/API/Requests/App/Bsky/Actor/GetProfileTest.php b/tests/Unit/HTTP/API/Requests/App/Bsky/Actor/GetProfileTest.php index 6b842ac..9bbce9a 100644 --- a/tests/Unit/HTTP/API/Requests/App/Bsky/Actor/GetProfileTest.php +++ b/tests/Unit/HTTP/API/Requests/App/Bsky/Actor/GetProfileTest.php @@ -90,8 +90,10 @@ public function testBuildReturnsSameInterface(): void public function testBuildThrowsAnExceptionWhenActorDoesNotExist(): void { + $this->request->token($this->faker->word); + $this->expectException(MissingFieldProvidedException::class); - $this->expectExceptionMessage("Missing fields provided: actor, token"); + $this->expectExceptionMessage("Missing fields provided: actor"); $this->request->build(); } diff --git a/tests/Unit/HTTP/API/Requests/App/Bsky/Graph/GetFollowersTest.php b/tests/Unit/HTTP/API/Requests/App/Bsky/Graph/GetFollowersTest.php index 4883f9b..508bf92 100644 --- a/tests/Unit/HTTP/API/Requests/App/Bsky/Graph/GetFollowersTest.php +++ b/tests/Unit/HTTP/API/Requests/App/Bsky/Graph/GetFollowersTest.php @@ -80,7 +80,7 @@ public function testBuildThrowsExceptionWhenAuthorizationHeaderMissing() public function testBuildThrowsExceptionWhenActorParameterMissing() { $this->expectException(MissingFieldProvidedException::class); - $this->expectExceptionMessage("Missing provided fields: actor"); + $this->expectExceptionMessage("Missing fields provided: actor"); // Set 'Authorization' header $this->request->token('Bearer token'); From 93b85f7d3fa60ee5d3875ce6f86793d4a9d44bac Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Mon, 23 Sep 2024 22:12:03 +0400 Subject: [PATCH 05/58] WIP: Implement Facet lexicon - Add new RichText classes: FeatureAbstract, Link, Mention, and Tag - Implement Facet lexicon structure as per app.bsky.richtext.facet schema - Add unit tests for FeatureAbstract serialization - Improve type safety and add input validation for union facet classes --- .../App/Bsky/RichText/FeatureAbstract.php | 25 +++++++++ src/Lexicons/App/Bsky/RichText/Link.php | 35 +++++++++++++ src/Lexicons/App/Bsky/RichText/Mention.php | 25 +++++++++ src/Lexicons/App/Bsky/RichText/Tag.php | 34 +++++++++++++ .../App/Bsky/RichText/FeatureAbstractTest.php | 49 ++++++++++++++++++ .../Lexicons/App/Bsky/RichText/LinkTest.php | 51 +++++++++++++++++++ .../App/Bsky/RichText/MentionTest.php | 20 ++++++++ .../Lexicons/App/Bsky/RichText/TagTest.php | 22 ++++++++ 8 files changed, 261 insertions(+) create mode 100644 src/Lexicons/App/Bsky/RichText/FeatureAbstract.php create mode 100644 src/Lexicons/App/Bsky/RichText/Link.php create mode 100644 src/Lexicons/App/Bsky/RichText/Mention.php create mode 100644 src/Lexicons/App/Bsky/RichText/Tag.php create mode 100644 tests/Unit/Lexicons/App/Bsky/RichText/FeatureAbstractTest.php create mode 100644 tests/Unit/Lexicons/App/Bsky/RichText/LinkTest.php create mode 100644 tests/Unit/Lexicons/App/Bsky/RichText/MentionTest.php create mode 100644 tests/Unit/Lexicons/App/Bsky/RichText/TagTest.php diff --git a/src/Lexicons/App/Bsky/RichText/FeatureAbstract.php b/src/Lexicons/App/Bsky/RichText/FeatureAbstract.php new file mode 100644 index 0000000..9ea75a0 --- /dev/null +++ b/src/Lexicons/App/Bsky/RichText/FeatureAbstract.php @@ -0,0 +1,25 @@ + $this->type(),], + $this->schema() + ); + } + + public function __toString(): string + { + return json_encode($this); + } + + abstract public function schema(): array; + abstract public function type(): string; +} diff --git a/src/Lexicons/App/Bsky/RichText/Link.php b/src/Lexicons/App/Bsky/RichText/Link.php new file mode 100644 index 0000000..7bc4e4f --- /dev/null +++ b/src/Lexicons/App/Bsky/RichText/Link.php @@ -0,0 +1,35 @@ +url = $url; + } + + public function schema(): array + { + return [ + "uri" => $this->url, + ]; + } + + public function type(): string + { + return "link"; + } +} diff --git a/src/Lexicons/App/Bsky/RichText/Mention.php b/src/Lexicons/App/Bsky/RichText/Mention.php new file mode 100644 index 0000000..dbbfc16 --- /dev/null +++ b/src/Lexicons/App/Bsky/RichText/Mention.php @@ -0,0 +1,25 @@ +did = $did; + } + + public function schema(): array + { + return [ + "did" => $this->did, + ]; + } + + public function type(): string + { + return "mention"; + } +} diff --git a/src/Lexicons/App/Bsky/RichText/Tag.php b/src/Lexicons/App/Bsky/RichText/Tag.php new file mode 100644 index 0000000..bcb2108 --- /dev/null +++ b/src/Lexicons/App/Bsky/RichText/Tag.php @@ -0,0 +1,34 @@ + 640) { + throw new InvalidArgumentException("Tag cannot be longer than 640 characters."); + } + + $this->tag = $tag; + } + + public function schema(): array + { + return [ + "tag" => $this->tag + ]; + } + + public function type(): string + { + return "tag"; + } +} diff --git a/tests/Unit/Lexicons/App/Bsky/RichText/FeatureAbstractTest.php b/tests/Unit/Lexicons/App/Bsky/RichText/FeatureAbstractTest.php new file mode 100644 index 0000000..5144cce --- /dev/null +++ b/tests/Unit/Lexicons/App/Bsky/RichText/FeatureAbstractTest.php @@ -0,0 +1,49 @@ +faker = Factory::create(); + } + + /** @dataProvider featureProvider */ + public function testFeatureSerializationIsCorrect(string $class, string $input, array $expectedSchema): void + { + $instance = new $class($input); + + $this->assertSame($this->buildExpectedJson($expectedSchema), json_encode($instance)); + $this->assertSame($this->buildExpectedJson($expectedSchema), (string)$instance); + } + + public function featureProvider(): array + { + $faker = Factory::create(); + + $url = $faker->url; + $did = $faker->uuid; + $tag = $faker->word; + + return [ + [Link::class, $url, ['type' => 'link', 'uri' => $url]], + [Mention::class, $did, ['type' => 'mention', 'did' => $did]], + [Tag::class, $tag, ['type' => 'tag', 'tag' => $tag]], + ]; + } + + private function buildExpectedJson(array $schema): string + { + return json_encode($schema); + } +} diff --git a/tests/Unit/Lexicons/App/Bsky/RichText/LinkTest.php b/tests/Unit/Lexicons/App/Bsky/RichText/LinkTest.php new file mode 100644 index 0000000..9ae978f --- /dev/null +++ b/tests/Unit/Lexicons/App/Bsky/RichText/LinkTest.php @@ -0,0 +1,51 @@ +faker = Factory::create(); + } + + public function testConstructorThrowsExceptionWhenPassedInvalidDataType() + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage("Invalid URI: 123"); + + new Link(123); + } + + public function testLinkThrowsExceptionWhenPassedInvalidURL() + { + $invalidURL = $this->faker->word; + + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage("Invalid URI: $invalidURL"); + + new Link($invalidURL); + } + + /** + * @throws InvalidArgumentException|ReflectionException + */ + public function testLinkConstructorWorksCorrectly() + { + $url = $this->faker->url; + $link = new Link($url); + + $this->assertSame($url, $this->getPropertyValue('url', $link)); + } +} diff --git a/tests/Unit/Lexicons/App/Bsky/RichText/MentionTest.php b/tests/Unit/Lexicons/App/Bsky/RichText/MentionTest.php new file mode 100644 index 0000000..b07447d --- /dev/null +++ b/tests/Unit/Lexicons/App/Bsky/RichText/MentionTest.php @@ -0,0 +1,20 @@ +faker->word; + $mention = new Mention($expected); + + $this->assertSame($expected, $this->getPropertyValue('did', $mention)); + } +} diff --git a/tests/Unit/Lexicons/App/Bsky/RichText/TagTest.php b/tests/Unit/Lexicons/App/Bsky/RichText/TagTest.php new file mode 100644 index 0000000..e0507de --- /dev/null +++ b/tests/Unit/Lexicons/App/Bsky/RichText/TagTest.php @@ -0,0 +1,22 @@ +faker->word; + $tag = new Tag($expected); + + $this->assertSame($expected, $this->getPropertyValue('tag', $tag)); + } +} From 0ac209e71f8a08f7730d5fc6f2fcb37ee3e8c5ea Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Mon, 30 Sep 2024 21:41:01 +0400 Subject: [PATCH 06/58] Update dependencies --- composer.lock | 74 +++++++++++++++++++++++++-------------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/composer.lock b/composer.lock index 93b0564..44e0bc8 100644 --- a/composer.lock +++ b/composer.lock @@ -232,16 +232,16 @@ }, { "name": "shahmal1yev/gcollection", - "version": "1.0.6", + "version": "1.0.7", "source": { "type": "git", "url": "https://github.com/shahmal1yev/gcollection.git", - "reference": "17c04887dd852eeedb4451e1d276d4faa22eb15a" + "reference": "1ec135b2c65e15b1ab97b886c21bf49adc1358cc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/shahmal1yev/gcollection/zipball/17c04887dd852eeedb4451e1d276d4faa22eb15a", - "reference": "17c04887dd852eeedb4451e1d276d4faa22eb15a", + "url": "https://api.github.com/repos/shahmal1yev/gcollection/zipball/1ec135b2c65e15b1ab97b886c21bf49adc1358cc", + "reference": "1ec135b2c65e15b1ab97b886c21bf49adc1358cc", "shasum": "" }, "require": { @@ -261,9 +261,9 @@ "description": "GenericCollection is a versatile PHP library that provides a type-safe collection class for managing various data types. Simplify your data management with intuitive methods and strong type constraints.", "support": { "issues": "https://github.com/shahmal1yev/gcollection/issues", - "source": "https://github.com/shahmal1yev/gcollection/tree/1.0.6" + "source": "https://github.com/shahmal1yev/gcollection/tree/1.0.7" }, - "time": "2024-07-27T22:29:24+00:00" + "time": "2024-09-30T17:35:29+00:00" }, { "name": "symfony/deprecation-contracts", @@ -334,20 +334,20 @@ }, { "name": "symfony/polyfill-mbstring", - "version": "v1.30.0", + "version": "v1.31.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "fd22ab50000ef01661e2a31d850ebaa297f8e03c" + "reference": "85181ba99b2345b0ef10ce42ecac37612d9fd341" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/fd22ab50000ef01661e2a31d850ebaa297f8e03c", - "reference": "fd22ab50000ef01661e2a31d850ebaa297f8e03c", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/85181ba99b2345b0ef10ce42ecac37612d9fd341", + "reference": "85181ba99b2345b0ef10ce42ecac37612d9fd341", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=7.2" }, "provide": { "ext-mbstring": "*" @@ -394,7 +394,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.30.0" + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.31.0" }, "funding": [ { @@ -410,24 +410,24 @@ "type": "tidelift" } ], - "time": "2024-06-19T12:30:46+00:00" + "time": "2024-09-09T11:45:10+00:00" }, { "name": "symfony/polyfill-php80", - "version": "v1.30.0", + "version": "v1.31.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "77fa7995ac1b21ab60769b7323d600a991a90433" + "reference": "60328e362d4c2c802a54fcbf04f9d3fb892b4cf8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/77fa7995ac1b21ab60769b7323d600a991a90433", - "reference": "77fa7995ac1b21ab60769b7323d600a991a90433", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/60328e362d4c2c802a54fcbf04f9d3fb892b4cf8", + "reference": "60328e362d4c2c802a54fcbf04f9d3fb892b4cf8", "shasum": "" }, "require": { - "php": ">=7.1" + "php": ">=7.2" }, "type": "library", "extra": { @@ -474,7 +474,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php80/tree/v1.30.0" + "source": "https://github.com/symfony/polyfill-php80/tree/v1.31.0" }, "funding": [ { @@ -490,20 +490,20 @@ "type": "tidelift" } ], - "time": "2024-05-31T15:07:36+00:00" + "time": "2024-09-09T11:45:10+00:00" }, { "name": "symfony/translation", - "version": "v5.4.42", + "version": "v5.4.44", "source": { "type": "git", "url": "https://github.com/symfony/translation.git", - "reference": "1d702caccb9f091b738696185f778b1bfef7b5b2" + "reference": "6fed3a20b5b87ee9cdd9dacf545922b8fd475921" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/translation/zipball/1d702caccb9f091b738696185f778b1bfef7b5b2", - "reference": "1d702caccb9f091b738696185f778b1bfef7b5b2", + "url": "https://api.github.com/repos/symfony/translation/zipball/6fed3a20b5b87ee9cdd9dacf545922b8fd475921", + "reference": "6fed3a20b5b87ee9cdd9dacf545922b8fd475921", "shasum": "" }, "require": { @@ -571,7 +571,7 @@ "description": "Provides tools to internationalize your application", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/translation/tree/v5.4.42" + "source": "https://github.com/symfony/translation/tree/v5.4.44" }, "funding": [ { @@ -587,7 +587,7 @@ "type": "tidelift" } ], - "time": "2024-07-26T12:14:19+00:00" + "time": "2024-09-15T08:12:35+00:00" }, { "name": "symfony/translation-contracts", @@ -864,16 +864,16 @@ }, { "name": "nikic/php-parser", - "version": "v5.1.0", + "version": "v5.3.0", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "683130c2ff8c2739f4822ff7ac5c873ec529abd1" + "reference": "3abf7425cd284141dc5d8d14a9ee444de3345d1a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/683130c2ff8c2739f4822ff7ac5c873ec529abd1", - "reference": "683130c2ff8c2739f4822ff7ac5c873ec529abd1", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/3abf7425cd284141dc5d8d14a9ee444de3345d1a", + "reference": "3abf7425cd284141dc5d8d14a9ee444de3345d1a", "shasum": "" }, "require": { @@ -916,9 +916,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v5.1.0" + "source": "https://github.com/nikic/PHP-Parser/tree/v5.3.0" }, - "time": "2024-07-01T20:03:41+00:00" + "time": "2024-09-29T13:56:26+00:00" }, { "name": "phar-io/manifest", @@ -1040,16 +1040,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.12.3", + "version": "1.12.5", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "0fcbf194ab63d8159bb70d9aa3e1350051632009" + "reference": "7e6c6cb7cecb0a6254009a1a8a7d54ec99812b17" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/0fcbf194ab63d8159bb70d9aa3e1350051632009", - "reference": "0fcbf194ab63d8159bb70d9aa3e1350051632009", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/7e6c6cb7cecb0a6254009a1a8a7d54ec99812b17", + "reference": "7e6c6cb7cecb0a6254009a1a8a7d54ec99812b17", "shasum": "" }, "require": { @@ -1094,7 +1094,7 @@ "type": "github" } ], - "time": "2024-09-09T08:10:35+00:00" + "time": "2024-09-26T12:45:22+00:00" }, { "name": "phpunit/php-code-coverage", From 37acb541089c6d24f80e1ca90f32c0a5b41786b1 Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Wed, 9 Oct 2024 01:50:01 +0400 Subject: [PATCH 07/58] WIP: Implement Post Builder --- src/API/Com/Atrproto/Repo/UploadBlob.php | 2 +- src/Collections/FacetCollection.php | 15 ++ src/Collections/FeatureCollection.php | 14 ++ .../Types/NonPrimitive/FollowerAssetType.php | 2 +- .../Types/NonPrimitive/LabelAssetType.php | 2 +- .../Types/NonPrimitive/ProfileAssetType.php | 2 +- src/Contracts/BuilderInterface.php | 8 + src/Contracts/LexiconBuilder.php | 9 + .../App/Bsky/Embed/EmbedInterface.php | 9 + .../App/Bsky/Embed/ImageInterface.php | 12 + .../App/Bsky/Embed/VideoInterface.php | 15 ++ .../App/Bsky/Feed/PostBuilderContract.php | 25 +++ .../App/Bsky/RichText/ByteSliceContract.php | 11 + .../App/Bsky/RichText/FacetContract.php | 13 ++ src/Contracts/Stringable.php | 8 + src/Exceptions/RuntimeException.php | 7 + .../Requests/App/Bsky/Actor/GetProfile.php | 2 +- .../Requests/App/Bsky/Graph/GetFollowers.php | 2 +- src/Lexicons/App/Bsky/Embed/BlobHandler.php | 49 +++++ src/Lexicons/App/Bsky/Embed/Caption.php | 67 ++++++ .../Embed/Collections/CaptionCollection.php | 42 ++++ .../Embed/Collections/ImageCollection.php | 57 +++++ src/Lexicons/App/Bsky/Embed/File.php | 35 +++ src/Lexicons/App/Bsky/Embed/Image.php | 70 ++++++ src/Lexicons/App/Bsky/Embed/Video.php | 85 ++++++++ src/Lexicons/App/Bsky/Feed/Post.php | 205 ++++++++++++++++++ src/Lexicons/App/Bsky/RichText/ByteSlice.php | 35 +++ src/Lexicons/App/Bsky/RichText/Facet.php | 47 ++++ .../App/Bsky/RichText/FeatureAbstract.php | 28 ++- .../App/Bsky/RichText/FeatureFactory.php | 22 ++ src/Lexicons/App/Bsky/RichText/Link.php | 24 +- src/Lexicons/App/Bsky/RichText/Mention.php | 19 +- src/Lexicons/App/Bsky/RichText/Tag.php | 28 +-- src/Resources/Assets/FollowersAsset.php | 2 +- src/Resources/Assets/LabelsAsset.php | 2 +- src/Resources/BaseResource.php | 2 +- src/{Helpers => Support}/Arr.php | 2 +- src/{Helpers => Support}/File.php | 2 +- src/Support/Media.php | 10 + .../Unit/Lexicons/App/Bsky/Feed/PostTest.php | 195 +++++++++++++++++ .../App/Bsky/RichText/FeatureAbstractTest.php | 58 ++--- .../App/Bsky/RichText/FeatureTests.php | 110 ++++++++++ .../Lexicons/App/Bsky/RichText/LinkTest.php | 46 +--- .../App/Bsky/RichText/MentionTest.php | 15 +- .../Lexicons/App/Bsky/RichText/TagTest.php | 17 +- 45 files changed, 1276 insertions(+), 156 deletions(-) create mode 100644 src/Collections/FacetCollection.php create mode 100644 src/Collections/FeatureCollection.php rename src/{GenericCollection => Collections}/Types/NonPrimitive/FollowerAssetType.php (82%) rename src/{GenericCollection => Collections}/Types/NonPrimitive/LabelAssetType.php (81%) rename src/{GenericCollection => Collections}/Types/NonPrimitive/ProfileAssetType.php (81%) create mode 100644 src/Contracts/BuilderInterface.php create mode 100644 src/Contracts/LexiconBuilder.php create mode 100644 src/Contracts/Lexicons/App/Bsky/Embed/EmbedInterface.php create mode 100644 src/Contracts/Lexicons/App/Bsky/Embed/ImageInterface.php create mode 100644 src/Contracts/Lexicons/App/Bsky/Embed/VideoInterface.php create mode 100644 src/Contracts/Lexicons/App/Bsky/Feed/PostBuilderContract.php create mode 100644 src/Contracts/Lexicons/App/Bsky/RichText/ByteSliceContract.php create mode 100644 src/Contracts/Lexicons/App/Bsky/RichText/FacetContract.php create mode 100644 src/Contracts/Stringable.php create mode 100644 src/Exceptions/RuntimeException.php create mode 100644 src/Lexicons/App/Bsky/Embed/BlobHandler.php create mode 100644 src/Lexicons/App/Bsky/Embed/Caption.php create mode 100644 src/Lexicons/App/Bsky/Embed/Collections/CaptionCollection.php create mode 100644 src/Lexicons/App/Bsky/Embed/Collections/ImageCollection.php create mode 100644 src/Lexicons/App/Bsky/Embed/File.php create mode 100644 src/Lexicons/App/Bsky/Embed/Image.php create mode 100644 src/Lexicons/App/Bsky/Embed/Video.php create mode 100644 src/Lexicons/App/Bsky/Feed/Post.php create mode 100644 src/Lexicons/App/Bsky/RichText/ByteSlice.php create mode 100644 src/Lexicons/App/Bsky/RichText/Facet.php create mode 100644 src/Lexicons/App/Bsky/RichText/FeatureFactory.php rename src/{Helpers => Support}/Arr.php (99%) rename src/{Helpers => Support}/File.php (99%) create mode 100644 src/Support/Media.php create mode 100644 tests/Unit/Lexicons/App/Bsky/Feed/PostTest.php create mode 100644 tests/Unit/Lexicons/App/Bsky/RichText/FeatureTests.php diff --git a/src/API/Com/Atrproto/Repo/UploadBlob.php b/src/API/Com/Atrproto/Repo/UploadBlob.php index ce205f2..a81d934 100644 --- a/src/API/Com/Atrproto/Repo/UploadBlob.php +++ b/src/API/Com/Atrproto/Repo/UploadBlob.php @@ -4,7 +4,7 @@ use Atproto\Contracts\HTTP\RequestContract; use Atproto\Exceptions\Http\Request\RequestBodyHasMissingRequiredFields; -use Atproto\Helpers\File; +use Atproto\Support\File; use Atproto\Resources\Com\Atproto\Repo\UploadBlobResource; use InvalidArgumentException; diff --git a/src/Collections/FacetCollection.php b/src/Collections/FacetCollection.php new file mode 100644 index 0000000..fd55269 --- /dev/null +++ b/src/Collections/FacetCollection.php @@ -0,0 +1,15 @@ + $item instanceof FacetContract, $collection); + } +} diff --git a/src/Collections/FeatureCollection.php b/src/Collections/FeatureCollection.php new file mode 100644 index 0000000..02e0569 --- /dev/null +++ b/src/Collections/FeatureCollection.php @@ -0,0 +1,14 @@ + $feature instanceof FeatureAbstract, $features); + } +} diff --git a/src/GenericCollection/Types/NonPrimitive/FollowerAssetType.php b/src/Collections/Types/NonPrimitive/FollowerAssetType.php similarity index 82% rename from src/GenericCollection/Types/NonPrimitive/FollowerAssetType.php rename to src/Collections/Types/NonPrimitive/FollowerAssetType.php index 9d0c79c..9e156e3 100644 --- a/src/GenericCollection/Types/NonPrimitive/FollowerAssetType.php +++ b/src/Collections/Types/NonPrimitive/FollowerAssetType.php @@ -1,6 +1,6 @@ path = $path; + $this->handle(); + } + + /** + * @throws InvalidArgumentException + */ + private function handle(): void + { + $this->isFile(); + $this->isReadable(); + $this->isValid(); + } + + /** + * @throws InvalidArgumentException + */ + private function isFile(): void + { + if (! is_file($this->path)) { + throw new InvalidArgumentException("$this->path is not a file."); + } + } + + /** + * @throws InvalidArgumentException + */ + private function isReadable(): void + { + if (! is_readable($this->path)) { + throw new InvalidArgumentException("$this->path is not readable."); + } + } +} \ No newline at end of file diff --git a/src/Lexicons/App/Bsky/Embed/Caption.php b/src/Lexicons/App/Bsky/Embed/Caption.php new file mode 100644 index 0000000..9dd7fb6 --- /dev/null +++ b/src/Lexicons/App/Bsky/Embed/Caption.php @@ -0,0 +1,67 @@ +lang($lang); + $this->file($file); + } + + public function lang(string $lang = null): string + { + if (is_null($lang)) { + return $this->lang; + } + + $this->lang = $lang; + + return $this->lang; + } + + /** + * @throws InvalidArgumentException + */ + public function file(File $file = null) + { + if (is_null($file)) { + return $this->file; + } + + if ($file->size() > self::MAX_SIZE) { + throw new InvalidArgumentException($file->path().' is too large.'); + } + + if ($file->type() !== 'text/vtt') { + throw new InvalidArgumentException($file->path().' is not a text vtt.'); + } + + $this->file = $file; + + return $this; + } + + /** + * @throws InvalidArgumentException + */ + public function jsonSerialize(): array + { + return [ + 'lang' => $this->lang(), + 'file' => $this->file()->blob(), + ]; + } +} diff --git a/src/Lexicons/App/Bsky/Embed/Collections/CaptionCollection.php b/src/Lexicons/App/Bsky/Embed/Collections/CaptionCollection.php new file mode 100644 index 0000000..e2c66b7 --- /dev/null +++ b/src/Lexicons/App/Bsky/Embed/Collections/CaptionCollection.php @@ -0,0 +1,42 @@ + $item instanceof Caption, $collection); + } + + public function validate($value): bool + { + return parent::validate($value) && $this->validateLength(); + } + + private function validateLength(): bool + { + return $this->count() <= self::MAX_SIZE; + } + + public function validateWithException($value): void + { + parent::validateWithException($value); + + if (! $this->validateLength()) { + throw new InvalidArgumentException("Caption length must be less than or equal " . self::MAX_SIZE); + } + } + + public function jsonSerialize() + { + return $this->toArray(); + } +} diff --git a/src/Lexicons/App/Bsky/Embed/Collections/ImageCollection.php b/src/Lexicons/App/Bsky/Embed/Collections/ImageCollection.php new file mode 100644 index 0000000..6f3b3aa --- /dev/null +++ b/src/Lexicons/App/Bsky/Embed/Collections/ImageCollection.php @@ -0,0 +1,57 @@ + $item instanceof ImageInterface, $collection); + } + + private function validateLength(): bool + { + return ($this->count() <= self::MAX_ITEM); + } + + private function validateSize(ImageInterface $image): bool + { + return $image->size() <= self::MAX_SIZE; + } + + public function validate($value): bool + { + return parent::validate($value) + && $this->validateSize($value) + && $this->validateLength(); + } + + /** + * @throws InvalidArgumentException + */ + public function validateWithException($value): void + { + parent::validateWithException($value); + + if (! $this->validateLength()) { + throw new InvalidArgumentException("Image limit exceeded. Maximum allowed images: ".self::MAX_ITEM); + } + + if (! $this->validateSize($value)) { + throw new InvalidArgumentException("Image size exceeded. Maximum allowed size: ".self::MAX_SIZE); + } + } + + public function jsonSerialize(): array + { + return $this->toArray(); + } +} diff --git a/src/Lexicons/App/Bsky/Embed/File.php b/src/Lexicons/App/Bsky/Embed/File.php new file mode 100644 index 0000000..61d1b93 --- /dev/null +++ b/src/Lexicons/App/Bsky/Embed/File.php @@ -0,0 +1,35 @@ +path); + } + + public function type(): string + { + return mime_content_type($this->path); + } + + public function blob(): string + { + return file_get_contents($this->path); + } + + public function path(): string + { + return $this->path; + } + + public function __toString(): string + { + return $this->blob(); + } +} diff --git a/src/Lexicons/App/Bsky/Embed/Image.php b/src/Lexicons/App/Bsky/Embed/Image.php new file mode 100644 index 0000000..7036263 --- /dev/null +++ b/src/Lexicons/App/Bsky/Embed/Image.php @@ -0,0 +1,70 @@ +type(), 'image/')) { + throw new InvalidArgumentException($file->path()." is not a valid image file."); + } + + $this->file = $file; + $this->alt = $alt; + } + + public function alt(string $alt = null) + { + if (is_null($alt)) { + return $this->alt; + } + + $this->alt = $alt; + + return $this; + } + + /** + * @throws InvalidArgumentException + */ + public function aspectRatio(int $width = null, int $height = null) + { + if (is_null($width) && is_null($height)) { + return $this->aspectRatio; + } + + if ($width < 1 || $height < 1) { + throw new InvalidArgumentException("Width and height must be at least 1"); + } + + $this->aspectRatio = [ + 'width' => $width, + 'height' => $height + ]; + + return $this; + } + + /** + * @throws InvalidArgumentException + */ + public function jsonSerialize(): array + { + return array_filter([ + 'alt' => $this->alt(), + 'image' => $this->file->blob(), + 'aspectRatio' => $this->aspectRatio() ?: null, + ]); + } +} diff --git a/src/Lexicons/App/Bsky/Embed/Video.php b/src/Lexicons/App/Bsky/Embed/Video.php new file mode 100644 index 0000000..f4de269 --- /dev/null +++ b/src/Lexicons/App/Bsky/Embed/Video.php @@ -0,0 +1,85 @@ +type()) { + throw new InvalidArgumentException($file->path()." is not a valid video file."); + } + + $this->file = $file; + + $this->captions = new CaptionCollection(); + } + + /** + * @throws InvalidArgumentException + */ + public function jsonSerialize(): array + { + return array_filter([ + 'alt' => $this->alt() ?: null, + 'video' => $this->file->blob(), + 'aspectRatio' => $this->aspectRatio() ?: null, + 'captions' => $this->captions()->toArray() ?: null, + ]); + } + + public function alt(string $alt = null) + { + if (is_null($alt)) { + return $this->alt; + } + + $this->alt = $alt; + + return $this; + } + + /** + * @throws InvalidArgumentException + */ + public function aspectRatio(int $width = null, int $height = null) + { + if (is_null($width) && is_null($height)) { + return $this->aspectRatio; + } + + if ($width < 1 || $height < 1) { + throw new InvalidArgumentException("Width and height must be greater than 1"); + } + + $this->aspectRatio = [ + 'width' => $width, + 'height' => $height + ]; + + return $this; + } + + public function captions(CaptionCollection $captions = null) + { + if (is_null($captions)) { + return $this->captions; + } + + $this->captions = $captions; + + return $this; + } +} diff --git a/src/Lexicons/App/Bsky/Feed/Post.php b/src/Lexicons/App/Bsky/Feed/Post.php new file mode 100644 index 0000000..560b1af --- /dev/null +++ b/src/Lexicons/App/Bsky/Feed/Post.php @@ -0,0 +1,205 @@ +facets = new FacetCollection(); + } + + /** + * @throws InvalidArgumentException + */ + public function text(...$items): PostBuilderContract + { + foreach ($items as $index => $item) { + $this->validate($item, $index); + $this->processItem($item); + } + + return $this; + } + + /** + * Adds a tag to the post. + * + * @throws InvalidArgumentException + */ + public function tag(string $reference, string $label = null): PostBuilderContract + { + return $this->addFeatureItem('tag', $reference, $label); + } + + /** + * Adds a link to the post. + * + * @throws InvalidArgumentException + */ + public function link(string $reference, string $label = null): PostBuilderContract + { + return $this->addFeatureItem('link', $reference, $label); + } + + /** + * Adds a mention to the post. + * + * @throws InvalidArgumentException + */ + public function mention(string $reference, string $label = null): PostBuilderContract + { + return $this->addFeatureItem('mention', $reference, $label); + } + + public function embed(...$embeds): PostBuilderContract + { + return $this; + } + + public function createdAt(DateTimeImmutable $dateTime): PostBuilderContract + { + $this->createdAt = $dateTime; + + return $this; + } + + public function jsonSerialize(): array + { + return [ + '$type' => self::TYPE_NAME, + 'createdAt' => $this->getFormattedCreatedAt(), + 'text' => $this->text, + 'facets' => $this->facets->toArray(), + ]; + } + + public function __toString(): string + { + return json_encode($this); + } + + private function isString($item): bool + { + return is_scalar($item); + } + + private function isFeature($item): bool + { + return $item instanceof FeatureAbstract; + } + + /** + * Validates the given item. + * + * @throws InvalidArgumentException + */ + private function validate($item, int $index = 0): void + { + if (!$this->isString($item) && !$this->isFeature($item)) { + throw new InvalidArgumentException( + sprintf( + 'Argument at index %d is invalid: must be a string or an instance of %s.', + $index + 1, + FeatureAbstract::class + ) + ); + } + + if ($this->isString($item) && mb_strlen($item) > self::TEXT_LIMIT) { + throw new InvalidArgumentException( + sprintf( + 'Text must be less than or equal to %d characters.', + self::TEXT_LIMIT + ) + ); + } + } + + /** + * Processes the item, adding it to the post text or as a feature. + * @throws InvalidArgumentException + */ + private function processItem($item): void + { + if ($this->isString($item)) { + $this->addString($item); + } else { + $this->addFeature($item); + } + } + + /** + * Adds a feature item like tag, link, or mention to the post. + * + * @throws InvalidArgumentException + */ + private function addFeatureItem(string $type, string $reference, ?string $label): PostBuilderContract + { + $feature = FeatureFactory::{$type}($reference, $label); + $this->addFeature($feature); + + return $this; + } + + /** + * Adds a string to the post text. + * + * @param string $string + */ + private function addString(string $string): void + { + $this->text .= $string; + } + + /** + * Adds a feature to the post. + * + * @throws InvalidArgumentException + */ + private function addFeature(FeatureAbstract $feature): void + { + $label = (string) $feature; + $this->text .= $label; + + try { + $facet = new Facet( + new FeatureCollection([$feature]), + new ByteSlice($this->text, $label) + ); + $this->facets[] = $facet; + } catch (\GenericCollection\Exceptions\InvalidArgumentException $e) { + throw new InvalidArgumentException( + sprintf('Feature must be an instance of %s.', FeatureAbstract::class) + ); + } + } + + /** + * Returns the formatted creation date. + */ + private function getFormattedCreatedAt(): string + { + $createdAt = $this->createdAt ?: Carbon::now(); + + return $createdAt->format(DATE_ATOM); + } +} diff --git a/src/Lexicons/App/Bsky/RichText/ByteSlice.php b/src/Lexicons/App/Bsky/RichText/ByteSlice.php new file mode 100644 index 0000000..9f5ab96 --- /dev/null +++ b/src/Lexicons/App/Bsky/RichText/ByteSlice.php @@ -0,0 +1,35 @@ +text = $text; + $this->added = $added; + } + + public function start(): int + { + return mb_strpos($this->text, $this->added); + } + + public function end(): int + { + return mb_strpos($this->text, $this->added) + mb_strlen($this->added); + } + + public function jsonSerialize(): array + { + return [ + 'byteStart' => $this->start(), + 'byteEnd' => $this->end(), + ]; + } +} \ No newline at end of file diff --git a/src/Lexicons/App/Bsky/RichText/Facet.php b/src/Lexicons/App/Bsky/RichText/Facet.php new file mode 100644 index 0000000..dfbb9a4 --- /dev/null +++ b/src/Lexicons/App/Bsky/RichText/Facet.php @@ -0,0 +1,47 @@ +features = $features; + $this->byteSlice = $byteSlice; + } + + public function features(): FeatureCollection + { + return $this->features; + } + + public function byteSlice(): ByteSliceContract + { + return $this->byteSlice; + } + + public function jsonSerialize(): array + { + return [ + 'index' => $this->byteSlice, + 'features' => $this->features->toArray() + ]; + } + + public function __toString(): string + { + return json_encode($this); + } +} diff --git a/src/Lexicons/App/Bsky/RichText/FeatureAbstract.php b/src/Lexicons/App/Bsky/RichText/FeatureAbstract.php index 9ea75a0..bb50204 100644 --- a/src/Lexicons/App/Bsky/RichText/FeatureAbstract.php +++ b/src/Lexicons/App/Bsky/RichText/FeatureAbstract.php @@ -3,23 +3,29 @@ namespace Atproto\Lexicons\App\Bsky\RichText; use Atproto\Contracts\LexiconBuilder; -use Atproto\Contracts\Lexicons\App\Bsky\RichText\FeatureContract; +use Atproto\Contracts\Stringable; -abstract class FeatureAbstract implements LexiconBuilder +abstract class FeatureAbstract implements LexiconBuilder, Stringable { - public function jsonSerialize(): array + protected string $reference; + protected string $label; + + public function __construct(string $reference, string $label = null) { - return array_merge( - ['type' => $this->type(),], - $this->schema() - ); + if (is_null($label)) { + $label = $reference; + } + + $this->reference = $reference; + $this->label = $label; } - public function __toString(): string + final public function jsonSerialize(): array { - return json_encode($this); + return ['type' => $this->type()] + $this->schema(); } - abstract public function schema(): array; - abstract public function type(): string; + abstract protected function type(): string; + + abstract protected function schema(): array; } diff --git a/src/Lexicons/App/Bsky/RichText/FeatureFactory.php b/src/Lexicons/App/Bsky/RichText/FeatureFactory.php new file mode 100644 index 0000000..01a9682 --- /dev/null +++ b/src/Lexicons/App/Bsky/RichText/FeatureFactory.php @@ -0,0 +1,22 @@ +url = $url; + return [ + "label" => $this->label, + "uri" => $this->reference, + ]; } - public function schema(): array + public function __toString(): string { - return [ - "uri" => $this->url, - ]; + return $this->label; } - public function type(): string + protected function type(): string { return "link"; } diff --git a/src/Lexicons/App/Bsky/RichText/Mention.php b/src/Lexicons/App/Bsky/RichText/Mention.php index dbbfc16..989626b 100644 --- a/src/Lexicons/App/Bsky/RichText/Mention.php +++ b/src/Lexicons/App/Bsky/RichText/Mention.php @@ -4,22 +4,23 @@ class Mention extends FeatureAbstract { - private string $did; + protected ?string $type = 'mention'; - public function __construct(string $did) + protected function schema(): array { - $this->did = $did; + return [ + 'label' => "@$this->label", + 'did' => $this->reference, + ]; } - public function schema(): array + public function __toString(): string { - return [ - "did" => $this->did, - ]; + return "@$this->label"; } - public function type(): string + protected function type(): string { - return "mention"; + return 'mention'; } } diff --git a/src/Lexicons/App/Bsky/RichText/Tag.php b/src/Lexicons/App/Bsky/RichText/Tag.php index bcb2108..9f3291e 100644 --- a/src/Lexicons/App/Bsky/RichText/Tag.php +++ b/src/Lexicons/App/Bsky/RichText/Tag.php @@ -2,33 +2,23 @@ namespace Atproto\Lexicons\App\Bsky\RichText; -use Atproto\Exceptions\InvalidArgumentException; - class Tag extends FeatureAbstract { - private string $tag; - - /** - * @throws InvalidArgumentException - */ - public function __construct(string $tag) + protected function schema(): array { - if (mb_strlen($tag, "UTF-8") > 640) { - throw new InvalidArgumentException("Tag cannot be longer than 640 characters."); - } - - $this->tag = $tag; + return [ + "label" => "#$this->label", + "tag" => $this->reference, + ]; } - public function schema(): array + public function __toString(): string { - return [ - "tag" => $this->tag - ]; + return "#$this->label"; } - public function type(): string + protected function type(): string { - return "tag"; + return 'tag'; } } diff --git a/src/Resources/Assets/FollowersAsset.php b/src/Resources/Assets/FollowersAsset.php index b502797..637fcc3 100644 --- a/src/Resources/Assets/FollowersAsset.php +++ b/src/Resources/Assets/FollowersAsset.php @@ -3,7 +3,7 @@ namespace Atproto\Resources\Assets; use Atproto\Contracts\HTTP\Resources\AssetContract; -use Atproto\GenericCollection\Types\NonPrimitive\FollowerAssetType; +use Atproto\Collections\Types\NonPrimitive\FollowerAssetType; use GenericCollection\Exceptions\InvalidArgumentException; use GenericCollection\GenericCollection; use GenericCollection\Interfaces\TypeInterface; diff --git a/src/Resources/Assets/LabelsAsset.php b/src/Resources/Assets/LabelsAsset.php index 6c9dc19..9894d25 100644 --- a/src/Resources/Assets/LabelsAsset.php +++ b/src/Resources/Assets/LabelsAsset.php @@ -3,7 +3,7 @@ namespace Atproto\Resources\Assets; use Atproto\Contracts\HTTP\Resources\AssetContract; -use Atproto\GenericCollection\Types\NonPrimitive\LabelAssetType; +use Atproto\Collections\Types\NonPrimitive\LabelAssetType; use GenericCollection\Exceptions\InvalidArgumentException; use GenericCollection\GenericCollection; use GenericCollection\Interfaces\TypeInterface; diff --git a/src/Resources/BaseResource.php b/src/Resources/BaseResource.php index 0d0f346..fa1df67 100644 --- a/src/Resources/BaseResource.php +++ b/src/Resources/BaseResource.php @@ -4,7 +4,7 @@ use Atproto\Contracts\HTTP\Resources\AssetContract; use Atproto\Exceptions\Resource\BadAssetCallException; -use Atproto\Helpers\Arr; +use Atproto\Support\Arr; use Atproto\Traits\Castable; trait BaseResource diff --git a/src/Helpers/Arr.php b/src/Support/Arr.php similarity index 99% rename from src/Helpers/Arr.php rename to src/Support/Arr.php index 5bed62b..d8777ab 100644 --- a/src/Helpers/Arr.php +++ b/src/Support/Arr.php @@ -1,6 +1,6 @@ post = new Post(); + } + + /** + * @throws InvalidArgumentException + */ + public function testTextMethodWithBasicUsage() + { + $this->post->text('Hello, world!'); + $result = json_decode($this->post, true); + $this->assertEquals('Hello, world!', $result['text']); + } + + /** + * @throws InvalidArgumentException + */ + public function testTextMethod() + { + $this->post->text('Hello', ', ', new Mention('example:did:123', 'user'), "! It's ", 5, " o'clock now."); + $result = json_decode(json_encode($this->post), true); + $this->assertEquals("Hello, @user! It's 5 o'clock now.", $result['text']); + + $this->post->text('This ', new Mention('example:did:123', 'user'), '!'); + } + + /** + * @throws InvalidArgumentException + */ + public function testTagMethod() + { + $this->post->tag('example', 'test'); + $result = json_decode($this->post, true); + $this->assertEquals('#test', $result['text']); + $this->assertCount(1, $result['facets']); + } + + /** + * @throws InvalidArgumentException + */ + public function testLinkMethod() + { + $this->post->link('https://example.com', 'Example'); + $result = json_decode($this->post, true); + $this->assertEquals('Example', $result['text']); + $this->assertCount(1, $result['facets']); + } + + /** + * @throws InvalidArgumentException + */ + public function testMentionMethod() + { + $this->post->mention('did:example:123', 'user'); + $result = json_decode($this->post, true); + $this->assertEquals('@user', $result['text']); + $this->assertCount(1, $result['facets']); + } + + public function testCombinationOfMethods() + { + $this->post = $this->post(); + + $result = json_decode($this->post, true); + $this->assertEquals('Hello @user! Check out this link #example_tag', $result['text']); + $this->assertCount(3, $result['facets']); + } + + public function testCoordinatesOfFacets(): void + { + $this->post = $this->post(); + + $result = json_decode($this->post, true); + + $text = $result['text']; + $facets = $result['facets']; + + $this->assertSame($facets[0]['index'], $this->bytes($text, "@user")); + $this->assertSame($facets[1]['index'], $this->bytes($text, "this link")); + $this->assertSame($facets[2]['index'], $this->bytes($text, "#example_tag")); + } + + private function bytes(string $haystack, string $needle): array + { + $pos = mb_strpos($haystack, $needle); + $len = $pos + mb_strlen($needle); + + return [ + 'byteStart' => $pos, + 'byteEnd' => $len, + ]; + } + + private function post(): Post + { + return $this->post->text('Hello ') + ->mention('did:example:123', 'user') + ->text('! Check out ') + ->link('https://example.com', 'this link') + ->text(' ') + ->tag('example_tag'); + } + + /** + * @throws InvalidArgumentException + */ + public function testTextThrowsExceptionWhenLimitIsExceeded() + { + $this->post->text(str_repeat('a', 3000)); + + $this->expectException(InvalidArgumentException::class); + + $this->post->text(str_repeat('a', 3001)); + } + + public function testTextThrowsExceptionWhenPassedInvalidArgument(): void + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage( + "Argument at index 4 is invalid: must be a string or an instance of " . FeatureAbstract::class + ); + + $this->post->text(1, true, 'string', new Post); + } + + public function testCreatedAtField() + { + $result = json_decode($this->post, true); + $this->assertArrayHasKey('createdAt', $result); + $this->assertNotNull($result['createdAt']); + } + + public function testJsonSerialize() + { + $this->post->text('Test post'); + $result = $this->post->jsonSerialize(); + $this->assertArrayHasKey('$type', $result); + $this->assertEquals('app.bsky.feed.post', $result['$type']); + $this->assertArrayHasKey('text', $result); + $this->assertArrayHasKey('createdAt', $result); + $this->assertArrayHasKey('facets', $result); + } + + /** + * @throws InvalidArgumentException + */ + public function testCreatedAtAssignedByDefault(): void + { + $post = $this->post->text('Test post'); + $result = json_decode($post, true); + + $this->assertSame($result['createdAt'], Carbon::now()->toIso8601String()); + } + + public function testCreatedAtReturnsAssignedTime(): void + { + $timestamp = time() + 3600; // Get the current timestamp + $this->post->createdAt(new DateTimeImmutable("@$timestamp")); + + $actual = json_decode($this->post, false)->createdAt; + $expected = Carbon::now()->modify("+1 hour")->toIso8601String(); + + $this->assertSame( + $actual, + $expected, + ); + } + + public function testConstructorWorksCorrectlyOnDirectBuild(): void + { + $array = json_decode($this->post, true); + $json = json_encode($array); + + $this->assertTrue(is_array($array)); + $this->assertTrue(json_encode($array) === $json); + } +} diff --git a/tests/Unit/Lexicons/App/Bsky/RichText/FeatureAbstractTest.php b/tests/Unit/Lexicons/App/Bsky/RichText/FeatureAbstractTest.php index 5144cce..abdfb50 100644 --- a/tests/Unit/Lexicons/App/Bsky/RichText/FeatureAbstractTest.php +++ b/tests/Unit/Lexicons/App/Bsky/RichText/FeatureAbstractTest.php @@ -2,48 +2,52 @@ namespace Tests\Unit\Lexicons\App\Bsky\RichText; -use Atproto\Lexicons\App\Bsky\RichText\Link; -use Atproto\Lexicons\App\Bsky\RichText\Mention; -use Atproto\Lexicons\App\Bsky\RichText\Tag; -use Faker\Factory; +use Atproto\Lexicons\App\Bsky\RichText\FeatureAbstract; use PHPUnit\Framework\TestCase; +use ReflectionException; use Tests\Supports\Reflection; class FeatureAbstractTest extends TestCase { use Reflection; - public function setUp(): void + /** + * @throws ReflectionException + */ + public function testConstructorAssignsReferenceAndLabel() { - $this->faker = Factory::create(); - } + $mock = $this->getMockBuilder(FeatureAbstract::class) + ->setConstructorArgs(['reference', 'label']) + ->onlyMethods(['schema']) + ->getMockForAbstractClass(); - /** @dataProvider featureProvider */ - public function testFeatureSerializationIsCorrect(string $class, string $input, array $expectedSchema): void - { - $instance = new $class($input); + $reference = $this->getPropertyValue('reference', $mock); + $label = $this->getPropertyValue('label', $mock); - $this->assertSame($this->buildExpectedJson($expectedSchema), json_encode($instance)); - $this->assertSame($this->buildExpectedJson($expectedSchema), (string)$instance); + $this->assertSame('reference', $reference); + $this->assertSame('label', $label); } - public function featureProvider(): array + public function testJsonSerializeReturnsCorrectArray() { - $faker = Factory::create(); + $mock = $this->getMockBuilder(FeatureAbstract::class) + ->setConstructorArgs(['reference', 'label']) + ->onlyMethods(['schema', 'type']) + ->getMockForAbstractClass(); - $url = $faker->url; - $did = $faker->uuid; - $tag = $faker->word; + $schema = ['key' => 'value']; - return [ - [Link::class, $url, ['type' => 'link', 'uri' => $url]], - [Mention::class, $did, ['type' => 'mention', 'did' => $did]], - [Tag::class, $tag, ['type' => 'tag', 'tag' => $tag]], - ]; - } + $mock->expects($this->once()) + ->method('schema') + ->willReturn($schema); - private function buildExpectedJson(array $schema): string - { - return json_encode($schema); + $mock->expects($this->once()) + ->method('type') + ->willReturn('feature'); + + $this->assertSame( + ['type' => 'feature'] + $schema, + $mock->jsonSerialize() + ); } } diff --git a/tests/Unit/Lexicons/App/Bsky/RichText/FeatureTests.php b/tests/Unit/Lexicons/App/Bsky/RichText/FeatureTests.php new file mode 100644 index 0000000..b6237d5 --- /dev/null +++ b/tests/Unit/Lexicons/App/Bsky/RichText/FeatureTests.php @@ -0,0 +1,110 @@ +label = 'label'; + $this->reference = 'reference'; + } + + /** + * @throws ReflectionException + */ + public function testTypeReturnsCorrectType(): void + { + $feature = $this->feature($this->reference); + $method = $this->method('type', $feature); + $expected = $this->type; + + $this->assertSame( + $expected, + $method->invoke($feature) + ); + } + + public function test__toStringReturnsCorrectLabelWhenPassedBothParameters(): void + { + $feature = $this->feature($this->reference, $this->label); + $this->assert__toString($this->label, $feature); + } + + public function test__toStringReturnsCorrectLabelWhenPassedSingleParameter(): void + { + $feature = $this->feature($this->reference); + + $this->assert__toString($this->reference, $feature); + } + + private function assert__toString(string $expected, FeatureAbstract $feature): void + { + $this->assertEquals( + $this->prefix . $expected, + $feature + ); + } + + public function testSchemaReturnsCorrectSchemaWhenPassedBothParameters(): void + { + $feature = $this->feature($this->reference, $this->label); + + $expected = [ + 'type' => $this->type, + 'label' => $this->prefix . $this->label, + $this->key => $this->reference, + ]; + + $this->assertSchema($expected, $feature); + } + + public function testSchemaReturnsCorrectSchemaWhenPassedSingleParameter(): void + { + $expected = $this->schema($this->reference); + + $this->assertSchema($expected, $this->feature($this->reference)); + } + + private function schema(string $label): array + { + return [ + 'type' => $this->type, + 'label' => $this->prefix . $label, + $this->key => $this->reference, + ]; + } + + private function assertSchema(array $expected, FeatureAbstract $feature): void + { + $this->assertSame( + $expected, + json_decode(json_encode($feature), true) + ); + + $this->assertSame( + $expected, + $feature->jsonSerialize() + ); + } + + private function feature(string $reference, string $label = null): FeatureAbstract + { + $namespace = $this->namespace; + + if (! is_null($label)) { + return new $namespace($reference, $label); + } + + return new $namespace($reference); + } +} diff --git a/tests/Unit/Lexicons/App/Bsky/RichText/LinkTest.php b/tests/Unit/Lexicons/App/Bsky/RichText/LinkTest.php index 9ae978f..1730e65 100644 --- a/tests/Unit/Lexicons/App/Bsky/RichText/LinkTest.php +++ b/tests/Unit/Lexicons/App/Bsky/RichText/LinkTest.php @@ -2,50 +2,14 @@ namespace Tests\Unit\Lexicons\App\Bsky\RichText; -use Atproto\Exceptions\InvalidArgumentException; use Atproto\Lexicons\App\Bsky\RichText\Link; -use Faker\Factory; -use Faker\Generator; -use ReflectionException; -use Tests\Supports\Reflection; class LinkTest extends FeatureAbstractTest { - use Reflection; + use FeatureTests; - private Generator $faker; - - public function setUp(): void - { - $this->faker = Factory::create(); - } - - public function testConstructorThrowsExceptionWhenPassedInvalidDataType() - { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage("Invalid URI: 123"); - - new Link(123); - } - - public function testLinkThrowsExceptionWhenPassedInvalidURL() - { - $invalidURL = $this->faker->word; - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage("Invalid URI: $invalidURL"); - - new Link($invalidURL); - } - - /** - * @throws InvalidArgumentException|ReflectionException - */ - public function testLinkConstructorWorksCorrectly() - { - $url = $this->faker->url; - $link = new Link($url); - - $this->assertSame($url, $this->getPropertyValue('url', $link)); - } + private string $namespace = Link::class; + private string $type = 'link'; + private string $key = 'uri'; + private string $prefix = ''; } diff --git a/tests/Unit/Lexicons/App/Bsky/RichText/MentionTest.php b/tests/Unit/Lexicons/App/Bsky/RichText/MentionTest.php index b07447d..ba3bd46 100644 --- a/tests/Unit/Lexicons/App/Bsky/RichText/MentionTest.php +++ b/tests/Unit/Lexicons/App/Bsky/RichText/MentionTest.php @@ -3,18 +3,13 @@ namespace Tests\Unit\Lexicons\App\Bsky\RichText; use Atproto\Lexicons\App\Bsky\RichText\Mention; -use ReflectionException; class MentionTest extends FeatureAbstractTest { - /** - * @throws ReflectionException - */ - public function testConstructorWorksCorrectly(): void - { - $expected = $this->faker->word; - $mention = new Mention($expected); + use FeatureTests; - $this->assertSame($expected, $this->getPropertyValue('did', $mention)); - } + private string $namespace = Mention::class; + private string $type = 'mention'; + private string $key = 'did'; + private string $prefix = '@'; } diff --git a/tests/Unit/Lexicons/App/Bsky/RichText/TagTest.php b/tests/Unit/Lexicons/App/Bsky/RichText/TagTest.php index e0507de..4996fad 100644 --- a/tests/Unit/Lexicons/App/Bsky/RichText/TagTest.php +++ b/tests/Unit/Lexicons/App/Bsky/RichText/TagTest.php @@ -2,21 +2,14 @@ namespace Tests\Unit\Lexicons\App\Bsky\RichText; -use Atproto\Exceptions\InvalidArgumentException; use Atproto\Lexicons\App\Bsky\RichText\Tag; -use ReflectionException; class TagTest extends FeatureAbstractTest { - /** - * @throws ReflectionException - * @throws InvalidArgumentException - */ - public function testConstructorWorksCorrectly(): void - { - $expected = $this->faker->word; - $tag = new Tag($expected); + use FeatureTests; - $this->assertSame($expected, $this->getPropertyValue('tag', $tag)); - } + private string $namespace = Tag::class; + private string $type = 'tag'; + private string $key = 'tag'; + private string $prefix = '#'; } From 4c3a7c7f77a173c888430e6406a517ebfb0e9491 Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Thu, 10 Oct 2024 01:43:43 +0400 Subject: [PATCH 08/58] WIP: Implement components of post builder, improve validation, and add tests - Added `Stringable` interface to `File`, `Caption`, and `Image` for improved string handling. - Updated `BlobHandler` to remove unnecessary `isValid` check, simplifying file handling logic. - Enhanced `Caption` class with stricter validation for file size and type, using `InvalidArgumentException`. - Improved constructor and method handling in `Caption`, ensuring proper setting of file and language. - Created comprehensive unit tests for `Caption`, covering file validation, language setting, and JSON serialization. - Introduced `FileMocking` trait for reusable mock file generation in tests. --- .../App/Bsky/Embed/ImageInterface.php | 3 +- src/Lexicons/App/Bsky/Embed/BlobHandler.php | 3 +- src/Lexicons/App/Bsky/Embed/Caption.php | 16 +- src/Lexicons/App/Bsky/Embed/File.php | 2 +- src/Lexicons/App/Bsky/Embed/Image.php | 7 +- src/Support/File.php | 2 +- tests/Lexicons/App/Bsky/Embed/CaptionTest.php | 110 ++++++++++++++ tests/Lexicons/App/Bsky/Embed/FileMocking.php | 42 +++++ tests/Lexicons/App/Bsky/Embed/FileTest.php | 98 ++++++++++++ tests/Lexicons/App/Bsky/Embed/ImageTest.php | 143 ++++++++++++++++++ 10 files changed, 415 insertions(+), 11 deletions(-) create mode 100644 tests/Lexicons/App/Bsky/Embed/CaptionTest.php create mode 100644 tests/Lexicons/App/Bsky/Embed/FileMocking.php create mode 100644 tests/Lexicons/App/Bsky/Embed/FileTest.php create mode 100644 tests/Lexicons/App/Bsky/Embed/ImageTest.php diff --git a/src/Contracts/Lexicons/App/Bsky/Embed/ImageInterface.php b/src/Contracts/Lexicons/App/Bsky/Embed/ImageInterface.php index d4007ee..73d0a22 100644 --- a/src/Contracts/Lexicons/App/Bsky/Embed/ImageInterface.php +++ b/src/Contracts/Lexicons/App/Bsky/Embed/ImageInterface.php @@ -2,9 +2,10 @@ namespace Atproto\Contracts\Lexicons\App\Bsky\Embed; +use Atproto\Contracts\Stringable; use JsonSerializable; -interface ImageInterface extends JsonSerializable +interface ImageInterface extends JsonSerializable, Stringable { public function jsonSerialize(): array; public function alt(string $alt = null); diff --git a/src/Lexicons/App/Bsky/Embed/BlobHandler.php b/src/Lexicons/App/Bsky/Embed/BlobHandler.php index 060947d..0c8e243 100644 --- a/src/Lexicons/App/Bsky/Embed/BlobHandler.php +++ b/src/Lexicons/App/Bsky/Embed/BlobHandler.php @@ -24,7 +24,6 @@ private function handle(): void { $this->isFile(); $this->isReadable(); - $this->isValid(); } /** @@ -46,4 +45,4 @@ private function isReadable(): void throw new InvalidArgumentException("$this->path is not readable."); } } -} \ No newline at end of file +} diff --git a/src/Lexicons/App/Bsky/Embed/Caption.php b/src/Lexicons/App/Bsky/Embed/Caption.php index 9dd7fb6..4f205aa 100644 --- a/src/Lexicons/App/Bsky/Embed/Caption.php +++ b/src/Lexicons/App/Bsky/Embed/Caption.php @@ -2,10 +2,11 @@ namespace Atproto\Lexicons\App\Bsky\Embed; +use Atproto\Contracts\Stringable; use Atproto\Exceptions\InvalidArgumentException; use JsonSerializable; -class Caption implements JsonSerializable +class Caption implements JsonSerializable, Stringable { private const MAX_SIZE = 20000; @@ -21,7 +22,7 @@ public function __construct(string $lang, File $file) $this->file($file); } - public function lang(string $lang = null): string + public function lang(string $lang = null) { if (is_null($lang)) { return $this->lang; @@ -29,7 +30,7 @@ public function lang(string $lang = null): string $this->lang = $lang; - return $this->lang; + return $this; } /** @@ -42,11 +43,11 @@ public function file(File $file = null) } if ($file->size() > self::MAX_SIZE) { - throw new InvalidArgumentException($file->path().' is too large.'); + throw new InvalidArgumentException($file->path().' is too large. Max size: '.self::MAX_SIZE); } if ($file->type() !== 'text/vtt') { - throw new InvalidArgumentException($file->path().' is not a text vtt.'); + throw new InvalidArgumentException($file->path().' is not a text/vtt file.'); } $this->file = $file; @@ -64,4 +65,9 @@ public function jsonSerialize(): array 'file' => $this->file()->blob(), ]; } + + public function __toString(): string + { + return json_encode($this); + } } diff --git a/src/Lexicons/App/Bsky/Embed/File.php b/src/Lexicons/App/Bsky/Embed/File.php index 61d1b93..6c4baf0 100644 --- a/src/Lexicons/App/Bsky/Embed/File.php +++ b/src/Lexicons/App/Bsky/Embed/File.php @@ -4,7 +4,7 @@ use Atproto\Contracts\Stringable; -class File +class File implements Stringable { use BlobHandler; diff --git a/src/Lexicons/App/Bsky/Embed/Image.php b/src/Lexicons/App/Bsky/Embed/Image.php index 7036263..80d9d95 100644 --- a/src/Lexicons/App/Bsky/Embed/Image.php +++ b/src/Lexicons/App/Bsky/Embed/Image.php @@ -45,7 +45,7 @@ public function aspectRatio(int $width = null, int $height = null) } if ($width < 1 || $height < 1) { - throw new InvalidArgumentException("Width and height must be at least 1"); + throw new InvalidArgumentException("'\$width' and '\$height' must be greater than 0"); } $this->aspectRatio = [ @@ -67,4 +67,9 @@ public function jsonSerialize(): array 'aspectRatio' => $this->aspectRatio() ?: null, ]); } + + public function __toString(): string + { + return json_encode($this); + } } diff --git a/src/Support/File.php b/src/Support/File.php index ebe0415..641b6d7 100644 --- a/src/Support/File.php +++ b/src/Support/File.php @@ -10,7 +10,7 @@ class File { /** @var string $file_path The path to the file. */ - private $file_path; + private string $file_path; /** * Constructor. diff --git a/tests/Lexicons/App/Bsky/Embed/CaptionTest.php b/tests/Lexicons/App/Bsky/Embed/CaptionTest.php new file mode 100644 index 0000000..54c83ac --- /dev/null +++ b/tests/Lexicons/App/Bsky/Embed/CaptionTest.php @@ -0,0 +1,110 @@ + 'lang']; + + /** + * @throws InvalidArgumentException + */ + protected function setUp(): void + { + $file = $this->createMockFile(); + + $this->dependencies['file'] = $file; + + $this->caption = $this->createCaption(); + } + + /** + * @return Caption + * @throws InvalidArgumentException + */ + private function createCaption(): Caption + { + return new Caption(...array_values($this->dependencies)); + } + + /** + * @throws InvalidArgumentException + */ + public function testFile() + { + $actual = $this->caption->file(); + $this->assertSame($this->dependencies['file'], $actual); + } + + /** + * @throws InvalidArgumentException + */ + public function testSetFile(): void + { + $expected = clone $this->dependencies['file']; + + $this->assertFalse(spl_object_hash($expected) === spl_object_hash($this->caption->file())); + + $this->caption->file($expected); + $actual = $this->caption->file(); + + $this->assertSame($expected, $actual); + } + + public function testLang() + { + $actual = $this->caption->lang(); + $expected = $this->dependencies['lang']; + + $this->assertSame($expected, $actual); + } + + public function testSetLang(): void + { + $expected = "language"; + $this->caption->lang($expected); + $actual = $this->caption->lang(); + + $this->assertSame($expected, $actual); + } + + public function testJsonSerialize() + { + $expected = [ + 'file' => $this->blob, + 'lang' => $this->dependencies['lang'], + ]; + + $actual = json_decode($this->caption, true); + + $this->assertFalse(is_bool($actual)); + $this->assertEquals($expected, $actual); + } + + public function test__constructThrowsInvalidArgumentWhenPassedInvalidFileType(): void + { + $this->type = 'image/png'; + + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage($this->dependencies['file']->path()." is not a text/vtt file."); + + $this->createCaption(); + } + + public function test__constructorThrowsExceptionWhePassedUnacceptableSizedFile(): void + { + $this->size = 20001; + + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage($this->dependencies['file']->path()." is too large. Max size: 20000"); + + $this->createCaption(); + } +} diff --git a/tests/Lexicons/App/Bsky/Embed/FileMocking.php b/tests/Lexicons/App/Bsky/Embed/FileMocking.php new file mode 100644 index 0000000..7a08d6f --- /dev/null +++ b/tests/Lexicons/App/Bsky/Embed/FileMocking.php @@ -0,0 +1,42 @@ +getMockBuilder(File::class) + ->disableOriginalConstructor() + ->getMock(); + + $file->expects($this->any()) + ->method('path') + ->will($this->returnCallback(fn() => $this->path)); + + $file->expects($this->any()) + ->method('type') + ->will($this->returnCallback(fn() => $this->type)); + + $file->expects($this->any()) + ->method('size') + ->will($this->returnCallback(fn() => $this->size)); + + $file->expects($this->any()) + ->method('blob') + ->will($this->returnCallback(fn() => $this->blob)); + + return $file; + } +} \ No newline at end of file diff --git a/tests/Lexicons/App/Bsky/Embed/FileTest.php b/tests/Lexicons/App/Bsky/Embed/FileTest.php new file mode 100644 index 0000000..c8960ba --- /dev/null +++ b/tests/Lexicons/App/Bsky/Embed/FileTest.php @@ -0,0 +1,98 @@ +testFilePath = tempnam(sys_get_temp_dir(), 'testfile'); + file_put_contents($this->testFilePath, 'This is a test file.'); + $this->fileInstance = new File($this->testFilePath); + + $this->unreadableFilePath = tempnam(sys_get_temp_dir(), 'unreadable'); + file_put_contents($this->unreadableFilePath, 'This is an unreadable file.'); + chmod($this->unreadableFilePath, 0000); + + $this->nonFilePath = sys_get_temp_dir() . '/nonFile' . uniqid(); + mkdir($this->nonFilePath, 0777, true); + } + + protected function tearDown(): void + { + parent::tearDown(); + + if (file_exists($this->testFilePath)) { + unlink($this->testFilePath); + } + + if (file_exists($this->unreadableFilePath)) { + chmod($this->unreadableFilePath, 0644); + unlink($this->unreadableFilePath); + } + + if (is_dir($this->nonFilePath)) { + rmdir($this->nonFilePath); + } + } + + public function testFileSize(): void + { + $expectedSize = filesize($this->testFilePath); + $this->assertEquals($expectedSize, $this->fileInstance->size()); + } + + public function testMimeType(): void + { + $expectedType = mime_content_type($this->testFilePath); + $this->assertEquals($expectedType, $this->fileInstance->type()); + } + + public function testFileBlob(): void + { + $expectedContent = file_get_contents($this->testFilePath); + $this->assertEquals($expectedContent, $this->fileInstance->blob()); + } + + public function testToStringMethod(): void + { + $expectedContent = file_get_contents($this->testFilePath); + $this->assertEquals($expectedContent, (string) $this->fileInstance); + } + + public function testConstructorThrowsExceptionWhenPassedUnreadableFilePath(): void + { + if (function_exists('posix_geteuid') && posix_geteuid() === 0) { + $this->markTestSkipped('Test skipped because it is running as root.'); + } + + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage("$this->unreadableFilePath is not readable."); + + $this->assertFalse(is_readable($this->unreadableFilePath), 'File should not be readable.'); + + new File($this->unreadableFilePath); + } + + public function testConstructorThrowsExceptionWhenPassedNonFilePath(): void + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage("$this->nonFilePath is not a file."); + + new File($this->nonFilePath); + } +} diff --git a/tests/Lexicons/App/Bsky/Embed/ImageTest.php b/tests/Lexicons/App/Bsky/Embed/ImageTest.php new file mode 100644 index 0000000..87be7d4 --- /dev/null +++ b/tests/Lexicons/App/Bsky/Embed/ImageTest.php @@ -0,0 +1,143 @@ + 'alt']; + + /** + * @return array + */ + public function randAspectRatio(): array + { + return ['width' => rand(1, 50), 'height' => rand(1, 50)]; + } + + /** + * @return Image + * @throws InvalidArgumentException + */ + public function createImage(): Image + { + return new Image(...array_values($this->dependencies)); + } + + /** + * @throws InvalidArgumentException + */ + protected function setUp(): void + { + $this->type = 'image/png'; + + $this->dependencies = array_merge([ + 'file' => $this->createMockFile() + ], $this->dependencies); + + $this->image = $this->createImage(); + } + + /** + * @throws ReflectionException + */ + public function test__construct() + { + $this->assertSame($this->dependencies['file'], $this->getPropertyValue('file', $this->image)); + $this->assertSame($this->dependencies['alt'], $this->image->alt()); + } + + /** + * @throws InvalidArgumentException + */ + public function testAspectRatio() + { + $this->assertNull($this->image->aspectRatio()); + + $expected = $this->randAspectRatio(); + + $this->image->aspectRatio(...array_values($expected)); + + $this->assertSame($expected, $this->image->aspectRatio()); + } + + /** @dataProvider aspectRatioInvalidArguments */ + public function testAspectRatioThrowsInvalidArgumentException(...$arguments): void + { + $this->expectException(InvalidArgumentException::class); + + $this->image->aspectRatio(...$arguments); + } + + /** + * @return array + */ + public function aspectRatioInvalidArguments(): array + { + return [ + [0, 12], + [null, 0], + [12, null], + [0, 0], + [0, 54], + [76, 0], + [1] + ]; + } + + public function testAlt() + { + $expected = $this->dependencies['alt']; + + $this->assertSame($expected, $this->image->alt()); + + $new = uniqid(); + $this->image->alt($new); + + $this->assertSame($new, $this->image->alt()); + } + + /** + * @throws InvalidArgumentException + */ + public function testJsonSerialize() + { + $expected = [ + 'alt' => $this->dependencies['alt'], + 'image' => $this->dependencies['file']->blob(), + ]; + + $image = $this->createImage(); + + $this->assertSame($expected, json_decode($image, true)); + + $aspectRatio = $this->randAspectRatio(); + + $expected['aspectRatio'] = $aspectRatio; + + $image->aspectRatio(...array_values($aspectRatio)); + + $this->assertSame($expected, json_decode($image, true)); + } + + /** + * @throws InvalidArgumentException + */ + public function testMethodChaining() + { + $result = $this->image + ->alt('new alt') + ->aspectRatio(16, 9); + + $this->assertSame($this->image, $result); + } +} From 7c50c29f4bc5708a6878e557aa066fd50e77dcb9 Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Thu, 10 Oct 2024 23:26:10 +0400 Subject: [PATCH 09/58] WIP: PostBuilder Implementation. Add video test and move tests to correct directory - Add new test for the Video class related to embeds - Update namespaces of lexicon unit test classes related to embeds to fix being under the wrong namespace --- src/Lexicons/App/Bsky/Embed/Video.php | 13 +- .../Lexicons/App/Bsky/Embed/CaptionTest.php | 2 +- .../Lexicons/App/Bsky/Embed/FileMocking.php | 2 +- .../Lexicons/App/Bsky/Embed/FileTest.php | 2 +- .../Lexicons/App/Bsky/Embed/ImageTest.php | 2 +- .../Lexicons/App/Bsky/Embed/VideoTest.php | 123 ++++++++++++++++++ 6 files changed, 138 insertions(+), 6 deletions(-) rename tests/{ => Unit}/Lexicons/App/Bsky/Embed/CaptionTest.php (98%) rename tests/{ => Unit}/Lexicons/App/Bsky/Embed/FileMocking.php (95%) rename tests/{ => Unit}/Lexicons/App/Bsky/Embed/FileTest.php (98%) rename tests/{ => Unit}/Lexicons/App/Bsky/Embed/ImageTest.php (98%) create mode 100644 tests/Unit/Lexicons/App/Bsky/Embed/VideoTest.php diff --git a/src/Lexicons/App/Bsky/Embed/Video.php b/src/Lexicons/App/Bsky/Embed/Video.php index f4de269..9d3b905 100644 --- a/src/Lexicons/App/Bsky/Embed/Video.php +++ b/src/Lexicons/App/Bsky/Embed/Video.php @@ -3,10 +3,11 @@ namespace Atproto\Lexicons\App\Bsky\Embed; use Atproto\Contracts\Lexicons\App\Bsky\Embed\VideoInterface; +use Atproto\Contracts\Stringable; use Atproto\Exceptions\InvalidArgumentException; use Atproto\Lexicons\App\Bsky\Embed\Collections\CaptionCollection; -class Video implements VideoInterface +class Video implements VideoInterface, Stringable { private File $file; private ?string $alt = null; @@ -32,12 +33,14 @@ public function __construct(File $file) */ public function jsonSerialize(): array { - return array_filter([ + $result = array_filter([ 'alt' => $this->alt() ?: null, 'video' => $this->file->blob(), 'aspectRatio' => $this->aspectRatio() ?: null, 'captions' => $this->captions()->toArray() ?: null, ]); + + return $result; } public function alt(string $alt = null) @@ -82,4 +85,10 @@ public function captions(CaptionCollection $captions = null) return $this; } + + public function __toString(): string + { + $result = json_encode($this); + return $result; + } } diff --git a/tests/Lexicons/App/Bsky/Embed/CaptionTest.php b/tests/Unit/Lexicons/App/Bsky/Embed/CaptionTest.php similarity index 98% rename from tests/Lexicons/App/Bsky/Embed/CaptionTest.php rename to tests/Unit/Lexicons/App/Bsky/Embed/CaptionTest.php index 54c83ac..303adf9 100644 --- a/tests/Lexicons/App/Bsky/Embed/CaptionTest.php +++ b/tests/Unit/Lexicons/App/Bsky/Embed/CaptionTest.php @@ -1,6 +1,6 @@ type = 'video/mp4'; + + $this->file = $this->createMockFile(); + $this->video = new Video($this->file); + } + + public function testAlt(): void + { + $this->assertSame(null, $this->video->alt()); + + $expected = 'alt text'; + $this->video->alt($expected); + + $this->assertSame($expected, $this->video->alt()); + } + + /** @dataProvider invalidAspectRatioProvider */ + public function testAspectRatioThrowsInvalidArgumentExceptionWhenPassedInvalidArguments(...$args): void + { + $this->expectException(InvalidArgumentException::class); + + $this->video->aspectRatio(...array_values($args)); + } + + public function invalidAspectRatioProvider(): array + { + return [ + [-1, 0], + [0, -1], + [false, 1], + [true], + [1] + ]; + } + + public function testAspectRatio(): void + { + $this->assertSame([], $this->video->aspectRatio()); + + $expected = ['width' => 1, 'height' => 2]; + $this->video->aspectRatio(...array_values($expected)); + + $this->assertSame($expected, $this->video->aspectRatio()); + } + + public function testJsonSerializeReturnsCorrectSchema(): void + { + $this->assertSame($this->file->blob(), $this->blob); + + $expected = [ + 'video' => $this->file->blob(), + ]; + + $target = new Video($this->file); + + $this->assertSame($expected, json_decode($target, true)); + + $captions = $this->createCaptionsMock(); + $aspectRatio = $this->randAspectRatio(); + + $expected = [ + 'alt' => 'alt text', + 'video' => $expected['video'], + 'aspectRatio' => $aspectRatio, + 'captions' => $captions->toArray(), + ]; + + $target->captions($captions) + ->alt($expected['alt']) + ->aspectRatio(...array_values($expected['aspectRatio'])); + + $this->assertSame($expected, json_decode($target, true)); + } + + /** + * @return array + */ + private function randAspectRatio(): array + { + return ['width' => rand(1, 50), 'height' => rand(1, 50)]; + } + + /** + * @return (MockObject&CaptionCollection) + */ + private function createCaptionsMock(): CaptionCollection + { + $captions = $this->getMockBuilder(CaptionCollection::class) + ->disableOriginalConstructor() + ->onlyMethods(['toArray']) + ->getMock(); + + $captions->expects($this->any()) + ->method('toArray') + ->willReturn([ + ['lang' => 'lang', 'file' => $this->blob] + ]); + + return $captions; + } +} From 35e9abff4b9d12e3297b771e9ae8683d60a8175c Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Fri, 11 Oct 2024 00:07:52 +0400 Subject: [PATCH 10/58] Implement CaptionInterface for proper JSON serialization - Add CaptionInterface extending JsonSerializable and Stringable - Update Caption class to implement CaptionInterface - Modify CaptionCollection to use CaptionInterface - Adjust VideoTest to work with new interface structure Why: This change ensures proper serialization of Caption objects when json_encode is applied. By extending JsonSerializable and Stringable interfaces, CaptionInterface guarantees that Caption objects are converted to arrays during JSON serialization. --- .../App/Bsky/Embed/CaptionInterface.php | 13 +++++++++++++ src/Lexicons/App/Bsky/Embed/Caption.php | 4 ++-- .../Embed/Collections/CaptionCollection.php | 4 ++-- .../Unit/Lexicons/App/Bsky/Embed/VideoTest.php | 17 ++++++++++++++--- 4 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 src/Contracts/Lexicons/App/Bsky/Embed/CaptionInterface.php diff --git a/src/Contracts/Lexicons/App/Bsky/Embed/CaptionInterface.php b/src/Contracts/Lexicons/App/Bsky/Embed/CaptionInterface.php new file mode 100644 index 0000000..fcd6144 --- /dev/null +++ b/src/Contracts/Lexicons/App/Bsky/Embed/CaptionInterface.php @@ -0,0 +1,13 @@ + $item instanceof Caption, $collection); + parent::__construct(fn ($item) => $item instanceof CaptionInterface, $collection); } public function validate($value): bool diff --git a/tests/Unit/Lexicons/App/Bsky/Embed/VideoTest.php b/tests/Unit/Lexicons/App/Bsky/Embed/VideoTest.php index 528f032..94a0306 100644 --- a/tests/Unit/Lexicons/App/Bsky/Embed/VideoTest.php +++ b/tests/Unit/Lexicons/App/Bsky/Embed/VideoTest.php @@ -2,7 +2,9 @@ namespace Tests\Unit\Lexicons\App\Bsky\Embed; +use Atproto\Contracts\Lexicons\App\Bsky\Embed\CaptionInterface; use Atproto\Exceptions\InvalidArgumentException; +use Atproto\Lexicons\App\Bsky\Embed\Caption; use Atproto\Lexicons\App\Bsky\Embed\Collections\CaptionCollection; use Atproto\Lexicons\App\Bsky\Embed\File; use Atproto\Lexicons\App\Bsky\Embed\Video; @@ -107,6 +109,17 @@ private function randAspectRatio(): array */ private function createCaptionsMock(): CaptionCollection { + $caption = $this->getMockBuilder(CaptionInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $caption->expects($this->any()) + ->method('jsonSerialize') + ->willReturn([ + 'lang' => 'lang', + 'file' => $this->file->blob(), + ]); + $captions = $this->getMockBuilder(CaptionCollection::class) ->disableOriginalConstructor() ->onlyMethods(['toArray']) @@ -114,9 +127,7 @@ private function createCaptionsMock(): CaptionCollection $captions->expects($this->any()) ->method('toArray') - ->willReturn([ - ['lang' => 'lang', 'file' => $this->blob] - ]); + ->willReturn($caption->jsonSerialize()); return $captions; } From 641b63251694ebb04d79656109eaa5e7a74d3600 Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sat, 12 Oct 2024 02:28:16 +0400 Subject: [PATCH 11/58] Add size() method to Image class and interface --- src/Contracts/Lexicons/App/Bsky/Embed/ImageInterface.php | 1 + src/Lexicons/App/Bsky/Embed/Image.php | 5 +++++ tests/Unit/Lexicons/App/Bsky/Embed/ImageTest.php | 5 +++++ 3 files changed, 11 insertions(+) diff --git a/src/Contracts/Lexicons/App/Bsky/Embed/ImageInterface.php b/src/Contracts/Lexicons/App/Bsky/Embed/ImageInterface.php index 73d0a22..2935cfc 100644 --- a/src/Contracts/Lexicons/App/Bsky/Embed/ImageInterface.php +++ b/src/Contracts/Lexicons/App/Bsky/Embed/ImageInterface.php @@ -10,4 +10,5 @@ interface ImageInterface extends JsonSerializable, Stringable public function jsonSerialize(): array; public function alt(string $alt = null); public function aspectRatio(); + public function size(): int; } diff --git a/src/Lexicons/App/Bsky/Embed/Image.php b/src/Lexicons/App/Bsky/Embed/Image.php index 80d9d95..0846f1d 100644 --- a/src/Lexicons/App/Bsky/Embed/Image.php +++ b/src/Lexicons/App/Bsky/Embed/Image.php @@ -68,6 +68,11 @@ public function jsonSerialize(): array ]); } + public function size(): int + { + return $this->file->size(); + } + public function __toString(): string { return json_encode($this); diff --git a/tests/Unit/Lexicons/App/Bsky/Embed/ImageTest.php b/tests/Unit/Lexicons/App/Bsky/Embed/ImageTest.php index 2b8e9a5..6f2a78c 100644 --- a/tests/Unit/Lexicons/App/Bsky/Embed/ImageTest.php +++ b/tests/Unit/Lexicons/App/Bsky/Embed/ImageTest.php @@ -140,4 +140,9 @@ public function testMethodChaining() $this->assertSame($this->image, $result); } + + public function testSize(): void + { + $this->assertSame($this->size, $this->image->size()); + } } From 14076f65504b66d2db0e4143c878976ab23fb626 Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sat, 12 Oct 2024 02:31:27 +0400 Subject: [PATCH 12/58] Refactor collections by introducing `EmbedCollection` trait for code reuse. - Updated `CaptionCollection` and `ImageCollection` to use `EmbedCollection` for handling validation logic and ensuring consistent error handling. - Simplified the validation process by using closures in the `validator` method to ensure objects implement their respective interfaces. - Introduced custom exception handling for type errors to provide more meaningful feedback. - Ensured that collections adhere to size limits, with clear error messages for exceeding maximum size or incorrect object types. --- .../Embed/Collections/CaptionCollection.php | 35 +++------ .../Embed/Collections/EmbedCollection.php | 45 +++++++++++ .../Embed/Collections/ImageCollection.php | 52 ++++--------- .../Collections/CaptionCollectionTest.php | 16 ++++ .../Embed/Collections/EmbedCollectionTest.php | 78 +++++++++++++++++++ .../Embed/Collections/ImageCollectionTest.php | 17 ++++ 6 files changed, 178 insertions(+), 65 deletions(-) create mode 100644 src/Lexicons/App/Bsky/Embed/Collections/EmbedCollection.php create mode 100644 tests/Unit/Lexicons/App/Bsky/Embed/Collections/CaptionCollectionTest.php create mode 100644 tests/Unit/Lexicons/App/Bsky/Embed/Collections/EmbedCollectionTest.php create mode 100644 tests/Unit/Lexicons/App/Bsky/Embed/Collections/ImageCollectionTest.php diff --git a/src/Lexicons/App/Bsky/Embed/Collections/CaptionCollection.php b/src/Lexicons/App/Bsky/Embed/Collections/CaptionCollection.php index e8b5f34..6c22ad9 100644 --- a/src/Lexicons/App/Bsky/Embed/Collections/CaptionCollection.php +++ b/src/Lexicons/App/Bsky/Embed/Collections/CaptionCollection.php @@ -3,40 +3,23 @@ namespace Atproto\Lexicons\App\Bsky\Embed\Collections; use Atproto\Contracts\Lexicons\App\Bsky\Embed\CaptionInterface; -use GenericCollection\Exceptions\InvalidArgumentException; +use Atproto\Exceptions\InvalidArgumentException; use GenericCollection\GenericCollection; use JsonSerializable; class CaptionCollection extends GenericCollection implements JsonSerializable { + use EmbedCollection; private const MAX_SIZE = 20; - public function __construct(iterable $collection = []) + protected function validator(): \Closure { - parent::__construct(fn ($item) => $item instanceof CaptionInterface, $collection); - } - - public function validate($value): bool - { - return parent::validate($value) && $this->validateLength(); - } - - private function validateLength(): bool - { - return $this->count() <= self::MAX_SIZE; - } - - public function validateWithException($value): void - { - parent::validateWithException($value); + return function (CaptionInterface $caption) { + if ($this->count() > self::MAX_SIZE) { + throw new InvalidArgumentException(self::class.' collection exceeds maximum size: ' .self::MAX_SIZE); + } - if (! $this->validateLength()) { - throw new InvalidArgumentException("Caption length must be less than or equal " . self::MAX_SIZE); - } - } - - public function jsonSerialize() - { - return $this->toArray(); + return true; + }; } } diff --git a/src/Lexicons/App/Bsky/Embed/Collections/EmbedCollection.php b/src/Lexicons/App/Bsky/Embed/Collections/EmbedCollection.php new file mode 100644 index 0000000..8eb17d7 --- /dev/null +++ b/src/Lexicons/App/Bsky/Embed/Collections/EmbedCollection.php @@ -0,0 +1,45 @@ +collection = $collection; + + try { + parent::__construct($this->validator(), $collection); + } catch (\TypeError|\GenericCollection\Exceptions\InvalidArgumentException $e) { + $this->throw($e); + } + } + + /** + * @throws InvalidArgumentException + */ + private function throw($exception): void + { + throw new InvalidArgumentException( + str_replace( + "::".__NAMESPACE__."\{closure}()", + "", + $exception->getMessage() + ), + 0, + $exception + ); + } + + abstract protected function validator(): \Closure; + + public function jsonSerialize(): array + { + return $this->toArray(); + } +} diff --git a/src/Lexicons/App/Bsky/Embed/Collections/ImageCollection.php b/src/Lexicons/App/Bsky/Embed/Collections/ImageCollection.php index 6f3b3aa..9996bc6 100644 --- a/src/Lexicons/App/Bsky/Embed/Collections/ImageCollection.php +++ b/src/Lexicons/App/Bsky/Embed/Collections/ImageCollection.php @@ -9,49 +9,23 @@ class ImageCollection extends GenericCollection implements JsonSerializable { - private const MAX_ITEM = 4; - private const MAX_SIZE = 1000000; - - public function __construct(iterable $collection = []) - { - parent::__construct(fn ($item) => $item instanceof ImageInterface, $collection); - } - - private function validateLength(): bool - { - return ($this->count() <= self::MAX_ITEM); - } - - private function validateSize(ImageInterface $image): bool - { - return $image->size() <= self::MAX_SIZE; - } + use EmbedCollection; - public function validate($value): bool - { - return parent::validate($value) - && $this->validateSize($value) - && $this->validateLength(); - } + private const MAX_LENGTH = 4; + private const MAX_SIZE = 1000000; - /** - * @throws InvalidArgumentException - */ - public function validateWithException($value): void + protected function validator(): \Closure { - parent::validateWithException($value); - - if (! $this->validateLength()) { - throw new InvalidArgumentException("Image limit exceeded. Maximum allowed images: ".self::MAX_ITEM); - } + return function (ImageInterface $image) { + if ($this->count() > self::MAX_LENGTH) { + throw new InvalidArgumentException(self::class.' collection exceeds maximum size: ' .self::MAX_LENGTH); + } - if (! $this->validateSize($value)) { - throw new InvalidArgumentException("Image size exceeded. Maximum allowed size: ".self::MAX_SIZE); - } - } + if ($image->size() > self::MAX_SIZE) { + throw new InvalidArgumentException(self::class.' collection only accepts images with size less than '. self::MAX_LENGTH); + } - public function jsonSerialize(): array - { - return $this->toArray(); + return true; + }; } } diff --git a/tests/Unit/Lexicons/App/Bsky/Embed/Collections/CaptionCollectionTest.php b/tests/Unit/Lexicons/App/Bsky/Embed/Collections/CaptionCollectionTest.php new file mode 100644 index 0000000..fbd248f --- /dev/null +++ b/tests/Unit/Lexicons/App/Bsky/Embed/Collections/CaptionCollectionTest.php @@ -0,0 +1,16 @@ +getMockBuilder($this->dependency) + ->disableOriginalConstructor() + ->getMock(); + + $item->expects($this->any()) + ->method('jsonSerialize') + ->willReturn(['foo' => 'bar']); + + $items[] = $item; + } + + return $items; + } + + /** + * @throws InvalidArgumentException + */ + public function test__constructThatFillsCorrectlyCollection(): void + { + $expected = $this->items(); + $collection = new $this->target($expected); + + $this->assertSame($expected, $collection->toArray()); + } + + /** + * @throws InvalidArgumentException + */ + public function testValidateThrowsExceptionWhenPassedInvalidArgument(): void + { + $given = $this->createMock(Video::class); + + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage(sprintf( + "must implement interface %s, instance of %s given", + $this->dependency, + get_class($given) + )); + + new $this->target([$given]); + } + + public function testValidateThrowsExceptionWhenLimitExceed(): void + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage("collection exceeds maximum size"); + + new $this->target($this->items(++$this->maxLength)); + } + + /** + * @throws InvalidArgumentException + */ + public function testJsonSerialize() + { + $items = new $this->target($this->items(2)); + + $expected = json_encode(array_map(fn () => ['foo' => 'bar'], $items->toArray())); + $actual = json_encode($items); + + $this->assertSame($expected, $actual); + } +} diff --git a/tests/Unit/Lexicons/App/Bsky/Embed/Collections/ImageCollectionTest.php b/tests/Unit/Lexicons/App/Bsky/Embed/Collections/ImageCollectionTest.php new file mode 100644 index 0000000..efb6411 --- /dev/null +++ b/tests/Unit/Lexicons/App/Bsky/Embed/Collections/ImageCollectionTest.php @@ -0,0 +1,17 @@ + Date: Sat, 12 Oct 2024 02:39:10 +0400 Subject: [PATCH 13/58] Fix typo in exception message for class and add unit test for size validation. --- .../Bsky/Embed/Collections/ImageCollection.php | 2 +- .../Embed/Collections/ImageCollectionTest.php | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Lexicons/App/Bsky/Embed/Collections/ImageCollection.php b/src/Lexicons/App/Bsky/Embed/Collections/ImageCollection.php index 9996bc6..5ddea2f 100644 --- a/src/Lexicons/App/Bsky/Embed/Collections/ImageCollection.php +++ b/src/Lexicons/App/Bsky/Embed/Collections/ImageCollection.php @@ -22,7 +22,7 @@ protected function validator(): \Closure } if ($image->size() > self::MAX_SIZE) { - throw new InvalidArgumentException(self::class.' collection only accepts images with size less than '. self::MAX_LENGTH); + throw new InvalidArgumentException(self::class.' collection only accepts images with size less than '. self::MAX_SIZE); } return true; diff --git a/tests/Unit/Lexicons/App/Bsky/Embed/Collections/ImageCollectionTest.php b/tests/Unit/Lexicons/App/Bsky/Embed/Collections/ImageCollectionTest.php index efb6411..548e198 100644 --- a/tests/Unit/Lexicons/App/Bsky/Embed/Collections/ImageCollectionTest.php +++ b/tests/Unit/Lexicons/App/Bsky/Embed/Collections/ImageCollectionTest.php @@ -3,6 +3,7 @@ namespace Tests\Unit\Lexicons\App\Bsky\Embed\Collections; use Atproto\Contracts\Lexicons\App\Bsky\Embed\ImageInterface; +use Atproto\Exceptions\InvalidArgumentException; use Atproto\Lexicons\App\Bsky\Embed\Collections\ImageCollection; use PHPUnit\Framework\TestCase; @@ -14,4 +15,20 @@ class ImageCollectionTest extends TestCase private string $dependency = ImageInterface::class; private int $maxLength = 4; private int $maxSizeOfItem = 1000000; + + public function testValidateThrowsExceptionWherePassedThatSizeGreaterThanLimit(): void + { + $dependency = $this->getMockBuilder($this->dependency) + ->disableOriginalConstructor() + ->getMock(); + + $dependency->expects($this->once()) + ->method('size') + ->willReturn(++$this->maxSizeOfItem); + + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage("collection only accepts images with size less than"); + + new ImageCollection([$dependency]); + } } From af507a8dc52cbe42315f803d7bcf1beb5cd31af8 Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sat, 12 Oct 2024 20:59:49 +0400 Subject: [PATCH 14/58] Add External embed class and corresponding test file - Create src/Lexicons/App/Bsky/Embed/External.php for External embed implementation - Add tests/Unit/Lexicons/App/Bsky/Embed/ExternalTest.php for unit tests On branch embeds Changes to be committed: renamed: src/Lexicons/App/Bsky/Embed/File.php -> src/Lexicons/App/Bsky/Embed/Blob.php --- .../App/Bsky/Embed/CaptionInterface.php | 4 +- .../App/Bsky/Embed/{File.php => Blob.php} | 2 +- src/Lexicons/App/Bsky/Embed/Caption.php | 6 +- src/Lexicons/App/Bsky/Embed/External.php | 90 +++++++++++++++ src/Lexicons/App/Bsky/Embed/Image.php | 4 +- src/Lexicons/App/Bsky/Embed/Video.php | 4 +- .../Lexicons/App/Bsky/Embed/ExternalTest.php | 104 ++++++++++++++++++ .../Lexicons/App/Bsky/Embed/FileMocking.php | 6 +- .../Unit/Lexicons/App/Bsky/Embed/FileTest.php | 10 +- .../Lexicons/App/Bsky/Embed/VideoTest.php | 4 +- 10 files changed, 214 insertions(+), 20 deletions(-) rename src/Lexicons/App/Bsky/Embed/{File.php => Blob.php} (94%) create mode 100644 src/Lexicons/App/Bsky/Embed/External.php create mode 100644 tests/Unit/Lexicons/App/Bsky/Embed/ExternalTest.php diff --git a/src/Contracts/Lexicons/App/Bsky/Embed/CaptionInterface.php b/src/Contracts/Lexicons/App/Bsky/Embed/CaptionInterface.php index fcd6144..ed45198 100644 --- a/src/Contracts/Lexicons/App/Bsky/Embed/CaptionInterface.php +++ b/src/Contracts/Lexicons/App/Bsky/Embed/CaptionInterface.php @@ -3,11 +3,11 @@ namespace Atproto\Contracts\Lexicons\App\Bsky\Embed; use Atproto\Contracts\Stringable; -use Atproto\Lexicons\App\Bsky\Embed\File; +use Atproto\Lexicons\App\Bsky\Embed\Blob; use JsonSerializable; interface CaptionInterface extends JsonSerializable, Stringable { public function lang(string $lang = null); - public function file(File $file = null); + public function file(Blob $file = null); } diff --git a/src/Lexicons/App/Bsky/Embed/File.php b/src/Lexicons/App/Bsky/Embed/Blob.php similarity index 94% rename from src/Lexicons/App/Bsky/Embed/File.php rename to src/Lexicons/App/Bsky/Embed/Blob.php index 6c4baf0..d6c4421 100644 --- a/src/Lexicons/App/Bsky/Embed/File.php +++ b/src/Lexicons/App/Bsky/Embed/Blob.php @@ -4,7 +4,7 @@ use Atproto\Contracts\Stringable; -class File implements Stringable +class Blob implements Stringable { use BlobHandler; diff --git a/src/Lexicons/App/Bsky/Embed/Caption.php b/src/Lexicons/App/Bsky/Embed/Caption.php index c7c548b..816ab91 100644 --- a/src/Lexicons/App/Bsky/Embed/Caption.php +++ b/src/Lexicons/App/Bsky/Embed/Caption.php @@ -11,12 +11,12 @@ class Caption implements CaptionInterface private const MAX_SIZE = 20000; private string $lang; - private File $file; + private Blob $file; /** * @throws InvalidArgumentException */ - public function __construct(string $lang, File $file) + public function __construct(string $lang, Blob $file) { $this->lang($lang); $this->file($file); @@ -36,7 +36,7 @@ public function lang(string $lang = null) /** * @throws InvalidArgumentException */ - public function file(File $file = null) + public function file(Blob $file = null) { if (is_null($file)) { return $this->file; diff --git a/src/Lexicons/App/Bsky/Embed/External.php b/src/Lexicons/App/Bsky/Embed/External.php new file mode 100644 index 0000000..20e37be --- /dev/null +++ b/src/Lexicons/App/Bsky/Embed/External.php @@ -0,0 +1,90 @@ +uri($uri) + ->title($title) + ->description($description); + } + + /** + * @throws InvalidArgumentException + */ + public function uri(string $uri = null) + { + if (is_null($uri)) { + return $this->uri; + } + + if (! filter_var($uri, FILTER_VALIDATE_URL)) { + throw new InvalidArgumentException("'$uri' is not a valid URL"); + } + + $this->uri = $uri; + + return $this; + } + + public function title(string $title = null) + { + if (is_null($title)) { + return $this->title; + } + + $this->title = $title; + + return $this; + } + + public function description(string $description = null) + { + if (is_null($description)) { + return $this->description; + } + + $this->description = $description; + + return $this; + } + + /** + * @throws InvalidArgumentException + */ + public function thumb(Blob $blob = null) + { + if (is_null($blob)) { + return $this->blob; + } + + if (! str_starts_with($blob->type(), 'image/*')) { + throw new InvalidArgumentException(sprintf( + "'%s' is not a valid image type: %s", + $blob->path(), + $blob->type() + )); + } + + if (1000000 < $blob->size()) { + throw new InvalidArgumentException(sprintf( + "'%s' size is too big than maximum allowed: %d", + $blob->path(), + $blob->size() + )); + } + + $this->blob = $blob; + + return $this; + } +} diff --git a/src/Lexicons/App/Bsky/Embed/Image.php b/src/Lexicons/App/Bsky/Embed/Image.php index 0846f1d..894ba2c 100644 --- a/src/Lexicons/App/Bsky/Embed/Image.php +++ b/src/Lexicons/App/Bsky/Embed/Image.php @@ -7,14 +7,14 @@ class Image implements ImageInterface { - private File $file; + private Blob $file; private string $alt; private ?array $aspectRatio = null; /** * @throws InvalidArgumentException */ - public function __construct(File $file, string $alt) + public function __construct(Blob $file, string $alt) { if (true !== str_starts_with($file->type(), 'image/')) { throw new InvalidArgumentException($file->path()." is not a valid image file."); diff --git a/src/Lexicons/App/Bsky/Embed/Video.php b/src/Lexicons/App/Bsky/Embed/Video.php index 9d3b905..10cff40 100644 --- a/src/Lexicons/App/Bsky/Embed/Video.php +++ b/src/Lexicons/App/Bsky/Embed/Video.php @@ -9,7 +9,7 @@ class Video implements VideoInterface, Stringable { - private File $file; + private Blob $file; private ?string $alt = null; private CaptionCollection $captions; private array $aspectRatio = []; @@ -17,7 +17,7 @@ class Video implements VideoInterface, Stringable /** * @throws InvalidArgumentException */ - public function __construct(File $file) + public function __construct(Blob $file) { if ("video/mp4" !== $file->type()) { throw new InvalidArgumentException($file->path()." is not a valid video file."); diff --git a/tests/Unit/Lexicons/App/Bsky/Embed/ExternalTest.php b/tests/Unit/Lexicons/App/Bsky/Embed/ExternalTest.php new file mode 100644 index 0000000..f7e8877 --- /dev/null +++ b/tests/Unit/Lexicons/App/Bsky/Embed/ExternalTest.php @@ -0,0 +1,104 @@ +external = new External('https://shahmal1yev.dev', 'foo', 'bar'); + $this->blob = $this->getMockBuilder(Blob::class) + ->disableOriginalConstructor() + ->getMock(); + + $this->blob->expects($this->any()) + ->method('size') + ->will($this->returnCallback(fn () => $this->maximumAllowedBlobSize)); + + $this->blob->expects($this->any()) + ->method('type') + ->will($this->returnCallback(fn () => $this->allowedMimes)); + } + + public function testDescription() + { + $this->assertSame('bar', $this->external->description()); + $this->external->description('foo'); + $this->assertSame('foo', $this->external->description()); + } + + /** + * @throws InvalidArgumentException + */ + public function testThumb() + { + $this->external->thumb($this->blob); + $this->assertSame($this->blob, $this->external->thumb()); + } + + /** + * @throws InvalidArgumentException + */ + public function testThumbReturnsNull(): void + { + $this->assertNull($this->external->thumb()); + } + + public function testThumbThrowsExceptionWhenPassedBlobWithInvalidMimeType(): void + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('is not a valid image type: invalid/*'); + + $this->allowedMimes = 'invalid/*'; + + $this->external->thumb($this->blob); + } + + public function testThumbThrowsExceptionWhenPassedBlobExceedsMaximumAllowedSize(): void + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('size is too big than maximum allowed:'); + + $this->maximumAllowedBlobSize = ++$this->maximumAllowedBlobSize; + + $this->external->thumb($this->blob); + } + + /** + * @throws InvalidArgumentException + */ + public function testUri() + { + $this->assertSame('https://shahmal1yev.dev', $this->external->uri()); + $this->external->uri('https://google.com'); + $this->assertSame('https://google.com', $this->external->uri()); + } + + public function testUriThrowsExceptionWhenPassedInvalidUrl(): void + { + $trigger = 'invalid url'; + + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage("'$trigger' is not a valid URL"); + + $this->external->uri($trigger); + } + + public function testTitle() + { + $this->assertSame('foo', $this->external->title()); + $this->external->title('bar'); + $this->assertSame('bar', $this->external->title()); + } +} diff --git a/tests/Unit/Lexicons/App/Bsky/Embed/FileMocking.php b/tests/Unit/Lexicons/App/Bsky/Embed/FileMocking.php index bb5f3ab..9e43b22 100644 --- a/tests/Unit/Lexicons/App/Bsky/Embed/FileMocking.php +++ b/tests/Unit/Lexicons/App/Bsky/Embed/FileMocking.php @@ -2,7 +2,7 @@ namespace Tests\Unit\Lexicons\App\Bsky\Embed; -use Atproto\Lexicons\App\Bsky\Embed\File; +use Atproto\Lexicons\App\Bsky\Embed\Blob; use PHPUnit\Framework\MockObject\MockObject; trait FileMocking @@ -13,11 +13,11 @@ trait FileMocking private string $type = 'text/vtt'; /** - * @return (File&MockObject) + * @return (Blob&MockObject) */ private function createMockFile() { - $file = $this->getMockBuilder(File::class) + $file = $this->getMockBuilder(Blob::class) ->disableOriginalConstructor() ->getMock(); diff --git a/tests/Unit/Lexicons/App/Bsky/Embed/FileTest.php b/tests/Unit/Lexicons/App/Bsky/Embed/FileTest.php index 454762d..b95b503 100644 --- a/tests/Unit/Lexicons/App/Bsky/Embed/FileTest.php +++ b/tests/Unit/Lexicons/App/Bsky/Embed/FileTest.php @@ -3,7 +3,7 @@ namespace Tests\Unit\Lexicons\App\Bsky\Embed; use Atproto\Exceptions\InvalidArgumentException; -use Atproto\Lexicons\App\Bsky\Embed\File; +use Atproto\Lexicons\App\Bsky\Embed\Blob; use PHPUnit\Framework\TestCase; class FileTest extends TestCase @@ -11,7 +11,7 @@ class FileTest extends TestCase private string $testFilePath; private string $unreadableFilePath; private string $nonFilePath; - private File $fileInstance; + private Blob $fileInstance; /** * @throws InvalidArgumentException @@ -22,7 +22,7 @@ protected function setUp(): void $this->testFilePath = tempnam(sys_get_temp_dir(), 'testfile'); file_put_contents($this->testFilePath, 'This is a test file.'); - $this->fileInstance = new File($this->testFilePath); + $this->fileInstance = new Blob($this->testFilePath); $this->unreadableFilePath = tempnam(sys_get_temp_dir(), 'unreadable'); file_put_contents($this->unreadableFilePath, 'This is an unreadable file.'); @@ -85,7 +85,7 @@ public function testConstructorThrowsExceptionWhenPassedUnreadableFilePath(): vo $this->assertFalse(is_readable($this->unreadableFilePath), 'File should not be readable.'); - new File($this->unreadableFilePath); + new Blob($this->unreadableFilePath); } public function testConstructorThrowsExceptionWhenPassedNonFilePath(): void @@ -93,6 +93,6 @@ public function testConstructorThrowsExceptionWhenPassedNonFilePath(): void $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage("$this->nonFilePath is not a file."); - new File($this->nonFilePath); + new Blob($this->nonFilePath); } } diff --git a/tests/Unit/Lexicons/App/Bsky/Embed/VideoTest.php b/tests/Unit/Lexicons/App/Bsky/Embed/VideoTest.php index 94a0306..e69051c 100644 --- a/tests/Unit/Lexicons/App/Bsky/Embed/VideoTest.php +++ b/tests/Unit/Lexicons/App/Bsky/Embed/VideoTest.php @@ -6,7 +6,7 @@ use Atproto\Exceptions\InvalidArgumentException; use Atproto\Lexicons\App\Bsky\Embed\Caption; use Atproto\Lexicons\App\Bsky\Embed\Collections\CaptionCollection; -use Atproto\Lexicons\App\Bsky\Embed\File; +use Atproto\Lexicons\App\Bsky\Embed\Blob; use Atproto\Lexicons\App\Bsky\Embed\Video; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -16,7 +16,7 @@ class VideoTest extends TestCase use FileMocking; private Video $video; - private File $file; + private Blob $file; protected function setUp(): void { From 871a9670d4af70cd8f3307e6d7dc4608e815a510 Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sat, 12 Oct 2024 21:16:16 +0400 Subject: [PATCH 15/58] Implement JsonSerializable and Stringable for External class --- src/Lexicons/App/Bsky/Embed/External.php | 19 ++++++++++- .../Lexicons/App/Bsky/Embed/ExternalTest.php | 33 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/Lexicons/App/Bsky/Embed/External.php b/src/Lexicons/App/Bsky/Embed/External.php index 20e37be..6d9363c 100644 --- a/src/Lexicons/App/Bsky/Embed/External.php +++ b/src/Lexicons/App/Bsky/Embed/External.php @@ -2,9 +2,11 @@ namespace Atproto\Lexicons\App\Bsky\Embed; +use Atproto\Contracts\Stringable; use Atproto\Exceptions\InvalidArgumentException; +use JsonSerializable; -class External +class External implements JsonSerializable, Stringable { private string $uri; private string $title; @@ -87,4 +89,19 @@ public function thumb(Blob $blob = null) return $this; } + + public function jsonSerialize(): array + { + return array_filter([ + 'uri' => $this->uri, + 'title' => $this->title, + 'description' => $this->description, + 'blob' => ($b = $this->blob) ? $b->blob() : null, + ]); + } + + public function __toString(): string + { + return json_encode($this); + } } diff --git a/tests/Unit/Lexicons/App/Bsky/Embed/ExternalTest.php b/tests/Unit/Lexicons/App/Bsky/Embed/ExternalTest.php index f7e8877..0939e22 100644 --- a/tests/Unit/Lexicons/App/Bsky/Embed/ExternalTest.php +++ b/tests/Unit/Lexicons/App/Bsky/Embed/ExternalTest.php @@ -18,6 +18,7 @@ class ExternalTest extends TestCase public function setUp(): void { $this->external = new External('https://shahmal1yev.dev', 'foo', 'bar'); + $this->blob = $this->getMockBuilder(Blob::class) ->disableOriginalConstructor() ->getMock(); @@ -29,6 +30,10 @@ public function setUp(): void $this->blob->expects($this->any()) ->method('type') ->will($this->returnCallback(fn () => $this->allowedMimes)); + + $this->blob->expects($this->any()) + ->method('blob') + ->willReturn('blob'); } public function testDescription() @@ -101,4 +106,32 @@ public function testTitle() $this->external->title('bar'); $this->assertSame('bar', $this->external->title()); } + + public function testJsonSerializeWithoutSetBlob(): void + { + $expected = [ + 'uri' => 'https://shahmal1yev.dev', + 'title' => 'foo', + 'description' => 'bar', + ]; + + $this->assertSame($expected, json_decode($this->external, true)); + } + + /** + * @throws InvalidArgumentException + */ + public function testJsonSerializeWithSetBlob(): void + { + $this->external->thumb($this->blob); + + $expected = [ + 'uri' => 'https://shahmal1yev.dev', + 'title' => 'foo', + 'description' => 'bar', + 'blob' => 'blob', + ]; + + $this->assertSame($expected, json_decode($this->external, true)); + } } From 8d4ecc5b983c8c81a4c8ddfe41d18a42d526bdfd Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sat, 12 Oct 2024 21:31:18 +0400 Subject: [PATCH 16/58] Implement Record: Add Record and StrongRef classes with tests - Add StrongRef class for com.atproto.repo.strongRef - Implement JsonSerializable and Stringable interfaces for both classes - Add unit tests for Record and StrongRef classes - Include getter/setter methods and JSON serialization --- src/Lexicons/App/Bsky/Embed/Record.php | 29 ++++++++++ src/Lexicons/Com/Atproto/Repo/StrongRef.php | 53 +++++++++++++++++++ .../Com/Atproto/Repo/StrongRefTest.php | 39 ++++++++++++++ .../Lexicons/App/Bsky/Embed/RecordTest.php | 36 +++++++++++++ 4 files changed, 157 insertions(+) create mode 100644 src/Lexicons/App/Bsky/Embed/Record.php create mode 100644 src/Lexicons/Com/Atproto/Repo/StrongRef.php create mode 100644 tests/Lexicons/Com/Atproto/Repo/StrongRefTest.php create mode 100644 tests/Unit/Lexicons/App/Bsky/Embed/RecordTest.php diff --git a/src/Lexicons/App/Bsky/Embed/Record.php b/src/Lexicons/App/Bsky/Embed/Record.php new file mode 100644 index 0000000..dd873bb --- /dev/null +++ b/src/Lexicons/App/Bsky/Embed/Record.php @@ -0,0 +1,29 @@ +ref = $ref; + } + + public function __toString(): string + { + return json_encode($this); + } + + public function jsonSerialize(): array + { + return [ + 'record' => $this->ref, + ]; + } +} diff --git a/src/Lexicons/Com/Atproto/Repo/StrongRef.php b/src/Lexicons/Com/Atproto/Repo/StrongRef.php new file mode 100644 index 0000000..037a584 --- /dev/null +++ b/src/Lexicons/Com/Atproto/Repo/StrongRef.php @@ -0,0 +1,53 @@ +uri($uri) + ->cid($cid); + } + + public function uri(string $uri = null) + { + if (is_null($uri)) { + return $this->uri; + } + + $this->uri = $uri; + + return $this; + } + + public function cid(string $cid = null) + { + if (is_null($cid)) { + return $this->cid; + } + + $this->cid = $cid; + + return $this; + } + + public function jsonSerialize(): array + { + return [ + 'uri' => $this->uri, + 'cid' => $this->cid, + ]; + } + + public function __toString(): string + { + return json_encode($this); + } +} diff --git a/tests/Lexicons/Com/Atproto/Repo/StrongRefTest.php b/tests/Lexicons/Com/Atproto/Repo/StrongRefTest.php new file mode 100644 index 0000000..b98c359 --- /dev/null +++ b/tests/Lexicons/Com/Atproto/Repo/StrongRefTest.php @@ -0,0 +1,39 @@ +strongRef = new StrongRef('foo', 'bar'); + } + + public function testUri() + { + $this->assertSame('foo', $this->strongRef->uri()); + $this->strongRef->uri('bar'); + $this->assertSame('bar', $this->strongRef->uri()); + } + + public function testCid() + { + $this->assertSame('bar', $this->strongRef->cid()); + $this->strongRef->cid('foo'); + $this->assertSame('foo', $this->strongRef->cid()); + } + + public function testJsonSerialize(): void + { + $expected = [ + 'uri' => 'foo', + 'cid' => 'bar', + ]; + + $this->assertSame($expected, $this->strongRef->jsonSerialize()); + } +} diff --git a/tests/Unit/Lexicons/App/Bsky/Embed/RecordTest.php b/tests/Unit/Lexicons/App/Bsky/Embed/RecordTest.php new file mode 100644 index 0000000..65423a9 --- /dev/null +++ b/tests/Unit/Lexicons/App/Bsky/Embed/RecordTest.php @@ -0,0 +1,36 @@ + [ + 'uri' => 'foo', + 'cid' => 'bar' + ] + + ]; + + public function setUp(): void + { + $this->record = new Record(new StrongRef('foo', 'bar')); + } + + public function test__toStringWorksWithJsonDecodeDirectly(): void + { + $this->assertSame($this->expected, json_decode($this->record, true)); + } + + public function test__toStringWorksWithJsonEncodeDirectly(): void + { + $this->assertSame(json_encode($this->expected), json_encode($this->record)); + } +} From 4b0bda196df704c5a2ebd0bf83335c3989b4cbc6 Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sat, 12 Oct 2024 21:45:32 +0400 Subject: [PATCH 17/58] Implement RecordWithMedia and MediaInterface - Add MediaInterface for unifying different media types - Implement MediaInterface in ImageCollection, External, and Video classes - Create RecordWithMedia class to combine Record with media content - Add unit tests for RecordWithMedia - Update existing classes to implement new MediaInterface --- .../App/Bsky/Embed/MediaInterface.php | 8 +++++ .../Embed/Collections/ImageCollection.php | 3 +- src/Lexicons/App/Bsky/Embed/External.php | 3 +- .../App/Bsky/Embed/RecordWithMedia.php | 35 ++++++++++++++++++ src/Lexicons/App/Bsky/Embed/Video.php | 3 +- .../App/Bsky/Embed/RecordWithMediaTest.php | 36 +++++++++++++++++++ 6 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 src/Contracts/Lexicons/App/Bsky/Embed/MediaInterface.php create mode 100644 src/Lexicons/App/Bsky/Embed/RecordWithMedia.php create mode 100644 tests/Unit/Lexicons/App/Bsky/Embed/RecordWithMediaTest.php diff --git a/src/Contracts/Lexicons/App/Bsky/Embed/MediaInterface.php b/src/Contracts/Lexicons/App/Bsky/Embed/MediaInterface.php new file mode 100644 index 0000000..6fd2101 --- /dev/null +++ b/src/Contracts/Lexicons/App/Bsky/Embed/MediaInterface.php @@ -0,0 +1,8 @@ +media($media); + } + + public function media(MediaInterface $media = null) + { + if (is_null($media)) { + return $this->media; + } + + $this->media = $media; + + return $this; + } + + public function jsonSerialize(): array + { + return array_merge(parent::jsonSerialize(), [ + 'media' => $this->media, + ]); + } +} diff --git a/src/Lexicons/App/Bsky/Embed/Video.php b/src/Lexicons/App/Bsky/Embed/Video.php index 10cff40..bc97a39 100644 --- a/src/Lexicons/App/Bsky/Embed/Video.php +++ b/src/Lexicons/App/Bsky/Embed/Video.php @@ -2,12 +2,13 @@ namespace Atproto\Lexicons\App\Bsky\Embed; +use Atproto\Contracts\Lexicons\App\Bsky\Embed\MediaInterface; use Atproto\Contracts\Lexicons\App\Bsky\Embed\VideoInterface; use Atproto\Contracts\Stringable; use Atproto\Exceptions\InvalidArgumentException; use Atproto\Lexicons\App\Bsky\Embed\Collections\CaptionCollection; -class Video implements VideoInterface, Stringable +class Video implements MediaInterface, VideoInterface, Stringable { private Blob $file; private ?string $alt = null; diff --git a/tests/Unit/Lexicons/App/Bsky/Embed/RecordWithMediaTest.php b/tests/Unit/Lexicons/App/Bsky/Embed/RecordWithMediaTest.php new file mode 100644 index 0000000..870b73b --- /dev/null +++ b/tests/Unit/Lexicons/App/Bsky/Embed/RecordWithMediaTest.php @@ -0,0 +1,36 @@ +media = $this->createMock(MediaInterface::class); + $this->recordWithMedia = new RecordWithMedia($this->createMock(StrongRef::class), $this->media); + } + + public function testMedia() + { + $this->assertSame($this->media, $this->recordWithMedia->media()); + $this->recordWithMedia->media($expected = $this->createMock(MediaInterface::class)); + $this->assertSame($expected, $this->recordWithMedia->media()); + } + + public function testJsonSerialize() + { + $target = json_decode($this->recordWithMedia, true); + + $this->assertArrayHasKey('record', $target); + $this->assertArrayHasKey('media', $target); + $this->assertIsArray($target['media']); + } +} From e2ed997576880cd770eddc364dc772ab2c0fab58 Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sat, 12 Oct 2024 22:45:16 +0400 Subject: [PATCH 18/58] Implemented `embed` method on PostBuilder API and refactored embeds - EmbedInterface was introduced. All embeds were refactored to implement EmbedInterface. This interface extends two essential interfaces - JsonSerializable and Stringable, which are mandatory for Lexicon implementations. The reason is that when building a post with the PostBuilder API, each entity that can be used as an embed is a lexicon, and a lexicon should be serializable to an object or array type according to SDK design policy when necessary. The Lexicon interface to be introduced in the future will also extend these two interfaces, and all necessary entities will be refactored. - An embed method was added to the PostBuilder API, related tests were refactored/written. --- .../App/Bsky/Embed/EmbedInterface.php | 2 +- .../App/Bsky/Embed/VideoInterface.php | 5 +-- .../App/Bsky/Feed/PostBuilderContract.php | 6 ++-- .../Embed/Collections/EmbedCollection.php | 5 +++ .../Embed/Collections/ImageCollection.php | 4 +-- src/Lexicons/App/Bsky/Embed/External.php | 5 ++- src/Lexicons/App/Bsky/Embed/Record.php | 5 ++- src/Lexicons/App/Bsky/Embed/Video.php | 3 +- src/Lexicons/App/Bsky/Feed/Post.php | 14 ++++++--- .../Unit/Lexicons/App/Bsky/Feed/PostTest.php | 31 ++++++++++++++++++- 10 files changed, 55 insertions(+), 25 deletions(-) diff --git a/src/Contracts/Lexicons/App/Bsky/Embed/EmbedInterface.php b/src/Contracts/Lexicons/App/Bsky/Embed/EmbedInterface.php index 0f20293..4667dd7 100644 --- a/src/Contracts/Lexicons/App/Bsky/Embed/EmbedInterface.php +++ b/src/Contracts/Lexicons/App/Bsky/Embed/EmbedInterface.php @@ -4,6 +4,6 @@ use Atproto\Contracts\Stringable; -interface EmbedInterface extends Stringable +interface EmbedInterface extends \JsonSerializable, Stringable { } diff --git a/src/Contracts/Lexicons/App/Bsky/Embed/VideoInterface.php b/src/Contracts/Lexicons/App/Bsky/Embed/VideoInterface.php index 4e46a35..69ac85b 100644 --- a/src/Contracts/Lexicons/App/Bsky/Embed/VideoInterface.php +++ b/src/Contracts/Lexicons/App/Bsky/Embed/VideoInterface.php @@ -2,13 +2,10 @@ namespace Atproto\Contracts\Lexicons\App\Bsky\Embed; -use Atproto\Contracts\Stringable; use Atproto\Lexicons\App\Bsky\Embed\Collections\CaptionCollection; -use JsonSerializable; -interface VideoInterface extends JsonSerializable +interface VideoInterface extends EmbedInterface { - public function jsonSerialize(): array; public function captions(CaptionCollection $captions = null); public function alt(string $alt = null); public function aspectRatio(); diff --git a/src/Contracts/Lexicons/App/Bsky/Feed/PostBuilderContract.php b/src/Contracts/Lexicons/App/Bsky/Feed/PostBuilderContract.php index 601a088..0db79b1 100644 --- a/src/Contracts/Lexicons/App/Bsky/Feed/PostBuilderContract.php +++ b/src/Contracts/Lexicons/App/Bsky/Feed/PostBuilderContract.php @@ -3,10 +3,8 @@ namespace Atproto\Contracts\Lexicons\App\Bsky\Feed; use Atproto\Contracts\LexiconBuilder; +use Atproto\Contracts\Lexicons\App\Bsky\Embed\EmbedInterface; use Atproto\Contracts\Stringable; -use Atproto\Lexicons\App\Bsky\RichText\Link; -use Atproto\Lexicons\App\Bsky\RichText\Mention; -use Atproto\Lexicons\App\Bsky\RichText\Tag; use DateTimeImmutable; interface PostBuilderContract extends LexiconBuilder, Stringable @@ -21,5 +19,5 @@ public function mention(string $reference, string $label = null): PostBuilderCon public function createdAt(DateTimeImmutable $dateTime): PostBuilderContract; - public function embed(...$embeds): PostBuilderContract; + public function embed(EmbedInterface $embed): PostBuilderContract; } diff --git a/src/Lexicons/App/Bsky/Embed/Collections/EmbedCollection.php b/src/Lexicons/App/Bsky/Embed/Collections/EmbedCollection.php index 8eb17d7..e8c9e4c 100644 --- a/src/Lexicons/App/Bsky/Embed/Collections/EmbedCollection.php +++ b/src/Lexicons/App/Bsky/Embed/Collections/EmbedCollection.php @@ -42,4 +42,9 @@ public function jsonSerialize(): array { return $this->toArray(); } + + public function __toString(): string + { + return json_encode($this); + } } diff --git a/src/Lexicons/App/Bsky/Embed/Collections/ImageCollection.php b/src/Lexicons/App/Bsky/Embed/Collections/ImageCollection.php index 23c678f..57c641e 100644 --- a/src/Lexicons/App/Bsky/Embed/Collections/ImageCollection.php +++ b/src/Lexicons/App/Bsky/Embed/Collections/ImageCollection.php @@ -2,13 +2,13 @@ namespace Atproto\Lexicons\App\Bsky\Embed\Collections; +use Atproto\Contracts\Lexicons\App\Bsky\Embed\EmbedInterface; use Atproto\Contracts\Lexicons\App\Bsky\Embed\ImageInterface; use Atproto\Contracts\Lexicons\App\Bsky\Embed\MediaInterface; use GenericCollection\Exceptions\InvalidArgumentException; use GenericCollection\GenericCollection; -use JsonSerializable; -class ImageCollection extends GenericCollection implements MediaInterface, JsonSerializable +class ImageCollection extends GenericCollection implements EmbedInterface, MediaInterface { use EmbedCollection; diff --git a/src/Lexicons/App/Bsky/Embed/External.php b/src/Lexicons/App/Bsky/Embed/External.php index 8cbba67..8c380ed 100644 --- a/src/Lexicons/App/Bsky/Embed/External.php +++ b/src/Lexicons/App/Bsky/Embed/External.php @@ -2,12 +2,11 @@ namespace Atproto\Lexicons\App\Bsky\Embed; +use Atproto\Contracts\Lexicons\App\Bsky\Embed\EmbedInterface; use Atproto\Contracts\Lexicons\App\Bsky\Embed\MediaInterface; -use Atproto\Contracts\Stringable; use Atproto\Exceptions\InvalidArgumentException; -use JsonSerializable; -class External implements MediaInterface, JsonSerializable, Stringable +class External implements EmbedInterface, MediaInterface { private string $uri; private string $title; diff --git a/src/Lexicons/App/Bsky/Embed/Record.php b/src/Lexicons/App/Bsky/Embed/Record.php index dd873bb..eabe245 100644 --- a/src/Lexicons/App/Bsky/Embed/Record.php +++ b/src/Lexicons/App/Bsky/Embed/Record.php @@ -2,11 +2,10 @@ namespace Atproto\Lexicons\App\Bsky\Embed; -use Atproto\Contracts\Stringable; +use Atproto\Contracts\Lexicons\App\Bsky\Embed\EmbedInterface; use Atproto\Lexicons\Com\Atproto\Repo\StrongRef; -use JsonSerializable; -class Record implements JsonSerializable, Stringable +class Record implements EmbedInterface { private StrongRef $ref; diff --git a/src/Lexicons/App/Bsky/Embed/Video.php b/src/Lexicons/App/Bsky/Embed/Video.php index bc97a39..2b799c8 100644 --- a/src/Lexicons/App/Bsky/Embed/Video.php +++ b/src/Lexicons/App/Bsky/Embed/Video.php @@ -4,11 +4,10 @@ use Atproto\Contracts\Lexicons\App\Bsky\Embed\MediaInterface; use Atproto\Contracts\Lexicons\App\Bsky\Embed\VideoInterface; -use Atproto\Contracts\Stringable; use Atproto\Exceptions\InvalidArgumentException; use Atproto\Lexicons\App\Bsky\Embed\Collections\CaptionCollection; -class Video implements MediaInterface, VideoInterface, Stringable +class Video implements VideoInterface, MediaInterface { private Blob $file; private ?string $alt = null; diff --git a/src/Lexicons/App/Bsky/Feed/Post.php b/src/Lexicons/App/Bsky/Feed/Post.php index 560b1af..644a810 100644 --- a/src/Lexicons/App/Bsky/Feed/Post.php +++ b/src/Lexicons/App/Bsky/Feed/Post.php @@ -4,6 +4,7 @@ use Atproto\Collections\FacetCollection; use Atproto\Collections\FeatureCollection; +use Atproto\Contracts\Lexicons\App\Bsky\Embed\EmbedInterface; use Atproto\Contracts\Lexicons\App\Bsky\Feed\PostBuilderContract; use Atproto\Exceptions\InvalidArgumentException; use Atproto\Lexicons\App\Bsky\RichText\ByteSlice; @@ -21,6 +22,7 @@ class Post implements PostBuilderContract private string $text = ''; private ?DateTimeImmutable $createdAt = null; private FacetCollection $facets; + private ?EmbedInterface $embed = null; public function __construct() { @@ -70,8 +72,10 @@ public function mention(string $reference, string $label = null): PostBuilderCon return $this->addFeatureItem('mention', $reference, $label); } - public function embed(...$embeds): PostBuilderContract + public function embed(EmbedInterface $embed = null): PostBuilderContract { + $this->embed = $embed; + return $this; } @@ -84,12 +88,13 @@ public function createdAt(DateTimeImmutable $dateTime): PostBuilderContract public function jsonSerialize(): array { - return [ + return array_filter([ '$type' => self::TYPE_NAME, 'createdAt' => $this->getFormattedCreatedAt(), 'text' => $this->text, 'facets' => $this->facets->toArray(), - ]; + 'embed' => ($e = $this->embed) ? $e : null, + ]); } public function __toString(): string @@ -181,11 +186,10 @@ private function addFeature(FeatureAbstract $feature): void $this->text .= $label; try { - $facet = new Facet( + $this->facets[] = new Facet( new FeatureCollection([$feature]), new ByteSlice($this->text, $label) ); - $this->facets[] = $facet; } catch (\GenericCollection\Exceptions\InvalidArgumentException $e) { throw new InvalidArgumentException( sprintf('Feature must be an instance of %s.', FeatureAbstract::class) diff --git a/tests/Unit/Lexicons/App/Bsky/Feed/PostTest.php b/tests/Unit/Lexicons/App/Bsky/Feed/PostTest.php index fb65b3f..9582c94 100644 --- a/tests/Unit/Lexicons/App/Bsky/Feed/PostTest.php +++ b/tests/Unit/Lexicons/App/Bsky/Feed/PostTest.php @@ -2,7 +2,11 @@ namespace Tests\Unit\Lexicons\App\Bsky\Feed; +use Atproto\Contracts\Lexicons\App\Bsky\Embed\EmbedInterface; +use Atproto\Contracts\Lexicons\App\Bsky\Embed\VideoInterface; use Atproto\Exceptions\InvalidArgumentException; +use Atproto\Lexicons\App\Bsky\Embed\Blob; +use Atproto\Lexicons\App\Bsky\Embed\Video; use Atproto\Lexicons\App\Bsky\Feed\Post; use Atproto\Lexicons\App\Bsky\RichText\FeatureAbstract; use Atproto\Lexicons\App\Bsky\RichText\Mention; @@ -148,15 +152,40 @@ public function testCreatedAtField() $this->assertNotNull($result['createdAt']); } + public function testEmbed(): void + { + $video = $this->getMockBuilder(VideoInterface::class) + ->disableOriginalConstructor() + ->getMock(); + + $video->expects($this->once()) + ->method('jsonSerialize') + ->willReturn(['foo' => 'bar']); + + $this->post->embed($video); + + $expected = ['foo' => 'bar']; + $actual = json_decode($this->post, true); + + $this->assertArrayHasKey('embed', $actual); + $this->assertSame($expected, $actual['embed']); + } + + /** + * @throws InvalidArgumentException + */ public function testJsonSerialize() { - $this->post->text('Test post'); + $this->post->text('Test post: ', new Mention('reference', 'label')); + $this->post->embed($embed = $this->createMock(EmbedInterface::class)); + $result = $this->post->jsonSerialize(); $this->assertArrayHasKey('$type', $result); $this->assertEquals('app.bsky.feed.post', $result['$type']); $this->assertArrayHasKey('text', $result); $this->assertArrayHasKey('createdAt', $result); $this->assertArrayHasKey('facets', $result); + $this->assertArrayHasKey('embed', $result); } /** From f03e978d7f715ad1951ea35359a25286ae8db152 Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sat, 12 Oct 2024 22:55:51 +0400 Subject: [PATCH 19/58] Code cleanup and test refinements --- src/Lexicons/App/Bsky/RichText/ByteSlice.php | 2 +- src/Lexicons/App/Bsky/RichText/FeatureFactory.php | 1 - tests/Unit/Lexicons/App/Bsky/Embed/FileMocking.php | 10 +++++----- tests/Unit/Lexicons/App/Bsky/Feed/PostTest.php | 4 +--- .../Lexicons/Com/Atproto/Repo/StrongRefTest.php | 3 ++- 5 files changed, 9 insertions(+), 11 deletions(-) rename tests/{ => Unit}/Lexicons/Com/Atproto/Repo/StrongRefTest.php (89%) diff --git a/src/Lexicons/App/Bsky/RichText/ByteSlice.php b/src/Lexicons/App/Bsky/RichText/ByteSlice.php index 9f5ab96..75884ec 100644 --- a/src/Lexicons/App/Bsky/RichText/ByteSlice.php +++ b/src/Lexicons/App/Bsky/RichText/ByteSlice.php @@ -32,4 +32,4 @@ public function jsonSerialize(): array 'byteEnd' => $this->end(), ]; } -} \ No newline at end of file +} diff --git a/src/Lexicons/App/Bsky/RichText/FeatureFactory.php b/src/Lexicons/App/Bsky/RichText/FeatureFactory.php index 01a9682..3000d05 100644 --- a/src/Lexicons/App/Bsky/RichText/FeatureFactory.php +++ b/src/Lexicons/App/Bsky/RichText/FeatureFactory.php @@ -4,7 +4,6 @@ class FeatureFactory { - public static function link(string $reference, string $label = null): Link { return new Link($reference, $label); diff --git a/tests/Unit/Lexicons/App/Bsky/Embed/FileMocking.php b/tests/Unit/Lexicons/App/Bsky/Embed/FileMocking.php index 9e43b22..b1ba4cf 100644 --- a/tests/Unit/Lexicons/App/Bsky/Embed/FileMocking.php +++ b/tests/Unit/Lexicons/App/Bsky/Embed/FileMocking.php @@ -23,20 +23,20 @@ private function createMockFile() $file->expects($this->any()) ->method('path') - ->will($this->returnCallback(fn() => $this->path)); + ->will($this->returnCallback(fn () => $this->path)); $file->expects($this->any()) ->method('type') - ->will($this->returnCallback(fn() => $this->type)); + ->will($this->returnCallback(fn () => $this->type)); $file->expects($this->any()) ->method('size') - ->will($this->returnCallback(fn() => $this->size)); + ->will($this->returnCallback(fn () => $this->size)); $file->expects($this->any()) ->method('blob') - ->will($this->returnCallback(fn() => $this->blob)); + ->will($this->returnCallback(fn () => $this->blob)); return $file; } -} \ No newline at end of file +} diff --git a/tests/Unit/Lexicons/App/Bsky/Feed/PostTest.php b/tests/Unit/Lexicons/App/Bsky/Feed/PostTest.php index 9582c94..b2d6296 100644 --- a/tests/Unit/Lexicons/App/Bsky/Feed/PostTest.php +++ b/tests/Unit/Lexicons/App/Bsky/Feed/PostTest.php @@ -5,8 +5,6 @@ use Atproto\Contracts\Lexicons\App\Bsky\Embed\EmbedInterface; use Atproto\Contracts\Lexicons\App\Bsky\Embed\VideoInterface; use Atproto\Exceptions\InvalidArgumentException; -use Atproto\Lexicons\App\Bsky\Embed\Blob; -use Atproto\Lexicons\App\Bsky\Embed\Video; use Atproto\Lexicons\App\Bsky\Feed\Post; use Atproto\Lexicons\App\Bsky\RichText\FeatureAbstract; use Atproto\Lexicons\App\Bsky\RichText\Mention; @@ -142,7 +140,7 @@ public function testTextThrowsExceptionWhenPassedInvalidArgument(): void "Argument at index 4 is invalid: must be a string or an instance of " . FeatureAbstract::class ); - $this->post->text(1, true, 'string', new Post); + $this->post->text(1, true, 'string', new Post()); } public function testCreatedAtField() diff --git a/tests/Lexicons/Com/Atproto/Repo/StrongRefTest.php b/tests/Unit/Lexicons/Com/Atproto/Repo/StrongRefTest.php similarity index 89% rename from tests/Lexicons/Com/Atproto/Repo/StrongRefTest.php rename to tests/Unit/Lexicons/Com/Atproto/Repo/StrongRefTest.php index b98c359..6a9165a 100644 --- a/tests/Lexicons/Com/Atproto/Repo/StrongRefTest.php +++ b/tests/Unit/Lexicons/Com/Atproto/Repo/StrongRefTest.php @@ -1,7 +1,8 @@ Date: Sat, 12 Oct 2024 23:43:32 +0400 Subject: [PATCH 20/58] Implement 'reply' method in PostBuilder API and fix text length validation --- .../App/Bsky/Feed/PostBuilderContract.php | 3 + src/Lexicons/App/Bsky/Feed/Post.php | 17 +- .../Unit/Lexicons/App/Bsky/Feed/PostTest.php | 146 ++++++++---------- 3 files changed, 85 insertions(+), 81 deletions(-) diff --git a/src/Contracts/Lexicons/App/Bsky/Feed/PostBuilderContract.php b/src/Contracts/Lexicons/App/Bsky/Feed/PostBuilderContract.php index 0db79b1..ecc7517 100644 --- a/src/Contracts/Lexicons/App/Bsky/Feed/PostBuilderContract.php +++ b/src/Contracts/Lexicons/App/Bsky/Feed/PostBuilderContract.php @@ -5,6 +5,7 @@ use Atproto\Contracts\LexiconBuilder; use Atproto\Contracts\Lexicons\App\Bsky\Embed\EmbedInterface; use Atproto\Contracts\Stringable; +use Atproto\Lexicons\Com\Atproto\Repo\StrongRef; use DateTimeImmutable; interface PostBuilderContract extends LexiconBuilder, Stringable @@ -20,4 +21,6 @@ public function mention(string $reference, string $label = null): PostBuilderCon public function createdAt(DateTimeImmutable $dateTime): PostBuilderContract; public function embed(EmbedInterface $embed): PostBuilderContract; + + public function reply(StrongRef $root, StrongRef $parent): PostBuilderContract; } diff --git a/src/Lexicons/App/Bsky/Feed/Post.php b/src/Lexicons/App/Bsky/Feed/Post.php index 644a810..454f0a6 100644 --- a/src/Lexicons/App/Bsky/Feed/Post.php +++ b/src/Lexicons/App/Bsky/Feed/Post.php @@ -11,6 +11,7 @@ use Atproto\Lexicons\App\Bsky\RichText\Facet; use Atproto\Lexicons\App\Bsky\RichText\FeatureAbstract; use Atproto\Lexicons\App\Bsky\RichText\FeatureFactory; +use Atproto\Lexicons\Com\Atproto\Repo\StrongRef; use Carbon\Carbon; use DateTimeImmutable; @@ -23,6 +24,7 @@ class Post implements PostBuilderContract private ?DateTimeImmutable $createdAt = null; private FacetCollection $facets; private ?EmbedInterface $embed = null; + private ?array $reply = null; public function __construct() { @@ -79,6 +81,16 @@ public function embed(EmbedInterface $embed = null): PostBuilderContract return $this; } + public function reply(StrongRef $root, StrongRef $parent): PostBuilderContract + { + $this->reply = [ + 'root' => $root, + 'parent' => $parent + ]; + + return $this; + } + public function createdAt(DateTimeImmutable $dateTime): PostBuilderContract { $this->createdAt = $dateTime; @@ -93,7 +105,8 @@ public function jsonSerialize(): array 'createdAt' => $this->getFormattedCreatedAt(), 'text' => $this->text, 'facets' => $this->facets->toArray(), - 'embed' => ($e = $this->embed) ? $e : null, + 'embed' => $this->embed, + 'replyRef' => $this->reply, ]); } @@ -129,7 +142,7 @@ private function validate($item, int $index = 0): void ); } - if ($this->isString($item) && mb_strlen($item) > self::TEXT_LIMIT) { + if ($this->isString($item) && (mb_strlen($item) + mb_strlen($this->text)) > self::TEXT_LIMIT) { throw new InvalidArgumentException( sprintf( 'Text must be less than or equal to %d characters.', diff --git a/tests/Unit/Lexicons/App/Bsky/Feed/PostTest.php b/tests/Unit/Lexicons/App/Bsky/Feed/PostTest.php index b2d6296..3bcac96 100644 --- a/tests/Unit/Lexicons/App/Bsky/Feed/PostTest.php +++ b/tests/Unit/Lexicons/App/Bsky/Feed/PostTest.php @@ -3,11 +3,11 @@ namespace Tests\Unit\Lexicons\App\Bsky\Feed; use Atproto\Contracts\Lexicons\App\Bsky\Embed\EmbedInterface; -use Atproto\Contracts\Lexicons\App\Bsky\Embed\VideoInterface; use Atproto\Exceptions\InvalidArgumentException; use Atproto\Lexicons\App\Bsky\Feed\Post; use Atproto\Lexicons\App\Bsky\RichText\FeatureAbstract; use Atproto\Lexicons\App\Bsky\RichText\Mention; +use Atproto\Lexicons\Com\Atproto\Repo\StrongRef; use Carbon\Carbon; use DateTimeImmutable; use PHPUnit\Framework\TestCase; @@ -16,7 +16,7 @@ class PostTest extends TestCase { private Post $post; - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->post = new Post(); @@ -28,20 +28,18 @@ public function setUp(): void public function testTextMethodWithBasicUsage() { $this->post->text('Hello, world!'); - $result = json_decode($this->post, true); + $result = json_decode((string) $this->post, true); $this->assertEquals('Hello, world!', $result['text']); } /** * @throws InvalidArgumentException */ - public function testTextMethod() + public function testTextMethodWithMultipleItems() { $this->post->text('Hello', ', ', new Mention('example:did:123', 'user'), "! It's ", 5, " o'clock now."); - $result = json_decode(json_encode($this->post), true); + $result = json_decode((string) $this->post, true); $this->assertEquals("Hello, @user! It's 5 o'clock now.", $result['text']); - - $this->post->text('This ', new Mention('example:did:123', 'user'), '!'); } /** @@ -50,7 +48,7 @@ public function testTextMethod() public function testTagMethod() { $this->post->tag('example', 'test'); - $result = json_decode($this->post, true); + $result = json_decode((string) $this->post, true); $this->assertEquals('#test', $result['text']); $this->assertCount(1, $result['facets']); } @@ -60,8 +58,8 @@ public function testTagMethod() */ public function testLinkMethod() { - $this->post->link('https://example.com', 'Example'); - $result = json_decode($this->post, true); + $this->post->link('https://shahmal1yev.dev', 'Example'); + $result = json_decode((string) $this->post, true); $this->assertEquals('Example', $result['text']); $this->assertCount(1, $result['facets']); } @@ -72,51 +70,55 @@ public function testLinkMethod() public function testMentionMethod() { $this->post->mention('did:example:123', 'user'); - $result = json_decode($this->post, true); + $result = json_decode((string) $this->post, true); $this->assertEquals('@user', $result['text']); $this->assertCount(1, $result['facets']); } public function testCombinationOfMethods() { - $this->post = $this->post(); + $post = $this->createSamplePost(); - $result = json_decode($this->post, true); + $result = json_decode((string) $post, true); $this->assertEquals('Hello @user! Check out this link #example_tag', $result['text']); $this->assertCount(3, $result['facets']); } - public function testCoordinatesOfFacets(): void + public function testCoordinatesOfFacets() { - $this->post = $this->post(); + $post = $this->createSamplePost(); - $result = json_decode($this->post, true); + $result = json_decode((string) $post, true); $text = $result['text']; $facets = $result['facets']; - $this->assertSame($facets[0]['index'], $this->bytes($text, "@user")); - $this->assertSame($facets[1]['index'], $this->bytes($text, "this link")); - $this->assertSame($facets[2]['index'], $this->bytes($text, "#example_tag")); + $this->assertSame($this->calculateByteSlice($text, '@user'), $facets[0]['index']); + $this->assertSame($this->calculateByteSlice($text, 'this link'), $facets[1]['index']); + $this->assertSame($this->calculateByteSlice($text, '#example_tag'), $facets[2]['index']); } - private function bytes(string $haystack, string $needle): array + private function calculateByteSlice(string $text, string $substring): array { - $pos = mb_strpos($haystack, $needle); - $len = $pos + mb_strlen($needle); + $byteStart = mb_strpos($text, $substring); + $byteEnd = $byteStart + mb_strlen($substring); return [ - 'byteStart' => $pos, - 'byteEnd' => $len, + 'byteStart' => $byteStart, + 'byteEnd' => $byteEnd, ]; } - private function post(): Post + /** + * @throws InvalidArgumentException + */ + private function createSamplePost(): Post { - return $this->post->text('Hello ') + return (new Post()) + ->text('Hello ') ->mention('did:example:123', 'user') ->text('! Check out ') - ->link('https://example.com', 'this link') + ->link('https://shahmal1yev.dev', 'this link') ->text(' ') ->tag('example_tag'); } @@ -129,44 +131,52 @@ public function testTextThrowsExceptionWhenLimitIsExceeded() $this->post->text(str_repeat('a', 3000)); $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Text must be less than or equal to 3000 characters.'); - $this->post->text(str_repeat('a', 3001)); + // This should cause the total text length to exceed the limit + $this->post->text('a'); } - public function testTextThrowsExceptionWhenPassedInvalidArgument(): void + public function testTextThrowsExceptionWhenPassedInvalidArgument() { $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage( - "Argument at index 4 is invalid: must be a string or an instance of " . FeatureAbstract::class - ); + $this->expectExceptionMessageMatches('/Argument at index \d+ is invalid/'); $this->post->text(1, true, 'string', new Post()); } - public function testCreatedAtField() + public function testCreatedAtFieldIsSetByDefault() { - $result = json_decode($this->post, true); + $this->post->text('Test post'); + $result = json_decode((string) $this->post, true); + $this->assertArrayHasKey('createdAt', $result); - $this->assertNotNull($result['createdAt']); + + $createdAt = Carbon::parse($result['createdAt']); + $now = Carbon::now(); + + $this->assertTrue($createdAt->diffInSeconds($now) < 5, 'createdAt should be within the last 5 seconds'); } - public function testEmbed(): void + public function testCreatedAtReturnsAssignedTime() { - $video = $this->getMockBuilder(VideoInterface::class) - ->disableOriginalConstructor() - ->getMock(); + $futureTime = Carbon::now()->addHour(); + $this->post->createdAt($futureTime->toDateTimeImmutable()); - $video->expects($this->once()) - ->method('jsonSerialize') - ->willReturn(['foo' => 'bar']); + $result = json_decode((string) $this->post, true); + $this->assertEquals($futureTime->toIso8601String(), $result['createdAt']); + } - $this->post->embed($video); + public function testEmbedMethod() + { + $embed = $this->createMock(EmbedInterface::class); + $embed->method('jsonSerialize')->willReturn(['embedData' => 'value']); - $expected = ['foo' => 'bar']; - $actual = json_decode($this->post, true); + $this->post->embed($embed); - $this->assertArrayHasKey('embed', $actual); - $this->assertSame($expected, $actual['embed']); + $result = json_decode((string) $this->post, true); + $this->assertArrayHasKey('embed', $result); + $this->assertEquals(['embedData' => 'value'], $result['embed']); } /** @@ -175,7 +185,11 @@ public function testEmbed(): void public function testJsonSerialize() { $this->post->text('Test post: ', new Mention('reference', 'label')); - $this->post->embed($embed = $this->createMock(EmbedInterface::class)); + $embed = $this->createMock(EmbedInterface::class); + $embed->method('jsonSerialize')->willReturn(['embedKey' => 'embedValue']); + $this->post->embed($embed); + $sRef = new StrongRef('foo', 'bar'); + $this->post->reply($sRef, clone $sRef); $result = $this->post->jsonSerialize(); $this->assertArrayHasKey('$type', $result); @@ -184,39 +198,13 @@ public function testJsonSerialize() $this->assertArrayHasKey('createdAt', $result); $this->assertArrayHasKey('facets', $result); $this->assertArrayHasKey('embed', $result); + $this->assertArrayHasKey('replyRef', $result); } - /** - * @throws InvalidArgumentException - */ - public function testCreatedAtAssignedByDefault(): void - { - $post = $this->post->text('Test post'); - $result = json_decode($post, true); - - $this->assertSame($result['createdAt'], Carbon::now()->toIso8601String()); - } - - public function testCreatedAtReturnsAssignedTime(): void + public function testConstructorWorksCorrectlyOnDirectBuild() { - $timestamp = time() + 3600; // Get the current timestamp - $this->post->createdAt(new DateTimeImmutable("@$timestamp")); - - $actual = json_decode($this->post, false)->createdAt; - $expected = Carbon::now()->modify("+1 hour")->toIso8601String(); - - $this->assertSame( - $actual, - $expected, - ); - } - - public function testConstructorWorksCorrectlyOnDirectBuild(): void - { - $array = json_decode($this->post, true); - $json = json_encode($array); - - $this->assertTrue(is_array($array)); - $this->assertTrue(json_encode($array) === $json); + $result = json_decode((string) $this->post, true); + $this->assertIsArray($result); + $this->assertEquals($result, json_decode(json_encode($result), true)); } } From 612b6a583c964fbe5061712f84990248d99b1395 Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sun, 13 Oct 2024 00:23:22 +0400 Subject: [PATCH 21/58] Add language support to PostBuilderContract and Post class - Added `langs` method to PostBuilderContract interface to handle language settings for a post. - Implemented `langs` method in the Post class to set and validate language codes with a limit of 3 languages. - Added validation for language codes using a regex to ensure conformity with the standard language tag format. --- .../App/Bsky/Feed/PostBuilderContract.php | 2 + src/Lexicons/App/Bsky/Feed/Post.php | 58 +++++++++++++++++++ .../Unit/Lexicons/App/Bsky/Feed/PostTest.php | 37 ++++++++++++ 3 files changed, 97 insertions(+) diff --git a/src/Contracts/Lexicons/App/Bsky/Feed/PostBuilderContract.php b/src/Contracts/Lexicons/App/Bsky/Feed/PostBuilderContract.php index ecc7517..b90afc6 100644 --- a/src/Contracts/Lexicons/App/Bsky/Feed/PostBuilderContract.php +++ b/src/Contracts/Lexicons/App/Bsky/Feed/PostBuilderContract.php @@ -23,4 +23,6 @@ public function createdAt(DateTimeImmutable $dateTime): PostBuilderContract; public function embed(EmbedInterface $embed): PostBuilderContract; public function reply(StrongRef $root, StrongRef $parent): PostBuilderContract; + + public function langs(array $languages): PostBuilderContract; } diff --git a/src/Lexicons/App/Bsky/Feed/Post.php b/src/Lexicons/App/Bsky/Feed/Post.php index 454f0a6..6a1d450 100644 --- a/src/Lexicons/App/Bsky/Feed/Post.php +++ b/src/Lexicons/App/Bsky/Feed/Post.php @@ -25,6 +25,7 @@ class Post implements PostBuilderContract private FacetCollection $facets; private ?EmbedInterface $embed = null; private ?array $reply = null; + private ?array $languages = null; public function __construct() { @@ -91,6 +92,62 @@ public function reply(StrongRef $root, StrongRef $parent): PostBuilderContract return $this; } + /** + * Sets the languages for the post. + * + * @param array $languages + * @return PostBuilderContract + * @throws InvalidArgumentException + */ + public function langs(array $languages): PostBuilderContract + { + if (count($languages) > 3) { + throw new InvalidArgumentException('A maximum of 3 language codes is allowed.'); + } + + foreach($languages as $lang) { + if (! $this->isValidLanguageCode($lang)) { + throw new InvalidArgumentException(sprintf('Invalid language code: %s', $lang)); + } + } + + if (empty($languages)) { + $languages = null; + } + + $this->languages = $languages; + + return $this; + } + + /** + * Validates the format of a language code. + * + * @param string $lang + * @return bool + */ + private function isValidLanguageCode(string $lang): bool + { + $regular = '(art-lojban|cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|zh-min|zh-min-nan|zh-xiang)'; + $irregular = '(en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)'; + $grandfathered = '(' . $irregular . '|' . $regular . ')'; + $privateUse = '(x(-[A-Za-z0-9]{1,8})+)'; + $privateUse2 = '(x(-[A-Za-z0-9]{1,8})+)'; + $singleton = '[0-9A-WY-Za-wy-z]'; + $extension = '(' . $singleton . '(-[A-Za-z0-9]{2,8})+)'; + $variant = '([A-Za-z0-9]{5,8}|[0-9][A-Za-z0-9]{3})'; + $region = '([A-Za-z]{2}|[0-9]{3})'; + $script = '([A-Za-z]{4})'; + $extlang = '([A-Za-z]{3}(-[A-Za-z]{3}){0,2})'; + $language = '(([A-Za-z]{2,3}(-' . $extlang . ')?)|[A-Za-z]{4}|[A-Za-z]{5,8})'; + $langtag = '(' . $language . '(-' . $script . ')?(-' . $region . ')?(-' . $variant . ')*(-' . $extension . ')*(-' . $privateUse . ')?)'; + $languageTag = '(' . $grandfathered . '|' . $langtag . '|' . $privateUse2 . ')'; + + $regex = '/^' . $languageTag . '$/'; + + return preg_match($regex, $lang); + } + public function createdAt(DateTimeImmutable $dateTime): PostBuilderContract { $this->createdAt = $dateTime; @@ -107,6 +164,7 @@ public function jsonSerialize(): array 'facets' => $this->facets->toArray(), 'embed' => $this->embed, 'replyRef' => $this->reply, + 'langs' => $this->languages, ]); } diff --git a/tests/Unit/Lexicons/App/Bsky/Feed/PostTest.php b/tests/Unit/Lexicons/App/Bsky/Feed/PostTest.php index 3bcac96..2f8b657 100644 --- a/tests/Unit/Lexicons/App/Bsky/Feed/PostTest.php +++ b/tests/Unit/Lexicons/App/Bsky/Feed/PostTest.php @@ -179,6 +179,41 @@ public function testEmbedMethod() $this->assertEquals(['embedData' => 'value'], $result['embed']); } + /** + * @throws InvalidArgumentException + */ + public function testLangsMethodWithValidInput() + { + $this->post->langs(['en', 'fr', 'es']); + $result = json_decode($this->post, true); + + $this->assertArrayHasKey('langs', $result); + $this->assertEquals(['en', 'fr', 'es'], $result['langs']); + } + + /** + * @throws InvalidArgumentException + */ + public function testLangsMethodThrowsExceptionOnTooManyLanguages() + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('A maximum of 3 language codes is allowed.'); + + $this->post->langs(['en', 'fr', 'es', 'de']); + } + + /** + * @throws InvalidArgumentException + */ + public function testLangsMethodThrowsExceptionOnInvalidLanguageCode() + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('Invalid language code: d'); + + $this->post->langs(['en', 'd']); + } + + /** * @throws InvalidArgumentException */ @@ -190,6 +225,7 @@ public function testJsonSerialize() $this->post->embed($embed); $sRef = new StrongRef('foo', 'bar'); $this->post->reply($sRef, clone $sRef); + $this->post->langs(['en', 'fr', 'es']); $result = $this->post->jsonSerialize(); $this->assertArrayHasKey('$type', $result); @@ -199,6 +235,7 @@ public function testJsonSerialize() $this->assertArrayHasKey('facets', $result); $this->assertArrayHasKey('embed', $result); $this->assertArrayHasKey('replyRef', $result); + $this->assertArrayHasKey('langs', $result); } public function testConstructorWorksCorrectlyOnDirectBuild() From b249eb9a7ce5c12d3a675f826000e05f40768b75 Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sun, 13 Oct 2024 22:04:45 +0400 Subject: [PATCH 22/58] SelfLabels lexicon and corresponding unit tests --- src/Lexicons/Com/Atproto/Label/SelfLabels.php | 74 +++++++++++++++++++ .../Com/Atproto/Label/SelfLabelsTest.php | 73 ++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 src/Lexicons/Com/Atproto/Label/SelfLabels.php create mode 100644 tests/Unit/Lexicons/Com/Atproto/Label/SelfLabelsTest.php diff --git a/src/Lexicons/Com/Atproto/Label/SelfLabels.php b/src/Lexicons/Com/Atproto/Label/SelfLabels.php new file mode 100644 index 0000000..f2a0fd0 --- /dev/null +++ b/src/Lexicons/Com/Atproto/Label/SelfLabels.php @@ -0,0 +1,74 @@ +collection = $collection; + + try { + parent::__construct($this->validator(), $collection); + } catch (\TypeError|\GenericCollection\Exceptions\InvalidArgumentException $e) { + $this->throw($e); + } + } + + private function validator(): \Closure + { + return function (string $val): bool { + if ($this->count() + 1 > self::MAXLENGTH) { + throw new InvalidArgumentException("Maximum allowed length is " . self::MAXLENGTH); + } + + if (strlen($val) > self::MAXLENGTH_BY_ITEM) { + throw new InvalidArgumentException("Length exceeded for $val. Max ".self::MAXLENGTH_BY_ITEM." characters allowed."); + } + + return true; + }; + } + + /** + * @throws InvalidArgumentException + */ + private function throw($exception): void + { + throw new InvalidArgumentException( + str_replace( + "::".__NAMESPACE__."\{closure}()", + "", + $exception->getMessage() + ), + 0, + $exception + ); + } + + public function __toString(): string + { + return json_encode($this); + } + + public function jsonSerialize() + { + return $this->toArray(); + } + + public function toArray(): array + { + return array_map(fn (string $val) => ['val' => $val], $this->collection); + } +} diff --git a/tests/Unit/Lexicons/Com/Atproto/Label/SelfLabelsTest.php b/tests/Unit/Lexicons/Com/Atproto/Label/SelfLabelsTest.php new file mode 100644 index 0000000..b5291be --- /dev/null +++ b/tests/Unit/Lexicons/Com/Atproto/Label/SelfLabelsTest.php @@ -0,0 +1,73 @@ +selfLabels = new SelfLabels(); + } + + /** + * @throws InvalidArgumentException + */ + public function test__constructFillsDataCorrectly(): void + { + $expected = array_map(fn (string $val) => ['val' => $val], ['val 1', 'val 2', 'val 3']); + + $this->selfLabels = new SelfLabels(array_column( + $expected, + 'val' + )); + + $this->assertEquals($expected, $this->selfLabels->toArray()); + } + + public function test__constructorThrowsInvalidArgumentExceptionWhenPassedInvalidArgument(): void + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage("must be of the type string"); + + $this->selfLabels = new SelfLabels(['val 1', new stdClass()]); + } + + public function test__constructThrowsInvalidArgumentExceptionWhenLimitExceeded(): void + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage("Maximum allowed length is ".$this->maxlength); + + $trigger = str_split(str_pad('', ++$this->maxlength, 'a')); + $this->selfLabels = new SelfLabels($trigger); + } + + public function test__constructorThrowsExceptionWhenPassedArgumentThatExceedsLimit(): void + { + $trigger = [str_pad('', ++$this->maxlengthByItem, 'a')]; + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage("Length exceeded for " . current($trigger)); + + $this->selfLabels = new SelfLabels($trigger); + } + + public function testAddThrowsExceptionWhenPassedArgumentExceedsMaxLengthLimit(): void + { + $trigger = str_split(str_pad('', ++$this->maxlength, 'a')); + + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage("Maximum allowed length is ".--$this->maxlength); + + foreach($trigger as $item) { + $this->selfLabels[] = $item; + } + } +} From b21eb1367da8366ea1c3fc2c8dcca0c5721e7bea Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sun, 13 Oct 2024 22:15:05 +0400 Subject: [PATCH 23/58] Add support for labels in PostBuilderContract and Post class --- .../App/Bsky/Feed/PostBuilderContract.php | 3 +++ src/Lexicons/App/Bsky/Feed/Post.php | 11 +++++++++ .../Unit/Lexicons/App/Bsky/Feed/PostTest.php | 23 +++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/src/Contracts/Lexicons/App/Bsky/Feed/PostBuilderContract.php b/src/Contracts/Lexicons/App/Bsky/Feed/PostBuilderContract.php index b90afc6..9058dc6 100644 --- a/src/Contracts/Lexicons/App/Bsky/Feed/PostBuilderContract.php +++ b/src/Contracts/Lexicons/App/Bsky/Feed/PostBuilderContract.php @@ -5,6 +5,7 @@ use Atproto\Contracts\LexiconBuilder; use Atproto\Contracts\Lexicons\App\Bsky\Embed\EmbedInterface; use Atproto\Contracts\Stringable; +use Atproto\Lexicons\Com\Atproto\Label\SelfLabels; use Atproto\Lexicons\Com\Atproto\Repo\StrongRef; use DateTimeImmutable; @@ -25,4 +26,6 @@ public function embed(EmbedInterface $embed): PostBuilderContract; public function reply(StrongRef $root, StrongRef $parent): PostBuilderContract; public function langs(array $languages): PostBuilderContract; + + public function labels(SelfLabels $labels): PostBuilderContract; } diff --git a/src/Lexicons/App/Bsky/Feed/Post.php b/src/Lexicons/App/Bsky/Feed/Post.php index 6a1d450..b028d64 100644 --- a/src/Lexicons/App/Bsky/Feed/Post.php +++ b/src/Lexicons/App/Bsky/Feed/Post.php @@ -11,6 +11,7 @@ use Atproto\Lexicons\App\Bsky\RichText\Facet; use Atproto\Lexicons\App\Bsky\RichText\FeatureAbstract; use Atproto\Lexicons\App\Bsky\RichText\FeatureFactory; +use Atproto\Lexicons\Com\Atproto\Label\SelfLabels; use Atproto\Lexicons\Com\Atproto\Repo\StrongRef; use Carbon\Carbon; use DateTimeImmutable; @@ -26,6 +27,8 @@ class Post implements PostBuilderContract private ?EmbedInterface $embed = null; private ?array $reply = null; private ?array $languages = null; + private ?SelfLabels $labels = null; + public function __construct() { @@ -120,6 +123,13 @@ public function langs(array $languages): PostBuilderContract return $this; } + public function labels(SelfLabels $labels): PostBuilderContract + { + $this->labels = $labels; + + return $this; + } + /** * Validates the format of a language code. * @@ -165,6 +175,7 @@ public function jsonSerialize(): array 'embed' => $this->embed, 'replyRef' => $this->reply, 'langs' => $this->languages, + 'labels' => $this->labels ]); } diff --git a/tests/Unit/Lexicons/App/Bsky/Feed/PostTest.php b/tests/Unit/Lexicons/App/Bsky/Feed/PostTest.php index 2f8b657..8678a23 100644 --- a/tests/Unit/Lexicons/App/Bsky/Feed/PostTest.php +++ b/tests/Unit/Lexicons/App/Bsky/Feed/PostTest.php @@ -7,6 +7,7 @@ use Atproto\Lexicons\App\Bsky\Feed\Post; use Atproto\Lexicons\App\Bsky\RichText\FeatureAbstract; use Atproto\Lexicons\App\Bsky\RichText\Mention; +use Atproto\Lexicons\Com\Atproto\Label\SelfLabels; use Atproto\Lexicons\Com\Atproto\Repo\StrongRef; use Carbon\Carbon; use DateTimeImmutable; @@ -213,6 +214,23 @@ public function testLangsMethodThrowsExceptionOnInvalidLanguageCode() $this->post->langs(['en', 'd']); } + /** + * @throws InvalidArgumentException + */ + public function testLabelsMethod(): void + { + $labels = new SelfLabels(['v 1', 'v 2', 'v 3']); + + $this->post->labels($labels); + + $result = json_decode($this->post, true); + $this->assertArrayHasKey('labels', $result); + $this->assertEquals([ + ['val' => 'v 1'], + ['val' => 'v 2'], + ['val' => 'v 3'], + ], $result['labels']); + } /** * @throws InvalidArgumentException @@ -226,6 +244,10 @@ public function testJsonSerialize() $sRef = new StrongRef('foo', 'bar'); $this->post->reply($sRef, clone $sRef); $this->post->langs(['en', 'fr', 'es']); + $this->post->labels(new SelfLabels([ + 'val 1', + 'val 2' + ])); $result = $this->post->jsonSerialize(); $this->assertArrayHasKey('$type', $result); @@ -236,6 +258,7 @@ public function testJsonSerialize() $this->assertArrayHasKey('embed', $result); $this->assertArrayHasKey('replyRef', $result); $this->assertArrayHasKey('langs', $result); + $this->assertArrayHasKey('labels', $result); } public function testConstructorWorksCorrectlyOnDirectBuild() From c2ef9b7813769cb7e6f020ded7901a184e9d9cba Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sun, 13 Oct 2024 22:30:16 +0400 Subject: [PATCH 24/58] Add tags support to PostBuilder API --- .../App/Bsky/Feed/PostBuilderContract.php | 2 + src/Lexicons/App/Bsky/Feed/Post.php | 35 +++++++++++++- .../Unit/Lexicons/App/Bsky/Feed/PostTest.php | 46 ++++++++++++++++--- 3 files changed, 76 insertions(+), 7 deletions(-) diff --git a/src/Contracts/Lexicons/App/Bsky/Feed/PostBuilderContract.php b/src/Contracts/Lexicons/App/Bsky/Feed/PostBuilderContract.php index 9058dc6..835447b 100644 --- a/src/Contracts/Lexicons/App/Bsky/Feed/PostBuilderContract.php +++ b/src/Contracts/Lexicons/App/Bsky/Feed/PostBuilderContract.php @@ -28,4 +28,6 @@ public function reply(StrongRef $root, StrongRef $parent): PostBuilderContract; public function langs(array $languages): PostBuilderContract; public function labels(SelfLabels $labels): PostBuilderContract; + + public function tags(array $tags): PostBuilderContract; } diff --git a/src/Lexicons/App/Bsky/Feed/Post.php b/src/Lexicons/App/Bsky/Feed/Post.php index b028d64..9737904 100644 --- a/src/Lexicons/App/Bsky/Feed/Post.php +++ b/src/Lexicons/App/Bsky/Feed/Post.php @@ -28,6 +28,7 @@ class Post implements PostBuilderContract private ?array $reply = null; private ?array $languages = null; private ?SelfLabels $labels = null; + private ?array $tags = null; public function __construct() @@ -130,6 +131,37 @@ public function labels(SelfLabels $labels): PostBuilderContract return $this; } + /** + * @throws InvalidArgumentException + */ + public function tags(array $tags): PostBuilderContract + { + $maxLength = 8; + $maxLengthByTag = 640; + + if (count($tags) > $maxLength) { + throw new InvalidArgumentException('A maximum of 8 tags is allowed.'); + } + + $invalid = array_filter($tags, function ($tag) { + if (mb_strlen($tag) > 640) { + return true; + } + }); + + if (! empty($invalid)) { + throw new InvalidArgumentException(sprintf( + "Invalid tags: %s. A tag maximum of %s characters is allowed.", + implode(', ', $invalid), + $maxLengthByTag + )); + } + + $this->tags = $tags; + + return $this; + } + /** * Validates the format of a language code. * @@ -175,7 +207,8 @@ public function jsonSerialize(): array 'embed' => $this->embed, 'replyRef' => $this->reply, 'langs' => $this->languages, - 'labels' => $this->labels + 'labels' => $this->labels, + 'tags' => $this->tags, ]); } diff --git a/tests/Unit/Lexicons/App/Bsky/Feed/PostTest.php b/tests/Unit/Lexicons/App/Bsky/Feed/PostTest.php index 8678a23..5e40030 100644 --- a/tests/Unit/Lexicons/App/Bsky/Feed/PostTest.php +++ b/tests/Unit/Lexicons/App/Bsky/Feed/PostTest.php @@ -232,6 +232,41 @@ public function testLabelsMethod(): void ], $result['labels']); } + public function testTagsThrowsExceptionWhenPassedTagExceedsAllowedLength(): void + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage("Invalid tags: "); + + $trigger = [str_pad('', 641, 'a')]; + $this->post->tags($trigger); + } + + public function testTagsMethodThrowsExceptionWhenPassedArrayExceedsAllowedLength(): void + { + $max = 8; + + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage("A maximum of $max tags is allowed."); + + $trigger = str_split(str_pad('', ++$max, 'a')); + + $this->post->tags($trigger); + } + + /** + * @throws InvalidArgumentException + */ + public function testTags(): void + { + $tags = [str_pad('', 640, 'a')]; + $this->post->tags($tags); + + $result = json_decode($this->post, true); + + $this->assertArrayHasKey('tags', $result); + $this->assertEquals($tags, $result['tags']); + } + /** * @throws InvalidArgumentException */ @@ -241,15 +276,13 @@ public function testJsonSerialize() $embed = $this->createMock(EmbedInterface::class); $embed->method('jsonSerialize')->willReturn(['embedKey' => 'embedValue']); $this->post->embed($embed); - $sRef = new StrongRef('foo', 'bar'); - $this->post->reply($sRef, clone $sRef); + $this->post->reply($sRef = new StrongRef('foo', 'bar'), clone $sRef); $this->post->langs(['en', 'fr', 'es']); - $this->post->labels(new SelfLabels([ - 'val 1', - 'val 2' - ])); + $this->post->labels(new SelfLabels(str_split(str_pad('', 2, 'val')))); + $this->post->tags(str_split(str_pad('', 2, 'tag'))); $result = $this->post->jsonSerialize(); + $this->assertArrayHasKey('$type', $result); $this->assertEquals('app.bsky.feed.post', $result['$type']); $this->assertArrayHasKey('text', $result); @@ -259,6 +292,7 @@ public function testJsonSerialize() $this->assertArrayHasKey('replyRef', $result); $this->assertArrayHasKey('langs', $result); $this->assertArrayHasKey('labels', $result); + $this->assertArrayHasKey('tags', $result); } public function testConstructorWorksCorrectlyOnDirectBuild() From 06487f5935416cd86feb35797e40d37609ac5eec Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sun, 13 Oct 2024 22:54:17 +0400 Subject: [PATCH 25/58] Fix PHPStan-reported issues --- src/Lexicons/Com/Atproto/Label/SelfLabels.php | 2 +- src/Resources/Assets/ProfilesAsset.php | 3 +-- src/Support/Media.php | 10 ---------- src/Traits/Authentication.php | 6 +++--- 4 files changed, 5 insertions(+), 16 deletions(-) delete mode 100644 src/Support/Media.php diff --git a/src/Lexicons/Com/Atproto/Label/SelfLabels.php b/src/Lexicons/Com/Atproto/Label/SelfLabels.php index f2a0fd0..60489a2 100644 --- a/src/Lexicons/Com/Atproto/Label/SelfLabels.php +++ b/src/Lexicons/Com/Atproto/Label/SelfLabels.php @@ -62,7 +62,7 @@ public function __toString(): string return json_encode($this); } - public function jsonSerialize() + public function jsonSerialize(): array { return $this->toArray(); } diff --git a/src/Resources/Assets/ProfilesAsset.php b/src/Resources/Assets/ProfilesAsset.php index d856d53..defb8c0 100644 --- a/src/Resources/Assets/ProfilesAsset.php +++ b/src/Resources/Assets/ProfilesAsset.php @@ -2,9 +2,8 @@ namespace Atproto\Resources\Assets; +use Atproto\Collections\Types\NonPrimitive\ProfileAssetType; use Atproto\Contracts\HTTP\Resources\AssetContract; -use Atproto\GenericCollection\Types\NonPrimitive\FollowerAssetType; -use Atproto\GenericCollection\Types\NonPrimitive\ProfileAssetType; use GenericCollection\Exceptions\InvalidArgumentException; use GenericCollection\GenericCollection; use GenericCollection\Interfaces\TypeInterface; diff --git a/src/Support/Media.php b/src/Support/Media.php deleted file mode 100644 index 066e3d6..0000000 --- a/src/Support/Media.php +++ /dev/null @@ -1,10 +0,0 @@ -authenticated; } - public function attach(SplObserver $observer) + public function attach(SplObserver $observer): void { $this->observers->attach($observer); } - public function detach(SplObserver $observer) + public function detach(SplObserver $observer): void { $this->observers->detach($observer); } - public function notify() + public function notify(): void { foreach ($this->observers as $observer) { $observer->update($this); From 72a3b054aee73bf2d442046301c7dd9476416c2b Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Fri, 18 Oct 2024 19:00:58 +0400 Subject: [PATCH 26/58] Keep lexicons in one place --- src/{HTTP/API => Lexicons}/APIRequest.php | 3 +-- .../Requests => Lexicons}/App/Bsky/Actor/GetProfile.php | 7 +++---- .../Requests => Lexicons}/App/Bsky/Actor/GetProfiles.php | 6 +++--- .../Requests => Lexicons}/App/Bsky/Graph/GetFollowers.php | 8 ++++---- .../Com/Atproto/Repo/CreateRecord.php | 4 ++-- .../Requests => Lexicons}/Com/Atproto/Repo/UploadBlob.php | 4 ++-- .../Com/Atproto/Server/CreateSession.php | 4 ++-- src/{HTTP => Lexicons}/Request.php | 6 +++--- src/{HTTP => Lexicons}/Traits/Authentication.php | 4 ++-- src/{HTTP => Lexicons}/Traits/RequestBuilder.php | 2 +- src/{HTTP => Lexicons}/Traits/RequestHandler.php | 2 +- src/Traits/Smith.php | 2 +- .../HTTP/API/Requests/App/Bsky/Actor/GetProfilesTest.php | 2 +- tests/Unit/ClientTest.php | 8 ++++---- tests/Unit/HTTP/API/APIRequestTest.php | 6 +++--- .../HTTP/API/Requests/App/Bsky/Actor/GetProfileTest.php | 6 +++--- .../HTTP/API/Requests/App/Bsky/Actor/GetProfilesTest.php | 2 +- .../HTTP/API/Requests/App/Bsky/Graph/GetFollowersTest.php | 2 +- .../API/Requests/Com/Atproto/Repo/CreateRecordTest.php | 2 +- .../HTTP/API/Requests/Com/Atproto/Repo/UploadBlobTest.php | 2 +- tests/Unit/HTTP/RequestTest.php | 2 +- 21 files changed, 41 insertions(+), 43 deletions(-) rename src/{HTTP/API => Lexicons}/APIRequest.php (95%) rename src/{HTTP/API/Requests => Lexicons}/App/Bsky/Actor/GetProfile.php (90%) rename src/{HTTP/API/Requests => Lexicons}/App/Bsky/Actor/GetProfiles.php (93%) rename src/{HTTP/API/Requests => Lexicons}/App/Bsky/Graph/GetFollowers.php (93%) rename src/{HTTP/API/Requests => Lexicons}/Com/Atproto/Repo/CreateRecord.php (96%) rename src/{HTTP/API/Requests => Lexicons}/Com/Atproto/Repo/UploadBlob.php (93%) rename src/{HTTP/API/Requests => Lexicons}/Com/Atproto/Server/CreateSession.php (89%) rename src/{HTTP => Lexicons}/Request.php (54%) rename src/{HTTP => Lexicons}/Traits/Authentication.php (92%) rename src/{HTTP => Lexicons}/Traits/RequestBuilder.php (98%) rename src/{HTTP => Lexicons}/Traits/RequestHandler.php (98%) diff --git a/src/HTTP/API/APIRequest.php b/src/Lexicons/APIRequest.php similarity index 95% rename from src/HTTP/API/APIRequest.php rename to src/Lexicons/APIRequest.php index aba1b35..6a91b38 100644 --- a/src/HTTP/API/APIRequest.php +++ b/src/Lexicons/APIRequest.php @@ -1,11 +1,10 @@ invoke($this->client); - $expectedNamespace = 'Atproto\\HTTP\\API\\Requests\\App\\Bsky\\Actor'; + $expectedNamespace = 'Atproto\\Lexicons\\App\\Bsky\\Actor'; $this->assertSame($expectedNamespace, $namespace); } @@ -57,7 +57,7 @@ public function testForgeThrowsRequestNotFoundException(): void $this->client->nonExistentMethod(); $this->expectException(RequestNotFoundException::class); - $this->expectExceptionMessage("Atproto\\HTTP\\API\\Requests\\NonExistentMethod class does not exist."); + $this->expectExceptionMessage("Atproto\\Lexicons\\NonExistentMethod class does not exist."); $this->client->forge(); } diff --git a/tests/Unit/HTTP/API/APIRequestTest.php b/tests/Unit/HTTP/API/APIRequestTest.php index f92ef04..6674eee 100644 --- a/tests/Unit/HTTP/API/APIRequestTest.php +++ b/tests/Unit/HTTP/API/APIRequestTest.php @@ -3,8 +3,8 @@ namespace Tests\Unit\HTTP\API; use Atproto\Client; -use Atproto\HTTP\API\APIRequest; -use Atproto\HTTP\API\Requests\Com\Atproto\Server\CreateSession; +use Atproto\Lexicons\APIRequest; +use Atproto\Lexicons\Com\Atproto\Server\CreateSession; use Faker\Factory; use PHPUnit\Framework\TestCase; use Tests\Supports\Reflection; @@ -23,7 +23,7 @@ public function setUp(): void $clientMock = $this->createMock(Client::class); $clientMock->method('path')->willReturn(str_replace( - 'Atproto\\HTTP\\API\\Requests\\', + 'Atproto\\Lexicons\\', '', CreateSession::class )); diff --git a/tests/Unit/HTTP/API/Requests/App/Bsky/Actor/GetProfileTest.php b/tests/Unit/HTTP/API/Requests/App/Bsky/Actor/GetProfileTest.php index 9bbce9a..3f4ed5b 100644 --- a/tests/Unit/HTTP/API/Requests/App/Bsky/Actor/GetProfileTest.php +++ b/tests/Unit/HTTP/API/Requests/App/Bsky/Actor/GetProfileTest.php @@ -6,9 +6,9 @@ use Atproto\Contracts\HTTP\APIRequestContract; use Atproto\Contracts\RequestContract; use Atproto\Exceptions\Http\MissingFieldProvidedException; -use Atproto\HTTP\API\APIRequest; -use Atproto\HTTP\API\Requests\App\Bsky\Actor\GetProfile; -use Atproto\HTTP\Request; +use Atproto\Lexicons\APIRequest; +use Atproto\Lexicons\App\Bsky\Actor\GetProfile; +use Atproto\Lexicons\Request; use Faker\Factory; use Faker\Generator; use PHPUnit\Framework\TestCase; diff --git a/tests/Unit/HTTP/API/Requests/App/Bsky/Actor/GetProfilesTest.php b/tests/Unit/HTTP/API/Requests/App/Bsky/Actor/GetProfilesTest.php index 6bc3a4e..5e5e909 100644 --- a/tests/Unit/HTTP/API/Requests/App/Bsky/Actor/GetProfilesTest.php +++ b/tests/Unit/HTTP/API/Requests/App/Bsky/Actor/GetProfilesTest.php @@ -6,7 +6,7 @@ use Atproto\Exceptions\Auth\AuthRequired; use Atproto\Exceptions\Http\MissingFieldProvidedException; use Atproto\Exceptions\InvalidArgumentException; -use Atproto\HTTP\API\Requests\App\Bsky\Actor\GetProfiles; +use Atproto\Lexicons\App\Bsky\Actor\GetProfiles; use Atproto\Resources\App\Bsky\Actor\GetProfilesResource; use GenericCollection\GenericCollection; use GenericCollection\Types\Primitive\StringType; diff --git a/tests/Unit/HTTP/API/Requests/App/Bsky/Graph/GetFollowersTest.php b/tests/Unit/HTTP/API/Requests/App/Bsky/Graph/GetFollowersTest.php index 508bf92..a12c961 100644 --- a/tests/Unit/HTTP/API/Requests/App/Bsky/Graph/GetFollowersTest.php +++ b/tests/Unit/HTTP/API/Requests/App/Bsky/Graph/GetFollowersTest.php @@ -7,7 +7,7 @@ use Atproto\Exceptions\Http\MissingFieldProvidedException; use Atproto\Exceptions\Http\Response\AuthMissingException; use Atproto\Exceptions\InvalidArgumentException; -use Atproto\HTTP\API\Requests\App\Bsky\Graph\GetFollowers; +use Atproto\Lexicons\App\Bsky\Graph\GetFollowers; use PHPUnit\Framework\TestCase; class GetFollowersTest extends TestCase diff --git a/tests/Unit/HTTP/API/Requests/Com/Atproto/Repo/CreateRecordTest.php b/tests/Unit/HTTP/API/Requests/Com/Atproto/Repo/CreateRecordTest.php index 64cd712..8a1da0c 100644 --- a/tests/Unit/HTTP/API/Requests/Com/Atproto/Repo/CreateRecordTest.php +++ b/tests/Unit/HTTP/API/Requests/Com/Atproto/Repo/CreateRecordTest.php @@ -4,7 +4,7 @@ use Atproto\Client; use Atproto\Exceptions\Http\MissingFieldProvidedException; -use Atproto\HTTP\API\Requests\Com\Atproto\Repo\CreateRecord; +use Atproto\Lexicons\Com\Atproto\Repo\CreateRecord; use Faker\Factory; use Faker\Generator; use PHPUnit\Framework\TestCase; diff --git a/tests/Unit/HTTP/API/Requests/Com/Atproto/Repo/UploadBlobTest.php b/tests/Unit/HTTP/API/Requests/Com/Atproto/Repo/UploadBlobTest.php index 99adb56..f7eef05 100644 --- a/tests/Unit/HTTP/API/Requests/Com/Atproto/Repo/UploadBlobTest.php +++ b/tests/Unit/HTTP/API/Requests/Com/Atproto/Repo/UploadBlobTest.php @@ -4,7 +4,7 @@ use Atproto\Client; use Atproto\Exceptions\Http\MissingFieldProvidedException; -use Atproto\HTTP\API\Requests\Com\Atproto\Repo\UploadBlob; +use Atproto\Lexicons\Com\Atproto\Repo\UploadBlob; use Faker\Factory; use Faker\Generator; use PHPUnit\Framework\TestCase; diff --git a/tests/Unit/HTTP/RequestTest.php b/tests/Unit/HTTP/RequestTest.php index 542d07f..a734373 100644 --- a/tests/Unit/HTTP/RequestTest.php +++ b/tests/Unit/HTTP/RequestTest.php @@ -4,7 +4,7 @@ use ArgumentCountError; use Atproto\Contracts\RequestContract; -use Atproto\HTTP\Request; +use Atproto\Lexicons\Request; use Faker\Factory; use Faker\Generator; use PHPUnit\Framework\TestCase; From 7532e687d20186d305c13e084189d6cefff4bf39 Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Fri, 18 Oct 2024 19:25:10 +0400 Subject: [PATCH 27/58] Add a feature test for record creation --- src/Contracts/LexiconContract.php | 7 +++ .../Com/Atproto/Repo/CreateRecord.php | 19 ++++++- src/Traits/Smith.php | 7 ++- .../Com/Atproto/Repo/CreateRecordTest.php | 55 +++++++++++++++++++ 4 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 src/Contracts/LexiconContract.php create mode 100644 tests/Feature/Lexicons/Com/Atproto/Repo/CreateRecordTest.php diff --git a/src/Contracts/LexiconContract.php b/src/Contracts/LexiconContract.php new file mode 100644 index 0000000..00fa28f --- /dev/null +++ b/src/Contracts/LexiconContract.php @@ -0,0 +1,7 @@ + $this->repo(), + 'collection' => $this->collection(), + 'record' => $this->record(), + 'swapCommit' => $this->swapCommit(), + 'validate' => $this->validate(), + ]); + } } diff --git a/src/Traits/Smith.php b/src/Traits/Smith.php index b458f32..21ebde5 100644 --- a/src/Traits/Smith.php +++ b/src/Traits/Smith.php @@ -23,7 +23,7 @@ public function __call(string $name, array $arguments): Client /** * @throws RequestNotFoundException */ - public function forge(...$arguments): RequestContract + public function forge(...$arguments) { $arguments = array_merge([$this], array_values($arguments)); @@ -36,7 +36,10 @@ public function forge(...$arguments): RequestContract /** @var APIRequestContract $request */ $request = new $request(...$arguments); - $this->attach($request); + if ($request instanceof \SplObserver) { + $this->attach($request); + } + $this->refresh(); return $request; diff --git a/tests/Feature/Lexicons/Com/Atproto/Repo/CreateRecordTest.php b/tests/Feature/Lexicons/Com/Atproto/Repo/CreateRecordTest.php new file mode 100644 index 0000000..2311698 --- /dev/null +++ b/tests/Feature/Lexicons/Com/Atproto/Repo/CreateRecordTest.php @@ -0,0 +1,55 @@ +authenticate( + getenv('BLUESKY_IDENTIFIER'), + getenv('BLUESKY_PASSWORD') + ); + } + + /** + * @throws InvalidArgumentException + */ + public function testBuildCreateRecordRequestWithPost(): void + { + $client = static::$client; + + $post = $client->app()->bsky()->feed()->post()->forge()->text( + "Hello World! ", + "This post was sent from a feature test of the BlueSky PHP SDK ", + ); + + $this->assertInstanceOf(PostBuilderContract::class, $post); + + $createRecord = $client->com()->atproto()->repo()->createRecord()->forge()->record($post); + + $this->assertInstanceOf(CreateRecord::class, $createRecord); + + $serializedPost = json_decode($post, true); + $actualPost = Arr::get(json_decode($createRecord, true), 'record'); + + $this->assertSame($serializedPost, $actualPost); + + $response = $client->send(); + + $this->assertIsString($response->uri()); + + echo $response->uri(); + } +} From 68c12ed27671cb55a6fafcef2be3fafd1ed84af4 Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sun, 27 Oct 2024 01:19:16 +0400 Subject: [PATCH 28/58] refactor: standardize naming conventions and imports - Rename interfaces to Contract suffix - Rename support classes for clarity - Clean up test dependencies and imports - Update composer dependencies --- composer.json | 3 ++- .../{CaptionInterface.php => CaptionContract.php} | 4 ++-- .../{MediaInterface.php => MediaContract.php} | 5 ++--- src/Support/{File.php => FileSupport.php} | 7 ++++++- .../Bsky/Embed/{FileMocking.php => FileMock.php} | 15 +++------------ 5 files changed, 15 insertions(+), 19 deletions(-) rename src/Contracts/Lexicons/App/Bsky/Embed/{CaptionInterface.php => CaptionContract.php} (66%) rename src/Contracts/Lexicons/App/Bsky/Embed/{MediaInterface.php => MediaContract.php} (70%) rename src/Support/{File.php => FileSupport.php} (96%) rename tests/Unit/Lexicons/App/Bsky/Embed/{FileMocking.php => FileMock.php} (63%) diff --git a/composer.json b/composer.json index 1223b0b..8abe24a 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,8 @@ "require-dev": { "phpunit/phpunit": "9.6.20", "fakerphp/faker": "^1.23", - "phpstan/phpstan": "^1.12" + "phpstan/phpstan": "^1.12", + "ext-posix": "*" }, "require": { "ext-json": "*", diff --git a/src/Contracts/Lexicons/App/Bsky/Embed/CaptionInterface.php b/src/Contracts/Lexicons/App/Bsky/Embed/CaptionContract.php similarity index 66% rename from src/Contracts/Lexicons/App/Bsky/Embed/CaptionInterface.php rename to src/Contracts/Lexicons/App/Bsky/Embed/CaptionContract.php index ed45198..27e806a 100644 --- a/src/Contracts/Lexicons/App/Bsky/Embed/CaptionInterface.php +++ b/src/Contracts/Lexicons/App/Bsky/Embed/CaptionContract.php @@ -3,10 +3,10 @@ namespace Atproto\Contracts\Lexicons\App\Bsky\Embed; use Atproto\Contracts\Stringable; -use Atproto\Lexicons\App\Bsky\Embed\Blob; +use Atproto\DataModel\Blob\Blob; use JsonSerializable; -interface CaptionInterface extends JsonSerializable, Stringable +interface CaptionContract extends JsonSerializable, Stringable { public function lang(string $lang = null); public function file(Blob $file = null); diff --git a/src/Contracts/Lexicons/App/Bsky/Embed/MediaInterface.php b/src/Contracts/Lexicons/App/Bsky/Embed/MediaContract.php similarity index 70% rename from src/Contracts/Lexicons/App/Bsky/Embed/MediaInterface.php rename to src/Contracts/Lexicons/App/Bsky/Embed/MediaContract.php index 6fd2101..98496b9 100644 --- a/src/Contracts/Lexicons/App/Bsky/Embed/MediaInterface.php +++ b/src/Contracts/Lexicons/App/Bsky/Embed/MediaContract.php @@ -2,7 +2,6 @@ namespace Atproto\Contracts\Lexicons\App\Bsky\Embed; -interface MediaInterface +interface MediaContract { - -} \ No newline at end of file +} diff --git a/src/Support/File.php b/src/Support/FileSupport.php similarity index 96% rename from src/Support/File.php rename to src/Support/FileSupport.php index 641b6d7..c0bfff3 100644 --- a/src/Support/File.php +++ b/src/Support/FileSupport.php @@ -7,7 +7,7 @@ * * Helper class for file-related operations. */ -class File +class FileSupport { /** @var string $file_path The path to the file. */ private string $file_path; @@ -94,6 +94,11 @@ public function isFile() return is_file($this->file_path); } + public function isReadable(): bool + { + return is_readable($this->file_path); + } + /** * Check if the path is a directory. * diff --git a/tests/Unit/Lexicons/App/Bsky/Embed/FileMocking.php b/tests/Unit/Lexicons/App/Bsky/Embed/FileMock.php similarity index 63% rename from tests/Unit/Lexicons/App/Bsky/Embed/FileMocking.php rename to tests/Unit/Lexicons/App/Bsky/Embed/FileMock.php index b1ba4cf..850d87f 100644 --- a/tests/Unit/Lexicons/App/Bsky/Embed/FileMocking.php +++ b/tests/Unit/Lexicons/App/Bsky/Embed/FileMock.php @@ -2,14 +2,13 @@ namespace Tests\Unit\Lexicons\App\Bsky\Embed; -use Atproto\Lexicons\App\Bsky\Embed\Blob; +use Atproto\DataModel\Blob\Blob; use PHPUnit\Framework\MockObject\MockObject; -trait FileMocking +trait FileMock { private int $size = 2000; private string $path = 'path'; - private string $blob = 'blob'; private string $type = 'text/vtt'; /** @@ -22,21 +21,13 @@ private function createMockFile() ->getMock(); $file->expects($this->any()) - ->method('path') - ->will($this->returnCallback(fn () => $this->path)); - - $file->expects($this->any()) - ->method('type') + ->method('mimeType') ->will($this->returnCallback(fn () => $this->type)); $file->expects($this->any()) ->method('size') ->will($this->returnCallback(fn () => $this->size)); - $file->expects($this->any()) - ->method('blob') - ->will($this->returnCallback(fn () => $this->blob)); - return $file; } } From 872ee32b72eb6164955b9c4ebf55ab8dc8e94dc5 Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sun, 27 Oct 2024 01:20:47 +0400 Subject: [PATCH 29/58] feat: implement IPFS content identifier system - Add CID (Content Identifier) implementation - Add MultiCodec and MultiHash support - Add enum support for type safe constants --- src/IPFS/CID/CID.php | 58 +++++++++++++++++++++++++++++++++ src/IPFS/CID/CIDVersion.php | 15 +++++++++ src/IPFS/CID/Versions/CIDV1.php | 44 +++++++++++++++++++++++++ src/MultiFormats/MultiCodec.php | 17 ++++++++++ src/MultiFormats/MultiHash.php | 26 +++++++++++++++ src/Support/Enum.php | 47 ++++++++++++++++++++++++++ 6 files changed, 207 insertions(+) create mode 100644 src/IPFS/CID/CID.php create mode 100644 src/IPFS/CID/CIDVersion.php create mode 100644 src/IPFS/CID/Versions/CIDV1.php create mode 100644 src/MultiFormats/MultiCodec.php create mode 100644 src/MultiFormats/MultiHash.php create mode 100644 src/Support/Enum.php diff --git a/src/IPFS/CID/CID.php b/src/IPFS/CID/CID.php new file mode 100644 index 0000000..398223e --- /dev/null +++ b/src/IPFS/CID/CID.php @@ -0,0 +1,58 @@ +encoder = $encoderMultiBase->value; + $this->typeMultiCodec = $typeMultiCodec; + $this->target = $target; + $this->version = new CIDV1(); + $this->version->setCid($this); + } + + public function target(): string + { + return $this->target; + } + + public function typeMultiCodec(): MultiCodec + { + return $this->typeMultiCodec; + } + + public function version(CIDVersion $version = null) + { + if (is_null($version)) { + return $this->version; + } + + $this->version = $version; + $this->version->setCid($this); + + return $this; + } + + public function generate(): string + { + return $this->version->generate(); + } + + public function __toString(): string + { + return $this->encoder->encode($this->generate()); + } +} diff --git a/src/IPFS/CID/CIDVersion.php b/src/IPFS/CID/CIDVersion.php new file mode 100644 index 0000000..194842c --- /dev/null +++ b/src/IPFS/CID/CIDVersion.php @@ -0,0 +1,15 @@ +cid = $cid; + } + + abstract public function generate(): string; +} diff --git a/src/IPFS/CID/Versions/CIDV1.php b/src/IPFS/CID/Versions/CIDV1.php new file mode 100644 index 0000000..ff11db5 --- /dev/null +++ b/src/IPFS/CID/Versions/CIDV1.php @@ -0,0 +1,44 @@ +versionMultiCodecBin(); + $type = $this->typeMultiCodecBin(); + $contentMultiHash = $this->contentMultiHash(); + + return sprintf( + "%s%s%s", + $version, + $type, + $contentMultiHash + ); + } + + private function versionMultiCodecBin(): string + { + return hex2bin($this->versionMultiCodec()->value); + } + + private function typeMultiCodecBin(): string + { + return hex2bin($this->cid->typeMultiCodec()->value); + } + + private function contentMultiHash(): string + { + return MultiHash::generate('sha2-256', $this->cid->target()); + } + + private function versionMultiCodec(): MultiCodec + { + return MultiCodec::get('cidv1'); + } +} diff --git a/src/MultiFormats/MultiCodec.php b/src/MultiFormats/MultiCodec.php new file mode 100644 index 0000000..ae68c02 --- /dev/null +++ b/src/MultiFormats/MultiCodec.php @@ -0,0 +1,17 @@ + '01', + 'sha2-256' => '12', + 'raw' => '55', + ]; +} diff --git a/src/MultiFormats/MultiHash.php b/src/MultiFormats/MultiHash.php new file mode 100644 index 0000000..1fd68be --- /dev/null +++ b/src/MultiFormats/MultiHash.php @@ -0,0 +1,26 @@ + 'sha256', + ]; + + public static function generate(string $hashMulticodecName, string $content): string + { + $hash = hash( + self::MULTICODEC_NAME__HASH_ALGO[MultiCodec::get($hashMulticodecName)->name], + $content, + true + ); + + return sprintf( + "%s%s%s", + encode_varint(intval(MultiCodec::get($hashMulticodecName)->value, 16)), + encode_varint(strlen($hash)), + $hash + ); + } +} diff --git a/src/Support/Enum.php b/src/Support/Enum.php new file mode 100644 index 0000000..d9deec1 --- /dev/null +++ b/src/Support/Enum.php @@ -0,0 +1,47 @@ +name = $name; + $this->value = $value; + } + + private static function instance($name, $value): self + { + $static = static::class; + $instance = null; + + eval("\$instance = new class(\$name, \$value) extends $static {};"); + + return $instance; + } + + /** + * @throws InvalidArgumentException + */ + public static function get(string $name): self + { + self::validate($name); + + return self::instance($name, self::CONSTANTS[$name]); + } + + /** + * @throws InvalidArgumentException + */ + private static function validate(string $name): void + { + if (! isset(self::CONSTANTS[$name])) { + throw new InvalidArgumentException("'$name' is not implemented"); + } + } +} From 885ab9f52775ad1239fb04872df13acc92f09c6b Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sun, 27 Oct 2024 01:21:36 +0400 Subject: [PATCH 30/58] feat: add base32 encoding system - Implement base32 encoding/decoding - Add encoder contract and support traits - Update helper functions --- src/Contracts/EncoderContract.php | 10 +++ .../MultiBase/Encoders/Base32Encoder.php | 65 +++++++++++++++++++ .../MultiBase/Encoders/MultiBaseSupport.php | 22 +++++++ src/MultiFormats/MultiBase/MultiBase.php | 29 +++++++++ src/helpers.php | 21 ------ 5 files changed, 126 insertions(+), 21 deletions(-) create mode 100644 src/Contracts/EncoderContract.php create mode 100644 src/MultiFormats/MultiBase/Encoders/Base32Encoder.php create mode 100644 src/MultiFormats/MultiBase/Encoders/MultiBaseSupport.php create mode 100644 src/MultiFormats/MultiBase/MultiBase.php diff --git a/src/Contracts/EncoderContract.php b/src/Contracts/EncoderContract.php new file mode 100644 index 0000000..8a78003 --- /dev/null +++ b/src/Contracts/EncoderContract.php @@ -0,0 +1,10 @@ +prefixed($encoded); + } + + /** + * @throws InvalidArgumentException + */ + public function decode($data): string + { + $data = $this->unprefixed($data); + + $alphabet = 'abcdefghijklmnopqrstuvwxyz234567'; + $binaryString = ''; + $decoded = ''; + + $data = rtrim($data, '='); + + foreach (str_split($data) as $char) { + $position = strpos($alphabet, $char); + if ($position === false) { + throw new InvalidArgumentException("Invalid character found in Base32 string."); + } + $binaryString .= str_pad(decbin($position), 5, '0', STR_PAD_LEFT); + } + + $chunks = str_split($binaryString, 8); + foreach ($chunks as $chunk) { + if (strlen($chunk) === 8) { + $decoded .= chr(bindec($chunk)); + } + } + + return $decoded; + } + + public function prefix(): string + { + return 'b'; + } +} diff --git a/src/MultiFormats/MultiBase/Encoders/MultiBaseSupport.php b/src/MultiFormats/MultiBase/Encoders/MultiBaseSupport.php new file mode 100644 index 0000000..c61b2a9 --- /dev/null +++ b/src/MultiFormats/MultiBase/Encoders/MultiBaseSupport.php @@ -0,0 +1,22 @@ +prefix())) { + $offset = $pos + strlen($this->prefix()); + + return substr($data, $offset); + } + + return $data; + } + + private function prefixed(string $data): string + { + return $this->prefix() . $data; + } +} diff --git a/src/MultiFormats/MultiBase/MultiBase.php b/src/MultiFormats/MultiBase/MultiBase.php new file mode 100644 index 0000000..41f6ef8 --- /dev/null +++ b/src/MultiFormats/MultiBase/MultiBase.php @@ -0,0 +1,29 @@ + Base32Encoder::class, + ]; + + public static function get(string $name) + { + self::validate($name); + + $encoder = self::CONSTANTS[$name]; + $instance = new $encoder(); + + return self::instance($name, $instance); + } +} diff --git a/src/helpers.php b/src/helpers.php index d20aadd..21fec38 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -57,24 +57,3 @@ function encode_varint(int $int): string return $encoded; } } - -if (! function_exists('decode_varint')) { - function decode_varint(string $data): int - { - $number = 0; - $shift = 0; - - foreach (str_split($data) as $char) { - $byte = ord($char); - $number |= ($byte & 0x7F) << $shift; - - if (($byte & 0x80) === 0) { - break; - } - - $shift += 7; - } - - return $number; - } -} From 7c8a0dbf09957287070fb40686f79fe8e6b74efc Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sun, 27 Oct 2024 01:22:27 +0400 Subject: [PATCH 31/58] refactor blob implemention by atproto specification - Add blob contracts and handlers - Implement binary and file handlers - Revert old blob implemention --- src/Contracts/DataModel/BlobContract.php | 16 ++++++ src/Contracts/DataModel/BlobHandler.php | 10 ++++ src/DataModel/Blob/BinaryBlobHandler.php | 44 +++++++++++++++ src/DataModel/Blob/Blob.php | 68 ++++++++++++++++++++++++ src/DataModel/Blob/FileBlobHandler.php | 44 +++++++++++++++ 5 files changed, 182 insertions(+) create mode 100644 src/Contracts/DataModel/BlobContract.php create mode 100644 src/Contracts/DataModel/BlobHandler.php create mode 100644 src/DataModel/Blob/BinaryBlobHandler.php create mode 100644 src/DataModel/Blob/Blob.php create mode 100644 src/DataModel/Blob/FileBlobHandler.php diff --git a/src/Contracts/DataModel/BlobContract.php b/src/Contracts/DataModel/BlobContract.php new file mode 100644 index 0000000..e0f9afe --- /dev/null +++ b/src/Contracts/DataModel/BlobContract.php @@ -0,0 +1,16 @@ +isBinary($binary)) { + throw new InvalidArgumentException('$binary must be a binary'); + } + + $this->binary = $binary; + } + + private function isBinary(string $binary): bool + { + return ! mb_check_encoding($binary, 'UTF-8'); + } + + public function size(): int + { + return strlen($this->binary); + } + + public function mimeType(): string + { + return (new finfo(FILEINFO_MIME_TYPE))->buffer($this->binary); + } + + public function content(): string + { + return $this->binary; + } +} diff --git a/src/DataModel/Blob/Blob.php b/src/DataModel/Blob/Blob.php new file mode 100644 index 0000000..26fca09 --- /dev/null +++ b/src/DataModel/Blob/Blob.php @@ -0,0 +1,68 @@ +handler = $handler; + $this->cid = new CID( + MultiCodec::get('raw'), + MultiBase::get('base32'), + $handler->content() + ); + } + + public static function viaBinary(string $binary): BlobContract + { + return new self(new BinaryBlobHandler($binary)); + } + + public static function viaFile(FileSupport $file): BlobContract + { + return new self(new FileBlobHandler($file)); + } + + public function size(): int + { + return $this->handler->size(); + } + + public function mimeType(): string + { + return $this->handler->mimeType(); + } + + public function __toString(): string + { + return json_encode($this); + } + + public function link(): string + { + return $this->cid->__toString(); + } + + public function jsonSerialize(): array + { + return [ + '$type' => 'blob', + 'ref' => [ + '$link' => $this->link() + ], + 'mimeType' => $this->mimeType(), + 'size' => $this->size(), + ]; + } +} diff --git a/src/DataModel/Blob/FileBlobHandler.php b/src/DataModel/Blob/FileBlobHandler.php new file mode 100644 index 0000000..da04d2d --- /dev/null +++ b/src/DataModel/Blob/FileBlobHandler.php @@ -0,0 +1,44 @@ +exists()) { + throw new InvalidArgumentException('$file is not exists'); + } + + if (! $file->isFile()) { + throw new InvalidArgumentException('$file is not a file'); + } + + if (! $file->isReadable()) { + throw new InvalidArgumentException('$file is not readable'); + } + + $this->file = $file; + } + + public function size(): int + { + return $this->file->getFileSize(); + } + + public function mimeType(): string + { + return $this->file->getMimeType(); + } + + public function content(): string + { + return $this->file->getBlob(); + } +} From de63116a2149da88269a4d5f9ee9c8e3f8e75ab2 Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sun, 27 Oct 2024 01:25:39 +0400 Subject: [PATCH 32/58] refactor: update embed system for new blob implementation - Migrate to new blob system - Improve error messages - Fix type hints and serialization --- src/Lexicons/App/Bsky/Embed/Blob.php | 35 ------------------- src/Lexicons/App/Bsky/Embed/Caption.php | 14 ++++---- .../Embed/Collections/CaptionCollection.php | 4 +-- .../Embed/Collections/ImageCollection.php | 4 +-- src/Lexicons/App/Bsky/Embed/External.php | 17 +++++---- src/Lexicons/App/Bsky/Embed/Image.php | 5 +-- .../App/Bsky/Embed/RecordWithMedia.php | 8 ++--- src/Lexicons/App/Bsky/Embed/Video.php | 9 ++--- 8 files changed, 31 insertions(+), 65 deletions(-) delete mode 100644 src/Lexicons/App/Bsky/Embed/Blob.php diff --git a/src/Lexicons/App/Bsky/Embed/Blob.php b/src/Lexicons/App/Bsky/Embed/Blob.php deleted file mode 100644 index d6c4421..0000000 --- a/src/Lexicons/App/Bsky/Embed/Blob.php +++ /dev/null @@ -1,35 +0,0 @@ -path); - } - - public function type(): string - { - return mime_content_type($this->path); - } - - public function blob(): string - { - return file_get_contents($this->path); - } - - public function path(): string - { - return $this->path; - } - - public function __toString(): string - { - return $this->blob(); - } -} diff --git a/src/Lexicons/App/Bsky/Embed/Caption.php b/src/Lexicons/App/Bsky/Embed/Caption.php index 816ab91..b67fc19 100644 --- a/src/Lexicons/App/Bsky/Embed/Caption.php +++ b/src/Lexicons/App/Bsky/Embed/Caption.php @@ -2,11 +2,11 @@ namespace Atproto\Lexicons\App\Bsky\Embed; -use Atproto\Contracts\Lexicons\App\Bsky\Embed\CaptionInterface; +use Atproto\Contracts\Lexicons\App\Bsky\Embed\CaptionContract; +use Atproto\DataModel\Blob\Blob; use Atproto\Exceptions\InvalidArgumentException; -use JsonSerializable; -class Caption implements CaptionInterface +class Caption implements CaptionContract { private const MAX_SIZE = 20000; @@ -43,11 +43,11 @@ public function file(Blob $file = null) } if ($file->size() > self::MAX_SIZE) { - throw new InvalidArgumentException($file->path().' is too large. Max size: '.self::MAX_SIZE); + throw new InvalidArgumentException('$file is too large. Max size: '.self::MAX_SIZE); } - if ($file->type() !== 'text/vtt') { - throw new InvalidArgumentException($file->path().' is not a text/vtt file.'); + if ($file->mimeType() !== 'text/vtt') { + throw new InvalidArgumentException('$file is not a text/vtt file.'); } $this->file = $file; @@ -62,7 +62,7 @@ public function jsonSerialize(): array { return [ 'lang' => $this->lang(), - 'file' => $this->file()->blob(), + 'file' => $this->file(), ]; } diff --git a/src/Lexicons/App/Bsky/Embed/Collections/CaptionCollection.php b/src/Lexicons/App/Bsky/Embed/Collections/CaptionCollection.php index 6c22ad9..68487a5 100644 --- a/src/Lexicons/App/Bsky/Embed/Collections/CaptionCollection.php +++ b/src/Lexicons/App/Bsky/Embed/Collections/CaptionCollection.php @@ -2,7 +2,7 @@ namespace Atproto\Lexicons\App\Bsky\Embed\Collections; -use Atproto\Contracts\Lexicons\App\Bsky\Embed\CaptionInterface; +use Atproto\Contracts\Lexicons\App\Bsky\Embed\CaptionContract; use Atproto\Exceptions\InvalidArgumentException; use GenericCollection\GenericCollection; use JsonSerializable; @@ -14,7 +14,7 @@ class CaptionCollection extends GenericCollection implements JsonSerializable protected function validator(): \Closure { - return function (CaptionInterface $caption) { + return function (CaptionContract $caption) { if ($this->count() > self::MAX_SIZE) { throw new InvalidArgumentException(self::class.' collection exceeds maximum size: ' .self::MAX_SIZE); } diff --git a/src/Lexicons/App/Bsky/Embed/Collections/ImageCollection.php b/src/Lexicons/App/Bsky/Embed/Collections/ImageCollection.php index 57c641e..c55fdd3 100644 --- a/src/Lexicons/App/Bsky/Embed/Collections/ImageCollection.php +++ b/src/Lexicons/App/Bsky/Embed/Collections/ImageCollection.php @@ -4,11 +4,11 @@ use Atproto\Contracts\Lexicons\App\Bsky\Embed\EmbedInterface; use Atproto\Contracts\Lexicons\App\Bsky\Embed\ImageInterface; -use Atproto\Contracts\Lexicons\App\Bsky\Embed\MediaInterface; +use Atproto\Contracts\Lexicons\App\Bsky\Embed\MediaContract; use GenericCollection\Exceptions\InvalidArgumentException; use GenericCollection\GenericCollection; -class ImageCollection extends GenericCollection implements EmbedInterface, MediaInterface +class ImageCollection extends GenericCollection implements EmbedInterface, MediaContract { use EmbedCollection; diff --git a/src/Lexicons/App/Bsky/Embed/External.php b/src/Lexicons/App/Bsky/Embed/External.php index 8c380ed..2272f8c 100644 --- a/src/Lexicons/App/Bsky/Embed/External.php +++ b/src/Lexicons/App/Bsky/Embed/External.php @@ -3,10 +3,11 @@ namespace Atproto\Lexicons\App\Bsky\Embed; use Atproto\Contracts\Lexicons\App\Bsky\Embed\EmbedInterface; -use Atproto\Contracts\Lexicons\App\Bsky\Embed\MediaInterface; +use Atproto\Contracts\Lexicons\App\Bsky\Embed\MediaContract; +use Atproto\DataModel\Blob\Blob; use Atproto\Exceptions\InvalidArgumentException; -class External implements EmbedInterface, MediaInterface +class External implements EmbedInterface, MediaContract { private string $uri; private string $title; @@ -69,18 +70,16 @@ public function thumb(Blob $blob = null) return $this->blob; } - if (! str_starts_with($blob->type(), 'image/*')) { + if (! str_starts_with($blob->mimeType(), 'image/*')) { throw new InvalidArgumentException(sprintf( - "'%s' is not a valid image type: %s", - $blob->path(), - $blob->type() + "\$blob is not a valid image type: %s", + $blob->mimeType() )); } if (1000000 < $blob->size()) { throw new InvalidArgumentException(sprintf( - "'%s' size is too big than maximum allowed: %d", - $blob->path(), + "\$blob size is too big than maximum allowed: %d", $blob->size() )); } @@ -96,7 +95,7 @@ public function jsonSerialize(): array 'uri' => $this->uri, 'title' => $this->title, 'description' => $this->description, - 'blob' => ($b = $this->blob) ? $b->blob() : null, + 'blob' => ($b = $this->blob) ? $b : null, ]); } diff --git a/src/Lexicons/App/Bsky/Embed/Image.php b/src/Lexicons/App/Bsky/Embed/Image.php index 894ba2c..c2c1ae8 100644 --- a/src/Lexicons/App/Bsky/Embed/Image.php +++ b/src/Lexicons/App/Bsky/Embed/Image.php @@ -3,6 +3,7 @@ namespace Atproto\Lexicons\App\Bsky\Embed; use Atproto\Contracts\Lexicons\App\Bsky\Embed\ImageInterface; +use Atproto\DataModel\Blob\Blob; use Atproto\Exceptions\InvalidArgumentException; class Image implements ImageInterface @@ -16,7 +17,7 @@ class Image implements ImageInterface */ public function __construct(Blob $file, string $alt) { - if (true !== str_starts_with($file->type(), 'image/')) { + if (true !== str_starts_with($file->mimeType(), 'image/')) { throw new InvalidArgumentException($file->path()." is not a valid image file."); } @@ -63,7 +64,7 @@ public function jsonSerialize(): array { return array_filter([ 'alt' => $this->alt(), - 'image' => $this->file->blob(), + 'image' => $this->file, 'aspectRatio' => $this->aspectRatio() ?: null, ]); } diff --git a/src/Lexicons/App/Bsky/Embed/RecordWithMedia.php b/src/Lexicons/App/Bsky/Embed/RecordWithMedia.php index d45ad86..61e260d 100644 --- a/src/Lexicons/App/Bsky/Embed/RecordWithMedia.php +++ b/src/Lexicons/App/Bsky/Embed/RecordWithMedia.php @@ -2,20 +2,20 @@ namespace Atproto\Lexicons\App\Bsky\Embed; -use Atproto\Contracts\Lexicons\App\Bsky\Embed\MediaInterface; +use Atproto\Contracts\Lexicons\App\Bsky\Embed\MediaContract; use Atproto\Lexicons\Com\Atproto\Repo\StrongRef; class RecordWithMedia extends Record { - private MediaInterface $media; + private MediaContract $media; - public function __construct(StrongRef $ref, MediaInterface $media) + public function __construct(StrongRef $ref, MediaContract $media) { parent::__construct($ref); $this->media($media); } - public function media(MediaInterface $media = null) + public function media(MediaContract $media = null) { if (is_null($media)) { return $this->media; diff --git a/src/Lexicons/App/Bsky/Embed/Video.php b/src/Lexicons/App/Bsky/Embed/Video.php index 2b799c8..066a5b2 100644 --- a/src/Lexicons/App/Bsky/Embed/Video.php +++ b/src/Lexicons/App/Bsky/Embed/Video.php @@ -2,12 +2,13 @@ namespace Atproto\Lexicons\App\Bsky\Embed; -use Atproto\Contracts\Lexicons\App\Bsky\Embed\MediaInterface; +use Atproto\Contracts\Lexicons\App\Bsky\Embed\MediaContract; use Atproto\Contracts\Lexicons\App\Bsky\Embed\VideoInterface; +use Atproto\DataModel\Blob\Blob; use Atproto\Exceptions\InvalidArgumentException; use Atproto\Lexicons\App\Bsky\Embed\Collections\CaptionCollection; -class Video implements VideoInterface, MediaInterface +class Video implements VideoInterface, MediaContract { private Blob $file; private ?string $alt = null; @@ -19,7 +20,7 @@ class Video implements VideoInterface, MediaInterface */ public function __construct(Blob $file) { - if ("video/mp4" !== $file->type()) { + if ("video/mp4" !== $file->mimeType()) { throw new InvalidArgumentException($file->path()." is not a valid video file."); } @@ -35,7 +36,7 @@ public function jsonSerialize(): array { $result = array_filter([ 'alt' => $this->alt() ?: null, - 'video' => $this->file->blob(), + 'video' => $this->file, 'aspectRatio' => $this->aspectRatio() ?: null, 'captions' => $this->captions()->toArray() ?: null, ]); From de6e0897ae42fb0c41a48bac8a04198292d7535c Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sun, 27 Oct 2024 01:27:25 +0400 Subject: [PATCH 33/58] test: comprehensive test coverage update - Add tests for new blob and CID systems - Update embed system tests - Clean up test organization and assertions - Improve mock implementations --- src/API/Com/Atrproto/Repo/UploadBlob.php | 8 +- .../Com/Atproto/Repo/CreateRecord.php | 2 +- tests/Unit/DataModel/Blob/BlobTest.php | 143 ++++++++++++++++++ tests/Unit/IPFS/CID/CIDTest.php | 57 +++++++ .../Lexicons/App/Bsky/Embed/CaptionTest.php | 8 +- .../Collections/CaptionCollectionTest.php | 4 +- .../Lexicons/App/Bsky/Embed/ExternalTest.php | 10 +- .../Unit/Lexicons/App/Bsky/Embed/FileTest.php | 94 +++++------- .../Lexicons/App/Bsky/Embed/ImageTest.php | 8 +- .../App/Bsky/Embed/RecordWithMediaTest.php | 8 +- .../Lexicons/App/Bsky/Embed/VideoTest.php | 19 +-- .../Unit/Lexicons/App/Bsky/Feed/PostTest.php | 2 - .../App/Bsky/Actor/GetProfileResourceTest.php | 8 +- .../Resources/Assets/AssociatedAssetTest.php | 2 +- tests/Unit/Resources/Assets/BaseAssetTest.php | 2 +- tests/Unit/Resources/Assets/ChatAssetTest.php | 1 - .../Resources/Assets/CreatorAssetTest.php | 2 - tests/Unit/Resources/Assets/UserAssetTest.php | 4 +- .../Unit/Resources/Assets/ViewerAssetTest.php | 1 - 19 files changed, 274 insertions(+), 109 deletions(-) create mode 100644 tests/Unit/DataModel/Blob/BlobTest.php create mode 100644 tests/Unit/IPFS/CID/CIDTest.php diff --git a/src/API/Com/Atrproto/Repo/UploadBlob.php b/src/API/Com/Atrproto/Repo/UploadBlob.php index a81d934..4c8095f 100644 --- a/src/API/Com/Atrproto/Repo/UploadBlob.php +++ b/src/API/Com/Atrproto/Repo/UploadBlob.php @@ -4,7 +4,7 @@ use Atproto\Contracts\HTTP\RequestContract; use Atproto\Exceptions\Http\Request\RequestBodyHasMissingRequiredFields; -use Atproto\Support\File; +use Atproto\Support\FileSupport; use Atproto\Resources\Com\Atproto\Repo\UploadBlobResource; use InvalidArgumentException; @@ -20,7 +20,7 @@ class UploadBlob implements RequestContract /** @var object $body The request body */ private $body; - /** @var File The blob content. */ + /** @var FileSupport The blob content. */ private $blob; /** @var array The headers for the request. */ @@ -53,7 +53,7 @@ public function __construct() */ public function setBlob($filePath) { - $file = new File($filePath); + $file = new FileSupport($filePath); if (! $file->exists()) { throw new InvalidArgumentException("File '$filePath' does not exist"); @@ -76,7 +76,7 @@ public function setBlob($filePath) /** * Get the blob content. * - * @return ?File The blob content. + * @return ?FileSupport The blob content. */ public function getBlob() { diff --git a/src/Lexicons/Com/Atproto/Repo/CreateRecord.php b/src/Lexicons/Com/Atproto/Repo/CreateRecord.php index 076a686..6dfd364 100644 --- a/src/Lexicons/Com/Atproto/Repo/CreateRecord.php +++ b/src/Lexicons/Com/Atproto/Repo/CreateRecord.php @@ -111,7 +111,7 @@ public function __toString(): string return json_encode($this); } - public function jsonSerialize() + public function jsonSerialize(): array { return array_filter([ 'repo' => $this->repo(), diff --git a/tests/Unit/DataModel/Blob/BlobTest.php b/tests/Unit/DataModel/Blob/BlobTest.php new file mode 100644 index 0000000..22a4656 --- /dev/null +++ b/tests/Unit/DataModel/Blob/BlobTest.php @@ -0,0 +1,143 @@ +markTestSkipped("Skip checking temporary files: tests are running by root"); + } + + $this->assertTrue(is_dir(self::$tmpDirPath)); + $this->assertTrue(is_file(self::$tmpFilePath)); + $this->assertIsReadable(self::$tmpFilePath); + } + + public static function tearDownAfterClass(): void + { + rmdir(self::$tmpDirPath); + + foreach(scandir(sys_get_temp_dir()) as $file) { + if (strpos($file, self::FILE_PREFIX) === 0) { + unlink(sys_get_temp_dir().DIRECTORY_SEPARATOR.$file); + } + } + } + + public function testBlobConstructorThrowsExceptionWhenPassedInvalidBinary(): void + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('$binary must be a binary'); + + Blob::viaBinary('invalid binary'); + } + + public function testSizeReturnsSizeOfBinary(): void + { + $binary = random_bytes(1024); + + $blob = Blob::viaBinary($binary); + + $actual = $blob->size(); + $expected = 1024; + + $this->assertSame($expected, $actual); + } + + public function testMimeTypeReturnsMimeTypeOfBinary(): void + { + $binary = random_bytes(1024); + + $blob = Blob::viaBinary($binary); + + $actual = $blob->mimeType(); + $expected = (new finfo(FILEINFO_MIME_TYPE))->buffer($binary); + + $this->assertSame($expected, $actual); + } + + public function testViaFileConstructorWorkingCorrectly(): void + { + $file = new FileSupport(self::$tmpFilePath); + $blob = Blob::viaFile($file); + + $this->assertSame($blob->size(), $file->getFileSize()); + $this->assertSame($blob->mimeType(), $file->getMimeType()); + $this->assertSame( + $blob->link(), + (new CID(MultiCodec::get('raw'), MultiBase::get('base32'), $file->getBlob()))->__toString() + ); + } + + /** @dataProvider expectedSerializations */ + public function testJsonSerialize(BlobContract $blob, array $expectedSerialization): void + { + $this->assertSame($expectedSerialization, json_decode($blob, true)); + } + + public function expectedSerializations(): array + { + $content = 'content'; + + $file = tempnam(sys_get_temp_dir(), self::FILE_PREFIX); + + $this->assertIsReadable($file); + file_put_contents($file, $content); + + $file = new FileSupport($file); + $viaFile = Blob::viaFile($file); + + $binary = random_bytes(strlen($content)); + $viaBinary = Blob::viaBinary($binary); + + return [ + [$viaFile, $this->createSchema($viaFile->link(), $file->getMimeType())], + [$viaBinary, $this->createSchema($viaBinary->link(), (new finfo(FILEINFO_MIME_TYPE))->buffer($binary))], + ]; + } + + public function createSchema(string $link, string $mimeType = null): array + { + return [ + '$type' => 'blob', + 'ref' => [ + '$link' => $link, + ], + 'mimeType' => $mimeType ?: 'application/octet-stream', + 'size' => 7, + ]; + } +} diff --git a/tests/Unit/IPFS/CID/CIDTest.php b/tests/Unit/IPFS/CID/CIDTest.php new file mode 100644 index 0000000..8f92f06 --- /dev/null +++ b/tests/Unit/IPFS/CID/CIDTest.php @@ -0,0 +1,57 @@ +generate(); + $expectedBinary = hex2bin($expectedHex); + + $actualHex = bin2hex($actualBinary); + + $this->assertSame($expectedHex, $actualHex); + + $actualLen = strlen($actualHex); + $expectedLen = strlen($expectedHex); + + $this->assertSame($expectedLen, $actualLen); + + $actualBase32 = substr($cid->__toString(), 1); + $expectedBase32 = substr((new Base32Encoder())->encode($expectedBinary), 1); + + $this->assertSame($expectedBase32, $actualBase32); + } + + public function testVersionChanging(): void + { + $mockVersion = new class () extends CIDVersion { + public function generate(): string + { + return ''; + } + }; + + $cid = new CID(MultiCodec::get('raw'), MultiBase::get('base32'), ''); + + $cid->version($mockVersion); + + $this->assertSame($mockVersion, $cid->version()); + $this->assertSame($cid, $this->getPropertyValue('cid', $mockVersion)); + } +} diff --git a/tests/Unit/Lexicons/App/Bsky/Embed/CaptionTest.php b/tests/Unit/Lexicons/App/Bsky/Embed/CaptionTest.php index 303adf9..8566e0e 100644 --- a/tests/Unit/Lexicons/App/Bsky/Embed/CaptionTest.php +++ b/tests/Unit/Lexicons/App/Bsky/Embed/CaptionTest.php @@ -8,7 +8,7 @@ class CaptionTest extends TestCase { - use FileMocking; + use FileMock; private Caption $caption; private array $dependencies = ['lang' => 'lang']; @@ -78,7 +78,7 @@ public function testSetLang(): void public function testJsonSerialize() { $expected = [ - 'file' => $this->blob, + 'file' => $this->createMockFile()->jsonSerialize(), 'lang' => $this->dependencies['lang'], ]; @@ -93,7 +93,7 @@ public function test__constructThrowsInvalidArgumentWhenPassedInvalidFileType(): $this->type = 'image/png'; $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage($this->dependencies['file']->path()." is not a text/vtt file."); + $this->expectExceptionMessage('$file is not a text/vtt file.'); $this->createCaption(); } @@ -103,7 +103,7 @@ public function test__constructorThrowsExceptionWhePassedUnacceptableSizedFile() $this->size = 20001; $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage($this->dependencies['file']->path()." is too large. Max size: 20000"); + $this->expectExceptionMessage('$file is too large. Max size: 20000'); $this->createCaption(); } diff --git a/tests/Unit/Lexicons/App/Bsky/Embed/Collections/CaptionCollectionTest.php b/tests/Unit/Lexicons/App/Bsky/Embed/Collections/CaptionCollectionTest.php index fbd248f..ba836dd 100644 --- a/tests/Unit/Lexicons/App/Bsky/Embed/Collections/CaptionCollectionTest.php +++ b/tests/Unit/Lexicons/App/Bsky/Embed/Collections/CaptionCollectionTest.php @@ -2,7 +2,7 @@ namespace Tests\Unit\Lexicons\App\Bsky\Embed\Collections; -use Atproto\Contracts\Lexicons\App\Bsky\Embed\CaptionInterface; +use Atproto\Contracts\Lexicons\App\Bsky\Embed\CaptionContract; use Atproto\Lexicons\App\Bsky\Embed\Collections\CaptionCollection; use PHPUnit\Framework\TestCase; @@ -11,6 +11,6 @@ class CaptionCollectionTest extends TestCase use EmbedCollectionTest; private string $target = CaptionCollection::class; - private string $dependency = CaptionInterface::class; + private string $dependency = CaptionContract::class; private int $maxLength = 20; } diff --git a/tests/Unit/Lexicons/App/Bsky/Embed/ExternalTest.php b/tests/Unit/Lexicons/App/Bsky/Embed/ExternalTest.php index 0939e22..3574916 100644 --- a/tests/Unit/Lexicons/App/Bsky/Embed/ExternalTest.php +++ b/tests/Unit/Lexicons/App/Bsky/Embed/ExternalTest.php @@ -2,8 +2,8 @@ namespace Tests\Unit\Lexicons\App\Bsky\Embed; +use Atproto\DataModel\Blob\Blob; use Atproto\Exceptions\InvalidArgumentException; -use Atproto\Lexicons\App\Bsky\Embed\Blob; use Atproto\Lexicons\App\Bsky\Embed\External; use PHPUnit\Framework\TestCase; @@ -28,12 +28,8 @@ public function setUp(): void ->will($this->returnCallback(fn () => $this->maximumAllowedBlobSize)); $this->blob->expects($this->any()) - ->method('type') + ->method('mimeType') ->will($this->returnCallback(fn () => $this->allowedMimes)); - - $this->blob->expects($this->any()) - ->method('blob') - ->willReturn('blob'); } public function testDescription() @@ -129,7 +125,7 @@ public function testJsonSerializeWithSetBlob(): void 'uri' => 'https://shahmal1yev.dev', 'title' => 'foo', 'description' => 'bar', - 'blob' => 'blob', + 'blob' => $this->blob->jsonSerialize(), ]; $this->assertSame($expected, json_decode($this->external, true)); diff --git a/tests/Unit/Lexicons/App/Bsky/Embed/FileTest.php b/tests/Unit/Lexicons/App/Bsky/Embed/FileTest.php index b95b503..e835e1a 100644 --- a/tests/Unit/Lexicons/App/Bsky/Embed/FileTest.php +++ b/tests/Unit/Lexicons/App/Bsky/Embed/FileTest.php @@ -2,97 +2,81 @@ namespace Tests\Unit\Lexicons\App\Bsky\Embed; +use Atproto\DataModel\Blob\Blob; use Atproto\Exceptions\InvalidArgumentException; -use Atproto\Lexicons\App\Bsky\Embed\Blob; +use Atproto\Support\FileSupport; use PHPUnit\Framework\TestCase; class FileTest extends TestCase { private string $testFilePath; - private string $unreadableFilePath; - private string $nonFilePath; + private string $testDirPath; private Blob $fileInstance; + private const FILE_PREFIX = '__FileTest__'; - /** - * @throws InvalidArgumentException - */ protected function setUp(): void { - parent::setUp(); + // Create a temporary test file + $this->testFilePath = tempnam(sys_get_temp_dir(), self::FILE_PREFIX); + file_put_contents($this->testFilePath, 'test content'); - $this->testFilePath = tempnam(sys_get_temp_dir(), 'testfile'); - file_put_contents($this->testFilePath, 'This is a test file.'); - $this->fileInstance = new Blob($this->testFilePath); + // Create a temporary test directory + $this->testDirPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . self::FILE_PREFIX . uniqid(); + mkdir($this->testDirPath); - $this->unreadableFilePath = tempnam(sys_get_temp_dir(), 'unreadable'); - file_put_contents($this->unreadableFilePath, 'This is an unreadable file.'); - chmod($this->unreadableFilePath, 0000); - - $this->nonFilePath = sys_get_temp_dir() . '/nonFile' . uniqid(); - mkdir($this->nonFilePath, 0777, true); + // Create file instance using the factory method + $fileSupport = new FileSupport($this->testFilePath); + $this->fileInstance = Blob::viaFile($fileSupport); } protected function tearDown(): void { - parent::tearDown(); - + // Clean up test files if (file_exists($this->testFilePath)) { unlink($this->testFilePath); } - - if (file_exists($this->unreadableFilePath)) { - chmod($this->unreadableFilePath, 0644); - unlink($this->unreadableFilePath); - } - - if (is_dir($this->nonFilePath)) { - rmdir($this->nonFilePath); + if (is_dir($this->testDirPath)) { + rmdir($this->testDirPath); } } - public function testFileSize(): void + public function testConstructorThrowsExceptionForNonExistentFile(): void { - $expectedSize = filesize($this->testFilePath); - $this->assertEquals($expectedSize, $this->fileInstance->size()); - } + $this->expectException(InvalidArgumentException::class); - public function testMimeType(): void - { - $expectedType = mime_content_type($this->testFilePath); - $this->assertEquals($expectedType, $this->fileInstance->type()); + $nonExistentFile = new FileSupport('/path/to/nonexistent/file'); + Blob::viaFile($nonExistentFile); } - public function testFileBlob(): void + public function testConstructorThrowsExceptionForDirectory(): void { - $expectedContent = file_get_contents($this->testFilePath); - $this->assertEquals($expectedContent, $this->fileInstance->blob()); + $this->expectException(InvalidArgumentException::class); + + $directory = new FileSupport($this->testDirPath); + Blob::viaFile($directory); } - public function testToStringMethod(): void + public function testSize(): void { - $expectedContent = file_get_contents($this->testFilePath); - $this->assertEquals($expectedContent, (string) $this->fileInstance); + $expectedSize = filesize($this->testFilePath); + $this->assertEquals($expectedSize, $this->fileInstance->size()); } - public function testConstructorThrowsExceptionWhenPassedUnreadableFilePath(): void + public function testMimeType(): void { - if (function_exists('posix_geteuid') && posix_geteuid() === 0) { - $this->markTestSkipped('Test skipped because it is running as root.'); - } - - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage("$this->unreadableFilePath is not readable."); - - $this->assertFalse(is_readable($this->unreadableFilePath), 'File should not be readable.'); - - new Blob($this->unreadableFilePath); + $expectedType = mime_content_type($this->testFilePath); + $this->assertEquals($expectedType, $this->fileInstance->mimeType()); } - public function testConstructorThrowsExceptionWhenPassedNonFilePath(): void + public function testJsonSerialize(): void { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage("$this->nonFilePath is not a file."); + $serialized = json_decode(json_encode($this->fileInstance), true); + + $this->assertArrayHasKey('$type', $serialized); + $this->assertArrayHasKey('ref', $serialized); + $this->assertArrayHasKey('mimeType', $serialized); + $this->assertArrayHasKey('size', $serialized); - new Blob($this->nonFilePath); + $this->assertEquals('blob', $serialized['$type']); } } diff --git a/tests/Unit/Lexicons/App/Bsky/Embed/ImageTest.php b/tests/Unit/Lexicons/App/Bsky/Embed/ImageTest.php index 6f2a78c..2eb816d 100644 --- a/tests/Unit/Lexicons/App/Bsky/Embed/ImageTest.php +++ b/tests/Unit/Lexicons/App/Bsky/Embed/ImageTest.php @@ -10,7 +10,7 @@ class ImageTest extends TestCase { - use FileMocking; + use FileMock; use Reflection; private Image $image; @@ -113,12 +113,12 @@ public function testJsonSerialize() { $expected = [ 'alt' => $this->dependencies['alt'], - 'image' => $this->dependencies['file']->blob(), + 'image' => $this->dependencies['file'], ]; $image = $this->createImage(); - $this->assertSame($expected, json_decode($image, true)); + $this->assertSame($expected, $image->jsonSerialize()); $aspectRatio = $this->randAspectRatio(); @@ -126,7 +126,7 @@ public function testJsonSerialize() $image->aspectRatio(...array_values($aspectRatio)); - $this->assertSame($expected, json_decode($image, true)); + $this->assertSame($expected, $image->jsonSerialize()); } /** diff --git a/tests/Unit/Lexicons/App/Bsky/Embed/RecordWithMediaTest.php b/tests/Unit/Lexicons/App/Bsky/Embed/RecordWithMediaTest.php index 870b73b..c422d40 100644 --- a/tests/Unit/Lexicons/App/Bsky/Embed/RecordWithMediaTest.php +++ b/tests/Unit/Lexicons/App/Bsky/Embed/RecordWithMediaTest.php @@ -2,26 +2,26 @@ namespace Tests\Unit\Lexicons\App\Bsky\Embed; -use Atproto\Contracts\Lexicons\App\Bsky\Embed\MediaInterface; +use Atproto\Contracts\Lexicons\App\Bsky\Embed\MediaContract; use Atproto\Lexicons\App\Bsky\Embed\RecordWithMedia; use Atproto\Lexicons\Com\Atproto\Repo\StrongRef; use PHPUnit\Framework\TestCase; class RecordWithMediaTest extends TestCase { - private MediaInterface $media; + private MediaContract $media; private RecordWithMedia $recordWithMedia; protected function setUp(): void { - $this->media = $this->createMock(MediaInterface::class); + $this->media = $this->createMock(MediaContract::class); $this->recordWithMedia = new RecordWithMedia($this->createMock(StrongRef::class), $this->media); } public function testMedia() { $this->assertSame($this->media, $this->recordWithMedia->media()); - $this->recordWithMedia->media($expected = $this->createMock(MediaInterface::class)); + $this->recordWithMedia->media($expected = $this->createMock(MediaContract::class)); $this->assertSame($expected, $this->recordWithMedia->media()); } diff --git a/tests/Unit/Lexicons/App/Bsky/Embed/VideoTest.php b/tests/Unit/Lexicons/App/Bsky/Embed/VideoTest.php index e69051c..d5336c9 100644 --- a/tests/Unit/Lexicons/App/Bsky/Embed/VideoTest.php +++ b/tests/Unit/Lexicons/App/Bsky/Embed/VideoTest.php @@ -2,18 +2,17 @@ namespace Tests\Unit\Lexicons\App\Bsky\Embed; -use Atproto\Contracts\Lexicons\App\Bsky\Embed\CaptionInterface; +use Atproto\Contracts\Lexicons\App\Bsky\Embed\CaptionContract; +use Atproto\DataModel\Blob\Blob; use Atproto\Exceptions\InvalidArgumentException; -use Atproto\Lexicons\App\Bsky\Embed\Caption; use Atproto\Lexicons\App\Bsky\Embed\Collections\CaptionCollection; -use Atproto\Lexicons\App\Bsky\Embed\Blob; use Atproto\Lexicons\App\Bsky\Embed\Video; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class VideoTest extends TestCase { - use FileMocking; + use FileMock; private Video $video; private Blob $file; @@ -69,15 +68,13 @@ public function testAspectRatio(): void public function testJsonSerializeReturnsCorrectSchema(): void { - $this->assertSame($this->file->blob(), $this->blob); - $expected = [ - 'video' => $this->file->blob(), + 'video' => $this->file, ]; $target = new Video($this->file); - $this->assertSame($expected, json_decode($target, true)); + $this->assertSame($expected, $target->jsonSerialize()); $captions = $this->createCaptionsMock(); $aspectRatio = $this->randAspectRatio(); @@ -93,7 +90,7 @@ public function testJsonSerializeReturnsCorrectSchema(): void ->alt($expected['alt']) ->aspectRatio(...array_values($expected['aspectRatio'])); - $this->assertSame($expected, json_decode($target, true)); + $this->assertSame($expected, $target->jsonSerialize()); } /** @@ -109,7 +106,7 @@ private function randAspectRatio(): array */ private function createCaptionsMock(): CaptionCollection { - $caption = $this->getMockBuilder(CaptionInterface::class) + $caption = $this->getMockBuilder(CaptionContract::class) ->disableOriginalConstructor() ->getMock(); @@ -117,7 +114,7 @@ private function createCaptionsMock(): CaptionCollection ->method('jsonSerialize') ->willReturn([ 'lang' => 'lang', - 'file' => $this->file->blob(), + 'file' => $this->file, ]); $captions = $this->getMockBuilder(CaptionCollection::class) diff --git a/tests/Unit/Lexicons/App/Bsky/Feed/PostTest.php b/tests/Unit/Lexicons/App/Bsky/Feed/PostTest.php index 5e40030..e430399 100644 --- a/tests/Unit/Lexicons/App/Bsky/Feed/PostTest.php +++ b/tests/Unit/Lexicons/App/Bsky/Feed/PostTest.php @@ -5,12 +5,10 @@ use Atproto\Contracts\Lexicons\App\Bsky\Embed\EmbedInterface; use Atproto\Exceptions\InvalidArgumentException; use Atproto\Lexicons\App\Bsky\Feed\Post; -use Atproto\Lexicons\App\Bsky\RichText\FeatureAbstract; use Atproto\Lexicons\App\Bsky\RichText\Mention; use Atproto\Lexicons\Com\Atproto\Label\SelfLabels; use Atproto\Lexicons\Com\Atproto\Repo\StrongRef; use Carbon\Carbon; -use DateTimeImmutable; use PHPUnit\Framework\TestCase; class PostTest extends TestCase diff --git a/tests/Unit/Resources/App/Bsky/Actor/GetProfileResourceTest.php b/tests/Unit/Resources/App/Bsky/Actor/GetProfileResourceTest.php index c56a1f7..e4054b2 100644 --- a/tests/Unit/Resources/App/Bsky/Actor/GetProfileResourceTest.php +++ b/tests/Unit/Resources/App/Bsky/Actor/GetProfileResourceTest.php @@ -2,23 +2,17 @@ namespace Tests\Unit\Resources\App\Bsky\Actor; -use Atproto\Contracts\HTTP\Resources\AssetContract; use Atproto\Contracts\HTTP\Resources\ResourceContract; -use Atproto\Exceptions\Resource\BadAssetCallException; use Atproto\Resources\App\Bsky\Actor\GetProfileResource; use Atproto\Resources\Assets\AssociatedAsset; use Atproto\Resources\Assets\DatetimeAsset; use Atproto\Resources\Assets\JoinedViaStarterPackAsset; -use Atproto\Resources\Assets\LabelAsset; use Atproto\Resources\Assets\ViewerAsset; -use Carbon\Carbon; -use Carbon\Exceptions\InvalidFormatException; -use GenericCollection\GenericCollection; use GenericCollection\Interfaces\GenericCollectionInterface; use PHPUnit\Framework\TestCase; -use Tests\Supports\PrimitiveAssetTest; use Tests\Supports\DateAssetTest; use Tests\Supports\NonPrimitiveAssetTest; +use Tests\Supports\PrimitiveAssetTest; class GetProfileResourceTest extends TestCase { diff --git a/tests/Unit/Resources/Assets/AssociatedAssetTest.php b/tests/Unit/Resources/Assets/AssociatedAssetTest.php index a7adcf3..c85dc7f 100644 --- a/tests/Unit/Resources/Assets/AssociatedAssetTest.php +++ b/tests/Unit/Resources/Assets/AssociatedAssetTest.php @@ -6,8 +6,8 @@ use Atproto\Resources\Assets\ChatAsset; use GenericCollection\Exceptions\InvalidArgumentException; use PHPUnit\Framework\TestCase; -use Tests\Supports\PrimitiveAssetTest; use Tests\Supports\NonPrimitiveAssetTest; +use Tests\Supports\PrimitiveAssetTest; class AssociatedAssetTest extends TestCase { diff --git a/tests/Unit/Resources/Assets/BaseAssetTest.php b/tests/Unit/Resources/Assets/BaseAssetTest.php index d0c4d22..83c05b4 100644 --- a/tests/Unit/Resources/Assets/BaseAssetTest.php +++ b/tests/Unit/Resources/Assets/BaseAssetTest.php @@ -2,10 +2,10 @@ namespace Tests\Unit\Resources\Assets; +use Atproto\Contracts\HTTP\Resources\AssetContract; use Atproto\Resources\Assets\BaseAsset; use GenericCollection\Exceptions\InvalidArgumentException; use PHPUnit\Framework\TestCase; -use Atproto\Contracts\HTTP\Resources\AssetContract; use Tests\Supports\AssetTest; class BaseAssetTest extends TestCase diff --git a/tests/Unit/Resources/Assets/ChatAssetTest.php b/tests/Unit/Resources/Assets/ChatAssetTest.php index 2b97e97..a5904d2 100644 --- a/tests/Unit/Resources/Assets/ChatAssetTest.php +++ b/tests/Unit/Resources/Assets/ChatAssetTest.php @@ -2,7 +2,6 @@ namespace Tests\Unit\Resources\Assets; -use Atproto\Contracts\HTTP\Resources\AssetContract; use Atproto\Resources\Assets\ChatAsset; use PHPUnit\Framework\TestCase; use Tests\Supports\PrimitiveAssetTest; diff --git a/tests/Unit/Resources/Assets/CreatorAssetTest.php b/tests/Unit/Resources/Assets/CreatorAssetTest.php index 27aedb2..cb937ad 100644 --- a/tests/Unit/Resources/Assets/CreatorAssetTest.php +++ b/tests/Unit/Resources/Assets/CreatorAssetTest.php @@ -2,9 +2,7 @@ namespace Tests\Unit\Resources\Assets; -use Atproto\Contracts\HTTP\Resources\AssetContract; use Atproto\Resources\Assets\CreatorAsset; -use Atproto\Resources\Assets\UserAsset; use PHPUnit\Framework\TestCase; use Tests\Supports\UserAssetTest; diff --git a/tests/Unit/Resources/Assets/UserAssetTest.php b/tests/Unit/Resources/Assets/UserAssetTest.php index b00f82e..5993c53 100644 --- a/tests/Unit/Resources/Assets/UserAssetTest.php +++ b/tests/Unit/Resources/Assets/UserAssetTest.php @@ -2,12 +2,12 @@ namespace Tests\Unit\Resources\Assets; -use Atproto\Resources\Assets\UserAsset; use Atproto\Resources\Assets\AssociatedAsset; use Atproto\Resources\Assets\DatetimeAsset; use Atproto\Resources\Assets\JoinedViaStarterPackAsset; -use Atproto\Resources\Assets\ViewerAsset; use Atproto\Resources\Assets\LabelsAsset; +use Atproto\Resources\Assets\UserAsset; +use Atproto\Resources\Assets\ViewerAsset; use Carbon\Carbon; use GenericCollection\Exceptions\InvalidArgumentException; use PHPUnit\Framework\TestCase; diff --git a/tests/Unit/Resources/Assets/ViewerAssetTest.php b/tests/Unit/Resources/Assets/ViewerAssetTest.php index 9d5ea9a..255e52e 100644 --- a/tests/Unit/Resources/Assets/ViewerAssetTest.php +++ b/tests/Unit/Resources/Assets/ViewerAssetTest.php @@ -3,7 +3,6 @@ namespace Tests\Unit\Resources\Assets\Resources\Assets; use Atproto\Resources\Assets\BlockingByListAsset; -use Atproto\Resources\Assets\FollowersAsset; use Atproto\Resources\Assets\KnownFollowersAsset; use Atproto\Resources\Assets\LabelsAsset; use Atproto\Resources\Assets\MutedByListAsset; From d518dfac62399d5953c50a0bf16deeb9adeb54f6 Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sun, 27 Oct 2024 01:30:08 +0400 Subject: [PATCH 34/58] update dependencies --- composer.lock | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/composer.lock b/composer.lock index 44e0bc8..c69364b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a9611ba6aeb11d62b419926b38c9a7d9", + "content-hash": "1702f11dcf6e5e2c11a6758cd92fce0a", "packages": [ { "name": "carbonphp/carbon-doctrine-types", @@ -864,16 +864,16 @@ }, { "name": "nikic/php-parser", - "version": "v5.3.0", + "version": "v5.3.1", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "3abf7425cd284141dc5d8d14a9ee444de3345d1a" + "reference": "8eea230464783aa9671db8eea6f8c6ac5285794b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/3abf7425cd284141dc5d8d14a9ee444de3345d1a", - "reference": "3abf7425cd284141dc5d8d14a9ee444de3345d1a", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/8eea230464783aa9671db8eea6f8c6ac5285794b", + "reference": "8eea230464783aa9671db8eea6f8c6ac5285794b", "shasum": "" }, "require": { @@ -916,9 +916,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v5.3.0" + "source": "https://github.com/nikic/PHP-Parser/tree/v5.3.1" }, - "time": "2024-09-29T13:56:26+00:00" + "time": "2024-10-08T18:51:32+00:00" }, { "name": "phar-io/manifest", @@ -1040,16 +1040,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.12.5", + "version": "1.12.7", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "7e6c6cb7cecb0a6254009a1a8a7d54ec99812b17" + "reference": "dc2b9976bd8b0f84ec9b0e50cc35378551de7af0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/7e6c6cb7cecb0a6254009a1a8a7d54ec99812b17", - "reference": "7e6c6cb7cecb0a6254009a1a8a7d54ec99812b17", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/dc2b9976bd8b0f84ec9b0e50cc35378551de7af0", + "reference": "dc2b9976bd8b0f84ec9b0e50cc35378551de7af0", "shasum": "" }, "require": { @@ -1094,7 +1094,7 @@ "type": "github" } ], - "time": "2024-09-26T12:45:22+00:00" + "time": "2024-10-18T11:12:07+00:00" }, { "name": "phpunit/php-code-coverage", @@ -2596,6 +2596,8 @@ "ext-fileinfo": "*", "php": ">=7.4" }, - "platform-dev": [], + "platform-dev": { + "ext-posix": "*" + }, "plugin-api-version": "2.6.0" } From 38c86c5235f6d095b0c7e75d699e44bb912a69cb Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sun, 27 Oct 2024 01:44:26 +0400 Subject: [PATCH 35/58] test: update exception message assertions for compatibility --- .../App/Bsky/Embed/Collections/EmbedCollectionTest.php | 3 +-- tests/Unit/Lexicons/Com/Atproto/Label/SelfLabelsTest.php | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/Unit/Lexicons/App/Bsky/Embed/Collections/EmbedCollectionTest.php b/tests/Unit/Lexicons/App/Bsky/Embed/Collections/EmbedCollectionTest.php index f7b9e26..69b1d44 100644 --- a/tests/Unit/Lexicons/App/Bsky/Embed/Collections/EmbedCollectionTest.php +++ b/tests/Unit/Lexicons/App/Bsky/Embed/Collections/EmbedCollectionTest.php @@ -47,8 +47,7 @@ public function testValidateThrowsExceptionWhenPassedInvalidArgument(): void $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage(sprintf( - "must implement interface %s, instance of %s given", - $this->dependency, + "%s given", get_class($given) )); diff --git a/tests/Unit/Lexicons/Com/Atproto/Label/SelfLabelsTest.php b/tests/Unit/Lexicons/Com/Atproto/Label/SelfLabelsTest.php index b5291be..208c750 100644 --- a/tests/Unit/Lexicons/Com/Atproto/Label/SelfLabelsTest.php +++ b/tests/Unit/Lexicons/Com/Atproto/Label/SelfLabelsTest.php @@ -35,8 +35,10 @@ public function test__constructFillsDataCorrectly(): void public function test__constructorThrowsInvalidArgumentExceptionWhenPassedInvalidArgument(): void { + $givenLabel = (PHP_VERSION_ID < 80000) ? 'object' : 'stdClass'; + $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage("must be of the type string"); + $this->expectExceptionMessage("$givenLabel given"); $this->selfLabels = new SelfLabels(['val 1', new stdClass()]); } From 329a83f5e929d119d930211ce35af531a4da79e6 Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sun, 27 Oct 2024 19:42:32 +0400 Subject: [PATCH 36/58] refactor: update embed interface implementation for autofill $type field --- .../Lexicons/App/Bsky/Embed/EmbedInterface.php | 1 + .../App/Bsky/Embed/Collections/ImageCollection.php | 13 +++++++++++++ src/Lexicons/App/Bsky/Embed/External.php | 6 ++++++ src/Lexicons/App/Bsky/Embed/Record.php | 6 ++++++ src/Lexicons/App/Bsky/Embed/RecordWithMedia.php | 6 ++++++ src/Lexicons/App/Bsky/Embed/Video.php | 6 ++++++ 6 files changed, 38 insertions(+) diff --git a/src/Contracts/Lexicons/App/Bsky/Embed/EmbedInterface.php b/src/Contracts/Lexicons/App/Bsky/Embed/EmbedInterface.php index 4667dd7..589ca6f 100644 --- a/src/Contracts/Lexicons/App/Bsky/Embed/EmbedInterface.php +++ b/src/Contracts/Lexicons/App/Bsky/Embed/EmbedInterface.php @@ -6,4 +6,5 @@ interface EmbedInterface extends \JsonSerializable, Stringable { + public function type(): string; } diff --git a/src/Lexicons/App/Bsky/Embed/Collections/ImageCollection.php b/src/Lexicons/App/Bsky/Embed/Collections/ImageCollection.php index c55fdd3..5302355 100644 --- a/src/Lexicons/App/Bsky/Embed/Collections/ImageCollection.php +++ b/src/Lexicons/App/Bsky/Embed/Collections/ImageCollection.php @@ -29,4 +29,17 @@ protected function validator(): \Closure return true; }; } + + public function type(): string + { + return 'app.bsky.embed.images'; + } + + public function jsonSerialize() + { + return [ + 'images' => $this->toArray(), + '$type' => $this->type(), + ]; + } } diff --git a/src/Lexicons/App/Bsky/Embed/External.php b/src/Lexicons/App/Bsky/Embed/External.php index 2272f8c..90b7d78 100644 --- a/src/Lexicons/App/Bsky/Embed/External.php +++ b/src/Lexicons/App/Bsky/Embed/External.php @@ -92,6 +92,7 @@ public function thumb(Blob $blob = null) public function jsonSerialize(): array { return array_filter([ + '$type' => $this->type(), 'uri' => $this->uri, 'title' => $this->title, 'description' => $this->description, @@ -103,4 +104,9 @@ public function __toString(): string { return json_encode($this); } + + public function type(): string + { + return 'app.bsky.embed.external'; + } } diff --git a/src/Lexicons/App/Bsky/Embed/Record.php b/src/Lexicons/App/Bsky/Embed/Record.php index eabe245..f1cf13b 100644 --- a/src/Lexicons/App/Bsky/Embed/Record.php +++ b/src/Lexicons/App/Bsky/Embed/Record.php @@ -22,7 +22,13 @@ public function __toString(): string public function jsonSerialize(): array { return [ + '$type' => $this->type(), 'record' => $this->ref, ]; } + + public function type(): string + { + return 'app.bsky.embed.record'; + } } diff --git a/src/Lexicons/App/Bsky/Embed/RecordWithMedia.php b/src/Lexicons/App/Bsky/Embed/RecordWithMedia.php index 61e260d..509abf0 100644 --- a/src/Lexicons/App/Bsky/Embed/RecordWithMedia.php +++ b/src/Lexicons/App/Bsky/Embed/RecordWithMedia.php @@ -29,7 +29,13 @@ public function media(MediaContract $media = null) public function jsonSerialize(): array { return array_merge(parent::jsonSerialize(), [ + '$type' => $this->type(), 'media' => $this->media, ]); } + + public function type(): string + { + return 'app.bsky.embed.recordWithMedia'; + } } diff --git a/src/Lexicons/App/Bsky/Embed/Video.php b/src/Lexicons/App/Bsky/Embed/Video.php index 066a5b2..a7f96b9 100644 --- a/src/Lexicons/App/Bsky/Embed/Video.php +++ b/src/Lexicons/App/Bsky/Embed/Video.php @@ -35,6 +35,7 @@ public function __construct(Blob $file) public function jsonSerialize(): array { $result = array_filter([ + '$type' => $this->type(), 'alt' => $this->alt() ?: null, 'video' => $this->file, 'aspectRatio' => $this->aspectRatio() ?: null, @@ -92,4 +93,9 @@ public function __toString(): string $result = json_encode($this); return $result; } + + public function type(): string + { + return 'app.bsky.embed.video'; + } } From bd36a66e36334e11168af544b118c95f75dde68e Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sun, 27 Oct 2024 19:43:39 +0400 Subject: [PATCH 37/58] refactor: update uploadBlob lexicon for fixing issues --- src/Lexicons/Com/Atproto/Repo/UploadBlob.php | 35 ++++++++++++-------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/Lexicons/Com/Atproto/Repo/UploadBlob.php b/src/Lexicons/Com/Atproto/Repo/UploadBlob.php index ec1130d..31a8bc5 100644 --- a/src/Lexicons/Com/Atproto/Repo/UploadBlob.php +++ b/src/Lexicons/Com/Atproto/Repo/UploadBlob.php @@ -4,22 +4,32 @@ use Atproto\Contracts\HTTP\Resources\ResourceContract; use Atproto\Contracts\RequestContract; +use Atproto\DataModel\Blob\Blob; use Atproto\Exceptions\Http\MissingFieldProvidedException; use Atproto\Lexicons\APIRequest; use Atproto\Resources\Com\Atproto\Repo\UploadBlobResource; +use Atproto\Support\FileSupport; class UploadBlob extends APIRequest { - protected ?string $blob = null; - protected ?string $token = null; + protected function initialize(): void + { + parent::initialize(); + $this->method('POST') + ->header('Content-Type', '*/*'); + } public function blob(string $blob = null) { if (is_null($blob)) { - return $this->blob; + return $this->parameter('blob'); } - $this->blob = $blob; + $blob = (! mb_check_encoding($blob, 'UTF-8')) + ? $blob + : (new FileSupport($blob))->getBlob(); + + $this->parameter('blob', bin2hex($blob)); return $this; } @@ -27,12 +37,10 @@ public function blob(string $blob = null) public function token(string $token = null) { if (is_null($token)) { - return $this->token; + return $this->header('Authorization'); } - $this->token = $token; - - $this->header('Authorization', "Bearer $this->token"); + $this->header('Authorization', "Bearer $token"); return $this; } @@ -43,13 +51,12 @@ public function token(string $token = null) public function build(): RequestContract { $missing = array_filter( - [$this->token => 'token', $this->blob => 'blob'], - fn ($key, $value) => ! $value, - ARRAY_FILTER_USE_BOTH + ['token' => $this->header('Authorization'), 'blob' => $this->parameter('blob')], + fn ($value) => is_null($value), ); if (count($missing)) { - throw new MissingFieldProvidedException(implode(", ", $missing)); + throw new MissingFieldProvidedException(implode(", ", array_keys($missing))); } return $this; @@ -57,6 +64,8 @@ public function build(): RequestContract public function resource(array $data): ResourceContract { - return new UploadBlobResource($data); + return new UploadBlobResource([ + 'blob' => Blob::viaBinary(hex2bin($this->parameter('blob'))) + ]); } } From ce2a8ba2e3c20b4a09d0c83354136660589d0833 Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sun, 27 Oct 2024 19:49:00 +0400 Subject: [PATCH 38/58] enhance: update createRecord implementation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - implement Authentication trait for tracking session changes - fix HTTP method to POST for proper API request - add feature tests for blob reuse in posts Previously uploaded blobs can now be reused in post creation without re-uploading ๐Ÿš€ --- .../Com/Atproto/Repo/CreateRecord.php | 10 ++ .../Com/Atproto/Repo/CreateRecordTest.php | 93 ++++++++++++++++++- 2 files changed, 101 insertions(+), 2 deletions(-) diff --git a/src/Lexicons/Com/Atproto/Repo/CreateRecord.php b/src/Lexicons/Com/Atproto/Repo/CreateRecord.php index 6dfd364..405aef3 100644 --- a/src/Lexicons/Com/Atproto/Repo/CreateRecord.php +++ b/src/Lexicons/Com/Atproto/Repo/CreateRecord.php @@ -7,16 +7,26 @@ use Atproto\Contracts\RequestContract; use Atproto\Exceptions\Http\MissingFieldProvidedException; use Atproto\Lexicons\APIRequest; +use Atproto\Lexicons\Traits\Authentication; use Atproto\Resources\Com\Atproto\Repo\CreateRecordResource; class CreateRecord extends APIRequest implements LexiconContract { + use Authentication; + protected array $required = [ 'repo', 'collection', 'record' ]; + protected function initialize(): void + { + parent::initialize(); + + $this->method('POST'); + } + public function repo(string $repo = null) { if (is_null($repo)) { diff --git a/tests/Feature/Lexicons/Com/Atproto/Repo/CreateRecordTest.php b/tests/Feature/Lexicons/Com/Atproto/Repo/CreateRecordTest.php index 2311698..0fd2434 100644 --- a/tests/Feature/Lexicons/Com/Atproto/Repo/CreateRecordTest.php +++ b/tests/Feature/Lexicons/Com/Atproto/Repo/CreateRecordTest.php @@ -4,9 +4,14 @@ use Atproto\Client; use Atproto\Contracts\Lexicons\App\Bsky\Feed\PostBuilderContract; +use Atproto\DataModel\Blob\Blob; +use Atproto\Exceptions\BlueskyException; use Atproto\Exceptions\InvalidArgumentException; +use Atproto\Lexicons\App\Bsky\Embed\Collections\ImageCollection; +use Atproto\Lexicons\App\Bsky\Embed\Image; use Atproto\Lexicons\Com\Atproto\Repo\CreateRecord; use Atproto\Support\Arr; +use Atproto\Support\FileSupport; use PHPUnit\Framework\TestCase; class CreateRecordTest extends TestCase @@ -37,7 +42,10 @@ public function testBuildCreateRecordRequestWithPost(): void $this->assertInstanceOf(PostBuilderContract::class, $post); - $createRecord = $client->com()->atproto()->repo()->createRecord()->forge()->record($post); + $createRecord = $client->com()->atproto()->repo()->createRecord()->forge() + ->record($post) + ->repo($client->authenticated()->did()) + ->collection('app.bsky.feed.post'); $this->assertInstanceOf(CreateRecord::class, $createRecord); @@ -46,10 +54,91 @@ public function testBuildCreateRecordRequestWithPost(): void $this->assertSame($serializedPost, $actualPost); - $response = $client->send(); + $response = $createRecord->send(); $this->assertIsString($response->uri()); echo $response->uri(); } + + /** + * @throws BlueskyException + */ + public function testSendPostWithBlobUsingPostBuilderAPI(): void + { + $client = static::$client; + + /** @var Blob $uploadBlob */ + $uploadedBlob = $client->com() + ->atproto() + ->repo() + ->uploadBlob() + ->forge() // Atproto\Lexicons\Com\Atproto\Repo\UploadBlob + ->token($client->authenticated()->accessJwt()) + ->blob(__DIR__.'/../../../../../../art/file.png') + ->build() + ->send() // Atproto\Resources\Com\Atproto\Repo\UploadBlobResource + ->blob(); + + $this->assertInstanceOf(Blob::class, $uploadedBlob); + + $post = $client->app() + ->bsky() + ->feed() + ->post() + ->forge() + ->text("Hello World!") + ->embed(new ImageCollection([ + new Image($uploadedBlob, "Alt text") + ])); + + $this->assertInstanceOf(PostBuilderContract::class, $post); + + $createdRecord = $client->com() + ->atproto() + ->repo() + ->createRecord() + ->forge() + ->record($post) + ->repo($client->authenticated()->did()) + ->collection('app.bsky.feed.post') + ->build() + ->send(); + + $this->assertIsString($createdRecord->uri()); + } + + /** + * @throws InvalidArgumentException + */ + public function testPostCreationWithoutBlobUploading(): void + { + $client = static::$client; + + $post = $client->app() + ->bsky() + ->feed() + ->post() + ->forge() + ->text("Testing post creation without a blob uploading") + ->embed(new ImageCollection([ + new Image( + Blob::viaFile(new FileSupport(__DIR__.'/../../../../../../art/file.png')), + 'This blob not uploaded during this post creation' + ), + ])); + + $createdRecord = $client->com() + ->atproto() + ->repo() + ->createRecord() + ->forge() + ->record($post) + ->repo($client->authenticated()->did()) + ->collection('app.bsky.feed.post') + ->build() + ->send(); + + $this->assertIsString($createdRecord->uri()); + } } From 19583965e60fe18e0244693b407983a5c331540c Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Mon, 28 Oct 2024 01:34:11 +0400 Subject: [PATCH 39/58] Refactor tests for compatibility with recent changes and resolve test-reported issues - Update tests to ensure compatibility with recent refactoring, including modified methods and type hints. - Fix failing tests by addressing issues reported in test results, such as data handling in `jsonSerialize()` and validation exceptions. --- .../App/Bsky/Embed/Collections/ImageCollection.php | 2 +- src/Lexicons/Com/Atproto/Repo/UploadBlob.php | 9 +++++++-- src/Support/FileSupport.php | 9 ++++++++- .../Requests/Com/Atproto/Repo/UploadBlobTest.php | 6 +++--- .../Embed/Collections/CaptionCollectionTest.php | 14 ++++++++++++++ .../Bsky/Embed/Collections/EmbedCollectionTest.php | 13 ------------- .../Bsky/Embed/Collections/ImageCollectionTest.php | 13 +++++++++++++ .../Unit/Lexicons/App/Bsky/Embed/ExternalTest.php | 2 ++ tests/Unit/Lexicons/App/Bsky/Embed/RecordTest.php | 2 +- tests/Unit/Lexicons/App/Bsky/Embed/VideoTest.php | 2 ++ 10 files changed, 51 insertions(+), 21 deletions(-) diff --git a/src/Lexicons/App/Bsky/Embed/Collections/ImageCollection.php b/src/Lexicons/App/Bsky/Embed/Collections/ImageCollection.php index 5302355..15800bc 100644 --- a/src/Lexicons/App/Bsky/Embed/Collections/ImageCollection.php +++ b/src/Lexicons/App/Bsky/Embed/Collections/ImageCollection.php @@ -35,7 +35,7 @@ public function type(): string return 'app.bsky.embed.images'; } - public function jsonSerialize() + public function jsonSerialize(): array { return [ 'images' => $this->toArray(), diff --git a/src/Lexicons/Com/Atproto/Repo/UploadBlob.php b/src/Lexicons/Com/Atproto/Repo/UploadBlob.php index 31a8bc5..6d1d8c5 100644 --- a/src/Lexicons/Com/Atproto/Repo/UploadBlob.php +++ b/src/Lexicons/Com/Atproto/Repo/UploadBlob.php @@ -6,6 +6,7 @@ use Atproto\Contracts\RequestContract; use Atproto\DataModel\Blob\Blob; use Atproto\Exceptions\Http\MissingFieldProvidedException; +use Atproto\Exceptions\InvalidArgumentException; use Atproto\Lexicons\APIRequest; use Atproto\Resources\Com\Atproto\Repo\UploadBlobResource; use Atproto\Support\FileSupport; @@ -19,10 +20,13 @@ protected function initialize(): void ->header('Content-Type', '*/*'); } + /** + * @throws InvalidArgumentException + */ public function blob(string $blob = null) { if (is_null($blob)) { - return $this->parameter('blob'); + return hex2bin($this->parameter('blob')); } $blob = (! mb_check_encoding($blob, 'UTF-8')) @@ -37,7 +41,8 @@ public function blob(string $blob = null) public function token(string $token = null) { if (is_null($token)) { - return $this->header('Authorization'); + $token = $this->header('Authorization'); + return trim(substr($token, strrpos($token, ' '))) ?: null; } $this->header('Authorization', "Bearer $token"); diff --git a/src/Support/FileSupport.php b/src/Support/FileSupport.php index c0bfff3..0801b13 100644 --- a/src/Support/FileSupport.php +++ b/src/Support/FileSupport.php @@ -2,6 +2,8 @@ namespace Atproto\Support; +use Atproto\Exceptions\InvalidArgumentException; + /** * Class File * @@ -15,11 +17,16 @@ class FileSupport /** * Constructor. * - * @param string $file_path The path to the file. + * @param string $file_path The path to the file. + * @throws InvalidArgumentException */ public function __construct($file_path) { $this->file_path = $file_path; + + if (! $this->isFile() && ! $this->isDirectory()) { + throw new InvalidArgumentException("File path '$file_path' does not exist."); + } } /** diff --git a/tests/Unit/HTTP/API/Requests/Com/Atproto/Repo/UploadBlobTest.php b/tests/Unit/HTTP/API/Requests/Com/Atproto/Repo/UploadBlobTest.php index f7eef05..9d32c59 100644 --- a/tests/Unit/HTTP/API/Requests/Com/Atproto/Repo/UploadBlobTest.php +++ b/tests/Unit/HTTP/API/Requests/Com/Atproto/Repo/UploadBlobTest.php @@ -26,7 +26,7 @@ protected function setUp(): void public function testBlobMethodSetsAndReturnsValue(): void { - $blobData = $this->faker->word; + $blobData = random_bytes(1024); $result = $this->uploadBlob->blob($blobData); @@ -69,7 +69,7 @@ public function testBuildThrowsExceptionWhenTokenIsMissing(): void $this->expectException(MissingFieldProvidedException::class); $this->expectExceptionMessage('token'); - $this->uploadBlob->blob($this->faker->word)->build(); + $this->uploadBlob->blob(random_bytes(1024))->build(); } /** @@ -78,7 +78,7 @@ public function testBuildThrowsExceptionWhenTokenIsMissing(): void public function testBuildReturnsInstanceWhenAllFieldsAreSet(): void { $result = $this->uploadBlob - ->blob($this->faker->word) + ->blob(random_bytes(1024)) ->token($this->faker->word) ->build(); diff --git a/tests/Unit/Lexicons/App/Bsky/Embed/Collections/CaptionCollectionTest.php b/tests/Unit/Lexicons/App/Bsky/Embed/Collections/CaptionCollectionTest.php index ba836dd..f99c41e 100644 --- a/tests/Unit/Lexicons/App/Bsky/Embed/Collections/CaptionCollectionTest.php +++ b/tests/Unit/Lexicons/App/Bsky/Embed/Collections/CaptionCollectionTest.php @@ -3,6 +3,7 @@ namespace Tests\Unit\Lexicons\App\Bsky\Embed\Collections; use Atproto\Contracts\Lexicons\App\Bsky\Embed\CaptionContract; +use Atproto\Exceptions\InvalidArgumentException; use Atproto\Lexicons\App\Bsky\Embed\Collections\CaptionCollection; use PHPUnit\Framework\TestCase; @@ -13,4 +14,17 @@ class CaptionCollectionTest extends TestCase private string $target = CaptionCollection::class; private string $dependency = CaptionContract::class; private int $maxLength = 20; + + /** + * @throws InvalidArgumentException + */ + public function testJsonSerialize() + { + $items = new $this->target($this->items(2)); + + $expected = json_encode(array_map(fn () => ['foo' => 'bar'], $items->toArray())); + $actual = json_encode($items); + + $this->assertSame($expected, $actual); + } } diff --git a/tests/Unit/Lexicons/App/Bsky/Embed/Collections/EmbedCollectionTest.php b/tests/Unit/Lexicons/App/Bsky/Embed/Collections/EmbedCollectionTest.php index 69b1d44..e6287f1 100644 --- a/tests/Unit/Lexicons/App/Bsky/Embed/Collections/EmbedCollectionTest.php +++ b/tests/Unit/Lexicons/App/Bsky/Embed/Collections/EmbedCollectionTest.php @@ -61,17 +61,4 @@ public function testValidateThrowsExceptionWhenLimitExceed(): void new $this->target($this->items(++$this->maxLength)); } - - /** - * @throws InvalidArgumentException - */ - public function testJsonSerialize() - { - $items = new $this->target($this->items(2)); - - $expected = json_encode(array_map(fn () => ['foo' => 'bar'], $items->toArray())); - $actual = json_encode($items); - - $this->assertSame($expected, $actual); - } } diff --git a/tests/Unit/Lexicons/App/Bsky/Embed/Collections/ImageCollectionTest.php b/tests/Unit/Lexicons/App/Bsky/Embed/Collections/ImageCollectionTest.php index 548e198..1d9b430 100644 --- a/tests/Unit/Lexicons/App/Bsky/Embed/Collections/ImageCollectionTest.php +++ b/tests/Unit/Lexicons/App/Bsky/Embed/Collections/ImageCollectionTest.php @@ -31,4 +31,17 @@ public function testValidateThrowsExceptionWherePassedThatSizeGreaterThanLimit() new ImageCollection([$dependency]); } + + /** + * @throws InvalidArgumentException + */ + public function testJsonSerialize() + { + $items = new $this->target($this->items(2)); + + $expected = json_encode(['images' => array_map(fn () => ['foo' => 'bar'], $items->toArray()), '$type' => 'app.bsky.embed.images']); + $actual = json_encode($items); + + $this->assertSame($expected, $actual); + } } diff --git a/tests/Unit/Lexicons/App/Bsky/Embed/ExternalTest.php b/tests/Unit/Lexicons/App/Bsky/Embed/ExternalTest.php index 3574916..383022a 100644 --- a/tests/Unit/Lexicons/App/Bsky/Embed/ExternalTest.php +++ b/tests/Unit/Lexicons/App/Bsky/Embed/ExternalTest.php @@ -106,6 +106,7 @@ public function testTitle() public function testJsonSerializeWithoutSetBlob(): void { $expected = [ + '$type' => 'app.bsky.embed.external', 'uri' => 'https://shahmal1yev.dev', 'title' => 'foo', 'description' => 'bar', @@ -122,6 +123,7 @@ public function testJsonSerializeWithSetBlob(): void $this->external->thumb($this->blob); $expected = [ + '$type' => 'app.bsky.embed.external', 'uri' => 'https://shahmal1yev.dev', 'title' => 'foo', 'description' => 'bar', diff --git a/tests/Unit/Lexicons/App/Bsky/Embed/RecordTest.php b/tests/Unit/Lexicons/App/Bsky/Embed/RecordTest.php index 65423a9..579215e 100644 --- a/tests/Unit/Lexicons/App/Bsky/Embed/RecordTest.php +++ b/tests/Unit/Lexicons/App/Bsky/Embed/RecordTest.php @@ -11,7 +11,7 @@ class RecordTest extends TestCase private Record $record; private array $expected = [ - + '$type' => 'app.bsky.embed.record', 'record' => [ 'uri' => 'foo', 'cid' => 'bar' diff --git a/tests/Unit/Lexicons/App/Bsky/Embed/VideoTest.php b/tests/Unit/Lexicons/App/Bsky/Embed/VideoTest.php index d5336c9..d945982 100644 --- a/tests/Unit/Lexicons/App/Bsky/Embed/VideoTest.php +++ b/tests/Unit/Lexicons/App/Bsky/Embed/VideoTest.php @@ -69,6 +69,7 @@ public function testAspectRatio(): void public function testJsonSerializeReturnsCorrectSchema(): void { $expected = [ + '$type' => 'app.bsky.embed.video', 'video' => $this->file, ]; @@ -80,6 +81,7 @@ public function testJsonSerializeReturnsCorrectSchema(): void $aspectRatio = $this->randAspectRatio(); $expected = [ + '$type' => 'app.bsky.embed.video', 'alt' => 'alt text', 'video' => $expected['video'], 'aspectRatio' => $aspectRatio, From 02d212afb2ac473f523b7859880414fa0e3348fd Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Mon, 28 Oct 2024 01:38:35 +0400 Subject: [PATCH 40/58] Optimize imports and apply PSR 12 using PHP CS Fixer --- src/API/Com/Atrproto/Repo/CreateRecord.php | 1 - src/API/Com/Atrproto/Repo/UploadBlob.php | 1 - src/Collections/FacetCollection.php | 1 - src/Contracts/AuthStrategyContract.php | 2 -- src/Contracts/HTTP/RequestContract.php | 2 -- src/Contracts/RecordBuilderContract.php | 1 - src/DataModel/Blob/BinaryBlobHandler.php | 2 +- src/DataModel/Blob/Blob.php | 4 ++-- src/DataModel/Blob/FileBlobHandler.php | 2 +- src/Exceptions/InvalidArgumentException.php | 2 -- src/Lexicons/App/Bsky/RichText/Link.php | 3 --- src/MultiFormats/MultiCodec.php | 1 - src/Resources/Assets/FollowersAsset.php | 2 +- src/Resources/Assets/LabelsAsset.php | 2 +- src/Support/Arr.php | 2 -- src/Traits/Smith.php | 1 - 16 files changed, 6 insertions(+), 23 deletions(-) diff --git a/src/API/Com/Atrproto/Repo/CreateRecord.php b/src/API/Com/Atrproto/Repo/CreateRecord.php index d2d4a90..99cfa3c 100644 --- a/src/API/Com/Atrproto/Repo/CreateRecord.php +++ b/src/API/Com/Atrproto/Repo/CreateRecord.php @@ -5,7 +5,6 @@ use Atproto\Contracts\HTTP\RequestContract; use Atproto\Contracts\RecordBuilderContract; use Atproto\Exceptions\Http\Request\RequestBodyHasMissingRequiredFields; -use Atproto\Resources\Com\Atproto\Repo\CreateRecordResource; use InvalidArgumentException; /** diff --git a/src/API/Com/Atrproto/Repo/UploadBlob.php b/src/API/Com/Atrproto/Repo/UploadBlob.php index 4c8095f..53c9cdd 100644 --- a/src/API/Com/Atrproto/Repo/UploadBlob.php +++ b/src/API/Com/Atrproto/Repo/UploadBlob.php @@ -5,7 +5,6 @@ use Atproto\Contracts\HTTP\RequestContract; use Atproto\Exceptions\Http\Request\RequestBodyHasMissingRequiredFields; use Atproto\Support\FileSupport; -use Atproto\Resources\Com\Atproto\Repo\UploadBlobResource; use InvalidArgumentException; /** diff --git a/src/Collections/FacetCollection.php b/src/Collections/FacetCollection.php index fd55269..269e83d 100644 --- a/src/Collections/FacetCollection.php +++ b/src/Collections/FacetCollection.php @@ -3,7 +3,6 @@ namespace Atproto\Collections; use Atproto\Contracts\Lexicons\App\Bsky\RichText\FacetContract; -use Atproto\Lexicons\App\Bsky\RichText\FeatureAbstract; use GenericCollection\GenericCollection; class FacetCollection extends GenericCollection diff --git a/src/Contracts/AuthStrategyContract.php b/src/Contracts/AuthStrategyContract.php index 203b35a..bf4cf59 100644 --- a/src/Contracts/AuthStrategyContract.php +++ b/src/Contracts/AuthStrategyContract.php @@ -2,8 +2,6 @@ namespace Atproto\Contracts; -use Exception; - /** * Interface AuthStrategyContract * diff --git a/src/Contracts/HTTP/RequestContract.php b/src/Contracts/HTTP/RequestContract.php index f647699..f6e8426 100644 --- a/src/Contracts/HTTP/RequestContract.php +++ b/src/Contracts/HTTP/RequestContract.php @@ -2,8 +2,6 @@ namespace Atproto\Contracts\HTTP; -use Atproto\Contracts\HTTP\Resources\ResourceContract; - /** * Interface RequestContract * diff --git a/src/Contracts/RecordBuilderContract.php b/src/Contracts/RecordBuilderContract.php index dc0264a..53d438f 100644 --- a/src/Contracts/RecordBuilderContract.php +++ b/src/Contracts/RecordBuilderContract.php @@ -3,7 +3,6 @@ namespace Atproto\Contracts; use DateTimeImmutable; -use InvalidArgumentException; use stdClass; /** diff --git a/src/DataModel/Blob/BinaryBlobHandler.php b/src/DataModel/Blob/BinaryBlobHandler.php index 0753bfc..5f95024 100644 --- a/src/DataModel/Blob/BinaryBlobHandler.php +++ b/src/DataModel/Blob/BinaryBlobHandler.php @@ -2,9 +2,9 @@ namespace Atproto\DataModel\Blob; +use Atproto\Contracts\DataModel\BlobHandler; use Atproto\Exceptions\InvalidArgumentException; use finfo; -use Atproto\Contracts\DataModel\BlobHandler; class BinaryBlobHandler implements BlobHandler { diff --git a/src/DataModel/Blob/Blob.php b/src/DataModel/Blob/Blob.php index 26fca09..22e1ca8 100644 --- a/src/DataModel/Blob/Blob.php +++ b/src/DataModel/Blob/Blob.php @@ -2,12 +2,12 @@ namespace Atproto\DataModel\Blob; +use Atproto\Contracts\DataModel\BlobContract; +use Atproto\Contracts\DataModel\BlobHandler; use Atproto\IPFS\CID\CID; use Atproto\MultiFormats\MultiBase\MultiBase; use Atproto\MultiFormats\MultiCodec; use Atproto\Support\FileSupport; -use Atproto\Contracts\DataModel\BlobContract; -use Atproto\Contracts\DataModel\BlobHandler; class Blob implements BlobContract { diff --git a/src/DataModel/Blob/FileBlobHandler.php b/src/DataModel/Blob/FileBlobHandler.php index da04d2d..72bd326 100644 --- a/src/DataModel/Blob/FileBlobHandler.php +++ b/src/DataModel/Blob/FileBlobHandler.php @@ -2,9 +2,9 @@ namespace Atproto\DataModel\Blob; +use Atproto\Contracts\DataModel\BlobHandler; use Atproto\Exceptions\InvalidArgumentException; use Atproto\Support\FileSupport; -use Atproto\Contracts\DataModel\BlobHandler; class FileBlobHandler implements BlobHandler { diff --git a/src/Exceptions/InvalidArgumentException.php b/src/Exceptions/InvalidArgumentException.php index 4c80bfc..07900d8 100644 --- a/src/Exceptions/InvalidArgumentException.php +++ b/src/Exceptions/InvalidArgumentException.php @@ -2,8 +2,6 @@ namespace Atproto\Exceptions; -use Atproto\Exceptions\BlueskyException; - class InvalidArgumentException extends BlueskyException { } diff --git a/src/Lexicons/App/Bsky/RichText/Link.php b/src/Lexicons/App/Bsky/RichText/Link.php index 6f8fc19..f23945e 100644 --- a/src/Lexicons/App/Bsky/RichText/Link.php +++ b/src/Lexicons/App/Bsky/RichText/Link.php @@ -2,9 +2,6 @@ namespace Atproto\Lexicons\App\Bsky\RichText; -use Atproto\Contracts\Lexicons\App\Bsky\RichText\FacetContract; -use Atproto\Exceptions\InvalidArgumentException; - class Link extends FeatureAbstract { protected function schema(): array diff --git a/src/MultiFormats/MultiCodec.php b/src/MultiFormats/MultiCodec.php index ae68c02..0980971 100644 --- a/src/MultiFormats/MultiCodec.php +++ b/src/MultiFormats/MultiCodec.php @@ -2,7 +2,6 @@ namespace Atproto\MultiFormats; -use Atproto\Exceptions\InvalidArgumentException; use Atproto\Support\Enum; abstract class MultiCodec diff --git a/src/Resources/Assets/FollowersAsset.php b/src/Resources/Assets/FollowersAsset.php index 637fcc3..e42cf35 100644 --- a/src/Resources/Assets/FollowersAsset.php +++ b/src/Resources/Assets/FollowersAsset.php @@ -2,8 +2,8 @@ namespace Atproto\Resources\Assets; -use Atproto\Contracts\HTTP\Resources\AssetContract; use Atproto\Collections\Types\NonPrimitive\FollowerAssetType; +use Atproto\Contracts\HTTP\Resources\AssetContract; use GenericCollection\Exceptions\InvalidArgumentException; use GenericCollection\GenericCollection; use GenericCollection\Interfaces\TypeInterface; diff --git a/src/Resources/Assets/LabelsAsset.php b/src/Resources/Assets/LabelsAsset.php index 9894d25..d4a0944 100644 --- a/src/Resources/Assets/LabelsAsset.php +++ b/src/Resources/Assets/LabelsAsset.php @@ -2,8 +2,8 @@ namespace Atproto\Resources\Assets; -use Atproto\Contracts\HTTP\Resources\AssetContract; use Atproto\Collections\Types\NonPrimitive\LabelAssetType; +use Atproto\Contracts\HTTP\Resources\AssetContract; use GenericCollection\Exceptions\InvalidArgumentException; use GenericCollection\GenericCollection; use GenericCollection\Interfaces\TypeInterface; diff --git a/src/Support/Arr.php b/src/Support/Arr.php index d8777ab..01d3917 100644 --- a/src/Support/Arr.php +++ b/src/Support/Arr.php @@ -2,8 +2,6 @@ namespace Atproto\Support; -use ArrayAccess; - class Arr { /** diff --git a/src/Traits/Smith.php b/src/Traits/Smith.php index 21ebde5..37d36ae 100644 --- a/src/Traits/Smith.php +++ b/src/Traits/Smith.php @@ -5,7 +5,6 @@ use Atproto\Client; use Atproto\Contracts\HTTP\APIRequestContract; use Atproto\Contracts\Observer; -use Atproto\Contracts\RequestContract; use Atproto\Exceptions\Http\Request\RequestNotFoundException; trait Smith From d1458b155bfa60ab8151fdbd533f9d43234f37c7 Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Mon, 28 Oct 2024 02:12:04 +0400 Subject: [PATCH 41/58] Complete the implementation of the "GetFollowers" lexicon. - Removed unused Authentication logic from GetFollowers - Enhanced GetFollowersResource with SubjectAsset - Added SubjectAsset class for expanded resource support - Introduced feature test for GetFollowers functionality - Updated unit tests for authorization and missing field exceptions --- src/Lexicons/App/Bsky/Graph/GetFollowers.php | 10 ----- .../App/Bsky/Graph/GetFollowersResource.php | 2 + src/Resources/Assets/SubjectAsset.php | 11 +++++ .../App/Bsky/Graph/GetFollowersTest.php | 41 +++++++++++++++++++ .../App/Bsky/Graph/GetFollowersTest.php | 20 ++------- 5 files changed, 58 insertions(+), 26 deletions(-) create mode 100644 src/Resources/Assets/SubjectAsset.php create mode 100644 tests/Feature/Lexicons/App/Bsky/Graph/GetFollowersTest.php diff --git a/src/Lexicons/App/Bsky/Graph/GetFollowers.php b/src/Lexicons/App/Bsky/Graph/GetFollowers.php index eee5495..3e09dc3 100644 --- a/src/Lexicons/App/Bsky/Graph/GetFollowers.php +++ b/src/Lexicons/App/Bsky/Graph/GetFollowers.php @@ -5,17 +5,12 @@ use Atproto\Contracts\HTTP\Resources\ResourceContract; use Atproto\Contracts\RequestContract; use Atproto\Exceptions\Http\MissingFieldProvidedException; -use Atproto\Exceptions\Http\Response\AuthMissingException; use Atproto\Exceptions\InvalidArgumentException; use Atproto\Lexicons\APIRequest; -use Atproto\Lexicons\Traits\Authentication; use Atproto\Resources\App\Bsky\Graph\GetFollowersResource; -use Atproto\Support\Arr; class GetFollowers extends APIRequest { - use Authentication; - public function actor(string $actor = null) { if (is_null($actor)) { @@ -63,14 +58,9 @@ public function resource(array $data): ResourceContract /** * @throws MissingFieldProvidedException - * @throws AuthMissingException */ public function build(): RequestContract { - if (! Arr::exists($this->headers(false), 'Authorization')) { - throw new AuthMissingException(); - } - if (! $this->queryParameter('actor')) { throw new MissingFieldProvidedException('actor'); } diff --git a/src/Resources/App/Bsky/Graph/GetFollowersResource.php b/src/Resources/App/Bsky/Graph/GetFollowersResource.php index e97c562..0968e4c 100644 --- a/src/Resources/App/Bsky/Graph/GetFollowersResource.php +++ b/src/Resources/App/Bsky/Graph/GetFollowersResource.php @@ -5,6 +5,7 @@ use Atproto\Contracts\HTTP\Resources\ResourceContract; use Atproto\Resources\Assets\BaseAsset; use Atproto\Resources\Assets\FollowersAsset; +use Atproto\Resources\Assets\SubjectAsset; use Atproto\Resources\BaseResource; use Atproto\Traits\Castable; @@ -23,6 +24,7 @@ protected function casts(): array { return [ 'followers' => FollowersAsset::class, + 'subject' => SubjectAsset::class, ]; } } diff --git a/src/Resources/Assets/SubjectAsset.php b/src/Resources/Assets/SubjectAsset.php new file mode 100644 index 0000000..19cbd5e --- /dev/null +++ b/src/Resources/Assets/SubjectAsset.php @@ -0,0 +1,11 @@ +authenticate( + getenv('BLUESKY_IDENTIFIER'), + getenv('BLUESKY_PASSWORD'), + ); + } + + public function testGetFollowers() + { + $client = static::$client; + + $request = $client->app() + ->bsky() + ->graph() + ->getFollowers() + ->forge(); + + $request->actor($client->authenticated()->did()) + ->build(); + + $response = $request->send(); + + $this->assertSame($client->authenticated()->did(), $response->subject()->did()); + $this->assertInstanceOf(FollowersAsset::class, $response->followers()); + } +} diff --git a/tests/Unit/HTTP/API/Requests/App/Bsky/Graph/GetFollowersTest.php b/tests/Unit/HTTP/API/Requests/App/Bsky/Graph/GetFollowersTest.php index a12c961..0aefa6c 100644 --- a/tests/Unit/HTTP/API/Requests/App/Bsky/Graph/GetFollowersTest.php +++ b/tests/Unit/HTTP/API/Requests/App/Bsky/Graph/GetFollowersTest.php @@ -65,34 +65,22 @@ public function testCursorSetterAndGetter() $this->assertSame($cursor, $this->request->cursor(), 'Cursor getter should return the value set by the setter.'); } - public function testBuildThrowsExceptionWhenAuthorizationHeaderMissing() - { - $this->expectException(AuthMissingException::class); - $this->expectExceptionMessage('Authentication Required'); - - // Set required 'actor' parameter - $this->request->actor('testActor'); - - // Do not set 'Authorization' header - $this->request->build(); - } - public function testBuildThrowsExceptionWhenActorParameterMissing() { $this->expectException(MissingFieldProvidedException::class); $this->expectExceptionMessage("Missing fields provided: actor"); - // Set 'Authorization' header - $this->request->token('Bearer token'); - // Do not set 'actor' parameter $this->request->build(); } + /** + * @throws MissingFieldProvidedException + * @throws AuthMissingException + */ public function testBuildSucceedsWithRequiredParameters() { // Set required 'Authorization' header and 'actor' parameter - $this->request->token('Bearer token'); $this->request->actor('testActor'); // Should not throw any exceptions From 5a251ddb4320215062448cd956ef29c3ad5eba5e Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Mon, 28 Oct 2024 02:34:02 +0400 Subject: [PATCH 42/58] Complete the implementation of "CreateRecord" lexicon - Updated `CreateRecord::record()` to accept only `PostBuilderContract` type, updated type safety for record instances - Added validation in `CreateRecord::rkey()` to restrict `rkey` to a max of 15 characters, throwing `InvalidArgumentException` on failure - Adjusted unit tests to mock `PostBuilderContract` for compatibility with updated `record` method signature --- src/Lexicons/Com/Atproto/Repo/CreateRecord.php | 11 ++++++++++- .../Requests/Com/Atproto/Repo/CreateRecordTest.php | 7 ++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Lexicons/Com/Atproto/Repo/CreateRecord.php b/src/Lexicons/Com/Atproto/Repo/CreateRecord.php index 405aef3..de8fd71 100644 --- a/src/Lexicons/Com/Atproto/Repo/CreateRecord.php +++ b/src/Lexicons/Com/Atproto/Repo/CreateRecord.php @@ -4,8 +4,10 @@ use Atproto\Contracts\HTTP\Resources\ResourceContract; use Atproto\Contracts\LexiconContract; +use Atproto\Contracts\Lexicons\App\Bsky\Feed\PostBuilderContract; use Atproto\Contracts\RequestContract; use Atproto\Exceptions\Http\MissingFieldProvidedException; +use Atproto\Exceptions\InvalidArgumentException; use Atproto\Lexicons\APIRequest; use Atproto\Lexicons\Traits\Authentication; use Atproto\Resources\Com\Atproto\Repo\CreateRecordResource; @@ -49,12 +51,19 @@ public function collection(string $collection = null) return $this; } + /** + * @throws InvalidArgumentException + */ public function rkey(string $rkey = null) { if (is_null($rkey)) { return $this->parameter('rkey') ?? null; } + if (strlen($rkey) > 15) { + throw new InvalidArgumentException("The 'rkey' must be a maximum of 15 characters."); + } + $this->parameter('rkey', $rkey); return $this; @@ -71,7 +80,7 @@ public function validate(bool $validate = null) return $this; } - public function record(object $record = null) + public function record(PostBuilderContract $record = null) { if (is_null($record)) { return $this->parameter('record') ?? null; diff --git a/tests/Unit/HTTP/API/Requests/Com/Atproto/Repo/CreateRecordTest.php b/tests/Unit/HTTP/API/Requests/Com/Atproto/Repo/CreateRecordTest.php index 8a1da0c..25348b9 100644 --- a/tests/Unit/HTTP/API/Requests/Com/Atproto/Repo/CreateRecordTest.php +++ b/tests/Unit/HTTP/API/Requests/Com/Atproto/Repo/CreateRecordTest.php @@ -3,6 +3,7 @@ namespace Tests\Unit\HTTP\API\Requests\Com\Atproto\Repo; use Atproto\Client; +use Atproto\Contracts\Lexicons\App\Bsky\Feed\PostBuilderContract; use Atproto\Exceptions\Http\MissingFieldProvidedException; use Atproto\Lexicons\Com\Atproto\Repo\CreateRecord; use Faker\Factory; @@ -59,7 +60,7 @@ public function testRecord() { $this->assertNull($this->createRecord->record()); - $record = (object)['key' => 'value']; + $record = $this->createMock(PostBuilderContract::class); $this->createRecord->record($record); $this->assertEquals($record, $this->createRecord->record()); } @@ -80,7 +81,7 @@ public function testBuildWithAllRequiredFields() { $this->createRecord->repo($this->faker->word) ->collection($this->faker->word) - ->record((object)['key' => 'value']); + ->record($this->createMock(PostBuilderContract::class)); $result = $this->createRecord->build(); @@ -104,7 +105,7 @@ public function testChaining() ->collection($this->faker->word) ->rkey($this->faker->word) ->validate(true) - ->record((object)['key' => 'value']) + ->record($this->createMock(PostBuilderContract::class)) ->swapCommit($this->faker->word); $this->assertInstanceOf(CreateRecord::class, $result); From 7d5f1cf298e083d927abd1f52d4e08c051b24fdc Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Wed, 30 Oct 2024 15:56:45 +0400 Subject: [PATCH 43/58] Rename and remove the old API --- src/API/App/Bsky/Actor/GetProfile.php | 161 --------- src/API/Com/Atrproto/Repo/CreateRecord.php | 324 ------------------ src/API/Com/Atrproto/Repo/UploadBlob.php | 174 ---------- src/API/Traits/ResourceSupport.php | 14 - .../Strategies/PasswordAuthentication.php | 94 ----- src/Builders/Bluesky/RecordBuilder.php | 232 ------------- src/Clients/BlueskyClient.php | 279 --------------- src/Contracts/AuthStrategyContract.php | 19 - src/Contracts/BuilderInterface.php | 8 - src/Contracts/ClientContract.php | 25 -- src/Contracts/HTTP/RequestContract.php | 53 --- .../{HTTP => Lexicons}/APIRequestContract.php | 3 +- .../{ => Lexicons}/RequestContract.php | 2 +- src/Contracts/RecordBuilderContract.php | 102 ------ .../{HTTP => }/Resources/AssetContract.php | 2 +- .../{HTTP => }/Resources/ResourceContract.php | 2 +- src/DataModel/Blob/Blob.php | 4 +- src/Exceptions/Auth/AuthFailed.php | 13 - .../Http/InvalidRequestException.php | 13 - .../RequestBodyHasMissingRequiredFields.php | 25 -- .../Http/Token/ExpiredTokenException.php | 13 - .../Http/Token/InvalidTokenException.php | 13 - src/Exceptions/Http/UnsupportedHTTPMethod.php | 10 - src/Exceptions/RuntimeException.php | 7 - src/IPFS/CID/CID.php | 4 +- src/IPFS/CID/Versions/CIDV1.php | 4 +- .../MultiBase/Encoders/Base32Encoder.php | 2 +- .../MultiBase/Encoders/MultiBaseSupport.php | 2 +- .../MultiFormats/MultiBase/MultiBase.php | 4 +- src/{ => IPFS}/MultiFormats/MultiCodec.php | 2 +- src/{ => IPFS}/MultiFormats/MultiHash.php | 2 +- src/Lexicons/APIRequest.php | 4 +- src/Lexicons/App/Bsky/Actor/GetProfile.php | 4 +- src/Lexicons/App/Bsky/Actor/GetProfiles.php | 4 +- src/Lexicons/App/Bsky/Graph/GetFollowers.php | 4 +- .../Com/Atproto/Repo/CreateRecord.php | 4 +- src/Lexicons/Com/Atproto/Repo/UploadBlob.php | 4 +- .../Com/Atproto/Server/CreateSession.php | 4 +- src/Lexicons/Request.php | 2 +- src/Lexicons/Traits/RequestHandler.php | 2 +- .../App/Bsky/Actor/GetProfileResource.php | 2 +- .../App/Bsky/Actor/GetProfilesResource.php | 2 +- .../App/Bsky/Graph/GetFollowersResource.php | 2 +- src/Resources/Assets/AssociatedAsset.php | 4 +- src/Resources/Assets/BaseAsset.php | 2 +- src/Resources/Assets/BlockingByListAsset.php | 4 +- src/Resources/Assets/ChatAsset.php | 4 +- src/Resources/Assets/CollectionAsset.php | 2 +- src/Resources/Assets/CreatorAsset.php | 4 +- src/Resources/Assets/DatetimeAsset.php | 2 +- src/Resources/Assets/FollowerAsset.php | 4 +- src/Resources/Assets/FollowersAsset.php | 2 +- .../Assets/JoinedViaStarterPackAsset.php | 4 +- src/Resources/Assets/KnownFollowersAsset.php | 2 +- src/Resources/Assets/LabelAsset.php | 4 +- src/Resources/Assets/LabelsAsset.php | 2 +- src/Resources/Assets/MutedByListAsset.php | 4 +- src/Resources/Assets/ProfileAsset.php | 4 +- src/Resources/Assets/ProfilesAsset.php | 2 +- src/Resources/Assets/SubjectAsset.php | 4 +- src/Resources/Assets/ViewerAsset.php | 4 +- src/Resources/BaseResource.php | 2 +- .../Com/Atproto/Repo/CreateRecordResource.php | 2 +- .../Com/Atproto/Repo/UploadBlobResource.php | 2 +- .../Atproto/Server/CreateSessionResource.php | 2 +- src/Traits/Smith.php | 2 +- tests/Feature/BlueskyClientTest.php | 286 ---------------- tests/Feature/ClientTest.php | 2 +- .../App/Bsky/Actor/GetProfilesTest.php | 116 ------- tests/Supports/NonPrimitiveAssetTest.php | 2 +- tests/Unit/ClientTest.php | 2 +- tests/Unit/DataModel/Blob/BlobTest.php | 4 +- tests/Unit/IPFS/CID/CIDTest.php | 6 +- .../{HTTP/API => Lexicons}/APIRequestTest.php | 2 +- .../App/Bsky/Actor/GetProfileTest.php | 6 +- .../App/Bsky/Actor/GetProfilesTest.php | 2 +- .../App/Bsky/Graph/GetFollowersTest.php | 4 +- .../Com/Atproto/Repo/CreateRecordTest.php | 2 +- .../Com/Atproto/Repo/UploadBlobTest.php | 2 +- tests/Unit/{HTTP => Lexicons}/RequestTest.php | 4 +- .../App/Bsky/Actor/GetProfileResourceTest.php | 2 +- tests/Unit/Resources/Assets/BaseAssetTest.php | 2 +- .../Resources/Assets/CollectionAssetTest.php | 2 +- .../Resources/Assets/FollowersAssetTest.php | 2 +- tests/Unit/Resources/BaseResourceTest.php | 4 +- 85 files changed, 94 insertions(+), 2076 deletions(-) delete mode 100644 src/API/App/Bsky/Actor/GetProfile.php delete mode 100644 src/API/Com/Atrproto/Repo/CreateRecord.php delete mode 100644 src/API/Com/Atrproto/Repo/UploadBlob.php delete mode 100644 src/API/Traits/ResourceSupport.php delete mode 100644 src/Auth/Strategies/PasswordAuthentication.php delete mode 100644 src/Builders/Bluesky/RecordBuilder.php delete mode 100644 src/Clients/BlueskyClient.php delete mode 100644 src/Contracts/AuthStrategyContract.php delete mode 100644 src/Contracts/BuilderInterface.php delete mode 100644 src/Contracts/ClientContract.php delete mode 100644 src/Contracts/HTTP/RequestContract.php rename src/Contracts/{HTTP => Lexicons}/APIRequestContract.php (81%) rename src/Contracts/{ => Lexicons}/RequestContract.php (98%) delete mode 100644 src/Contracts/RecordBuilderContract.php rename src/Contracts/{HTTP => }/Resources/AssetContract.php (68%) rename src/Contracts/{HTTP => }/Resources/ResourceContract.php (93%) delete mode 100644 src/Exceptions/Auth/AuthFailed.php delete mode 100644 src/Exceptions/Http/InvalidRequestException.php delete mode 100644 src/Exceptions/Http/Request/RequestBodyHasMissingRequiredFields.php delete mode 100644 src/Exceptions/Http/Token/ExpiredTokenException.php delete mode 100644 src/Exceptions/Http/Token/InvalidTokenException.php delete mode 100644 src/Exceptions/Http/UnsupportedHTTPMethod.php delete mode 100644 src/Exceptions/RuntimeException.php rename src/{ => IPFS}/MultiFormats/MultiBase/Encoders/Base32Encoder.php (96%) rename src/{ => IPFS}/MultiFormats/MultiBase/Encoders/MultiBaseSupport.php (87%) rename src/{ => IPFS}/MultiFormats/MultiBase/MultiBase.php (80%) rename src/{ => IPFS}/MultiFormats/MultiCodec.php (84%) rename src/{ => IPFS}/MultiFormats/MultiHash.php (94%) delete mode 100644 tests/Feature/BlueskyClientTest.php delete mode 100644 tests/Feature/HTTP/API/Requests/App/Bsky/Actor/GetProfilesTest.php rename tests/Unit/{HTTP/API => Lexicons}/APIRequestTest.php (97%) rename tests/Unit/{HTTP/API/Requests => Lexicons}/App/Bsky/Actor/GetProfileTest.php (95%) rename tests/Unit/{HTTP/API/Requests => Lexicons}/App/Bsky/Actor/GetProfilesTest.php (98%) rename tests/Unit/{HTTP/API/Requests => Lexicons}/App/Bsky/Graph/GetFollowersTest.php (97%) rename tests/Unit/{HTTP/API/Requests => Lexicons}/Com/Atproto/Repo/CreateRecordTest.php (98%) rename tests/Unit/{HTTP/API/Requests => Lexicons}/Com/Atproto/Repo/UploadBlobTest.php (97%) rename tests/Unit/{HTTP => Lexicons}/RequestTest.php (98%) diff --git a/src/API/App/Bsky/Actor/GetProfile.php b/src/API/App/Bsky/Actor/GetProfile.php deleted file mode 100644 index ae969dc..0000000 --- a/src/API/App/Bsky/Actor/GetProfile.php +++ /dev/null @@ -1,161 +0,0 @@ - "application/json" - ]; - - /** - * Constructs a new GetProfile instance. - */ - public function __construct() - { - $this->body = (object) [ - 'actor' => '', - ]; - } - - /** - * Sets the actor to be performed. - * - * @param string $actor The 'actor' to be set - * - * @throws InvalidArgumentException if $actor is not a string - */ - public function setActor($actor) - { - if (! is_string($actor)) { - throw new InvalidArgumentException("'actor' must be a string"); - } - - $this->body->actor = $actor; - } - - /** - * Retrieves the 'actor' that has been set. - * - * @return string The 'actor' field value - */ - public function getActor() - { - return $this->body->actor; - } - - /** - * Sets the request headers. - * - * @param array $headers The headers to be set - * - * @return $this - */ - public function setHeaders(array $headers) - { - $this->headers = array_diff_key( - $this->headers, - array_flip(array_keys($headers)) - ); - - $this->headers = array_merge( - $this->headers, - $headers - ); - - return $this; - } - - /** - * Retrieves the request headers. - * - * @return array The request headers - */ - public function getHeaders() - { - return $this->headers; - } - - /** - * Retrieves the HTTP method for the request. - * - * @return string The HTTP method - */ - public function getMethod() - { - return 'GET'; - } - - /** - * Retrieves the URI for the request. - * - * @return string The URI - */ - public function getUri() - { - return '/app.bsky.actor.getProfile'; - } - - /** - * Indicates whether authentication is required for the request. - * - * @return bool true if authentication is required, false otherwise - */ - public function authRequired() - { - return true; - } - - /** - * Boots the request with authentication response. - * - * @param mixed $authResponse The authentication response - */ - public function boot($authResponse) - { - $this->headers = array_merge($this->headers, [ - 'Authorization' => "Bearer $authResponse->accessJwt" - ]); - } - - /** - * Retrieves the request body. - * - * @return mixed The request body - * - * @throws RequestBodyHasMissingRequiredFields if the request body is missing required fields - */ - public function getBody() - { - if (! isset($this->body->actor)) { - throw new RequestBodyHasMissingRequiredFields('actor'); - } - - return ['actor' => $this->body->actor]; - } - - public function resource(array $response): ResourceContract - { - return new GetProfileResource($response); - } -} diff --git a/src/API/Com/Atrproto/Repo/CreateRecord.php b/src/API/Com/Atrproto/Repo/CreateRecord.php deleted file mode 100644 index 99cfa3c..0000000 --- a/src/API/Com/Atrproto/Repo/CreateRecord.php +++ /dev/null @@ -1,324 +0,0 @@ - 'application/json', - 'Content-Type' => 'application/json', - ]; - - public function __construct() - { - trigger_error( - "This class deprecated and will be removed in a future version.", - E_USER_DEPRECATED - ); - - $this->body = (object) [ - 'repo' => '', - 'rkey' => '', - 'validate' => true, - 'record' => [], - 'collection' => 'app.bsky.feed.post', - 'swapCommit' => '', - ]; - } - - /** - * Set the repository for the record. - * - * @param string $repo The repository name - * @return $this - * @throws InvalidArgumentException If $repo is not a string - */ - public function setRepo($repo) - { - if (!is_string($repo)) { - throw new InvalidArgumentException("'repo' must be a string"); - } - - $this->body->repo = $repo; - - return $this; - } - - /** - * Get the repository for the record. - * - * @return string The repository name - */ - public function getRepo() - { - return $this->body->repo; - } - - /** - * Set the key for the record. - * - * @param string $rkey The record key - * @return $this - * @throws InvalidArgumentException If $rkey is not a string or its length is invalid - */ - public function setRkey($rkey) - { - if (! is_string($rkey)) { - throw new InvalidArgumentException("'key' must be a string"); - } - - if (strlen($rkey) > 15 || 1 > strlen($rkey)) { - throw new InvalidArgumentException("'key' length must be between 1 and 15 characters"); - } - - $this->body->rkey = $rkey; - - return $this; - } - - /** - * Get the key for the record. - * - * @return string The record key - */ - public function getRkey() - { - return $this->body->rkey; - } - - /** - * Set whether to validate the record. - * - * @param bool $validate Whether to validate the record - * @return $this - * @throws InvalidArgumentException If $validate is not a boolean - */ - public function setValidate($validate) - { - if (! is_bool($validate)) { - throw new InvalidArgumentException("'validate' must be a boolean"); - } - - $this->body->validate = $validate; - - return $this; - } - - /** - * Get whether to validate the record. - * - * @return bool Whether to validate the record - */ - public function getValidate() - { - return $this->body->validate; - } - - /** - * Set the record data. - * - * @param RecordBuilderContract $record The record data - * @return $this - * @throws InvalidArgumentException If the record data is invalid - */ - public function setRecord(RecordBuilderContract $record) - { - $this->body->record = $record->buildRecord(); - - return $this; - } - - /** - * Get the record data. - * - * @return array The record data - */ - public function getRecord() - { - return $this->body->record; - } - - /** - * Set the collection to store the record in. - * - * @param string $collection The collection name - * @return $this - * @throws InvalidArgumentException If $collection is not a string or it is not one of the acceptable collections - */ - public function setCollection($collection) - { - $acceptableCollections = [ - 'app.bsky.feed.post', - 'app.bsky.feed.like', - 'app.bsky.actor.profile', - 'app.bsky.graph.follow' - ]; - - if (! is_string($collection)) { - throw new InvalidArgumentException("'collection' must be a string"); - } - - if (! in_array($collection, $acceptableCollections)) { - throw new InvalidArgumentException("'collection' must be one of '" . implode("', '", $acceptableCollections) . "'"); - } - - $this->body->collection = $collection; - - return $this; - } - - /** - * Get the collection to store the record in. - * - * @return string The collection name - */ - public function getCollection() - { - return $this->body->collection; - } - - /** - * Set the swap commit. - * - * @param mixed $swapCommit The swap commit value - * @return $this - */ - public function swapCommit($swapCommit) - { - $this->body->swapCommit = $swapCommit; - - return $this; - } - - /** - * Get the swap commit. - * - * @return mixed The swap commit value - */ - public function getSwapCommit() - { - return $this->body->swapCommit; - } - - /** - * Get the URI for the request. - * - * @return string The URI - */ - public function getUri() - { - return '/com.atproto.repo.createRecord'; - } - - /** - * Get the HTTP method for the request. - * - * @return string The HTTP method - */ - public function getMethod() - { - return 'POST'; - } - - /** - * Get the headers for the request. - * - * @return array The headers - */ - public function getHeaders() - { - return $this->headers; - } - - /** - * Set the headers for the request. - * - * @param array $headers The header/s for the request. - * @return $this - */ - public function setHeaders(array $headers) - { - $this->headers = array_diff_key( - $this->headers, - array_flip(array_keys($headers)) - ); - - $this->headers = array_merge( - $this->headers, - $headers - ); - - return $this; - } - - /** - * Get the body for the request. - * - * @return string The body - * @throws RequestBodyHasMissingRequiredFields If required fields are missing in the body - */ - public function getBody() - { - $fields = array_filter([ - 'repo' => $this->body->repo, - 'rkey' => $this->body->rkey, - 'validate' => $this->body->validate, - 'record' => $this->body->record, - 'collection' => $this->body->collection, - 'swapCommit' => $this->body->swapCommit, - ]); - - $requiredFields = [ - 'repo', - 'record', - 'collection' - ]; - - $missingFields = array_diff( - $requiredFields, - array_keys($fields) - ); - - if (! empty($missingFields)) { - throw new RequestBodyHasMissingRequiredFields(implode(', ', $missingFields)); - } - - return json_encode($fields); - } - - /** - * Check if authentication is required for the request. - * - * @return bool True if authentication is required, false otherwise - */ - public function authRequired() - { - return true; - } - - /** - * Boot the request with authentication response. - * - * @param mixed $authResponse The authentication response - */ - public function boot($authResponse) - { - $this->headers = array_merge($this->headers, [ - "Authorization" => "Bearer $authResponse->accessJwt" - ]); - - $this->body->repo = $authResponse->did; - } -} diff --git a/src/API/Com/Atrproto/Repo/UploadBlob.php b/src/API/Com/Atrproto/Repo/UploadBlob.php deleted file mode 100644 index 53c9cdd..0000000 --- a/src/API/Com/Atrproto/Repo/UploadBlob.php +++ /dev/null @@ -1,174 +0,0 @@ - '*/*', - 'Accept' => 'application/json', - ]; - - /** - * The class constructor. - * - * @return void - */ - public function __construct() - { - trigger_error( - "This class deprecated and will be removed in a future version.", - E_USER_DEPRECATED - ); - - $this->body = (object) []; - } - - /** - * Set the blob content. - * - * @param string $filePath The path to the blob file. - * @return $this - * @throws InvalidArgumentException If the blob path is invalid or blob size exceeds the maximum allowed. - */ - public function setBlob($filePath) - { - $file = new FileSupport($filePath); - - if (! $file->exists()) { - throw new InvalidArgumentException("File '$filePath' does not exist"); - } - - if (! $file->isFile()) { - throw new InvalidArgumentException("File '$filePath' is not a file"); - } - - $maxSize = 1000000; - if ($file->getFileSize() > $maxSize) { - throw new InvalidArgumentException("File '$filePath' is too big. Max file size is $maxSize bytes."); - } - - $this->body->blob = $file; - - return $this; - } - - /** - * Get the blob content. - * - * @return ?FileSupport The blob content. - */ - public function getBlob() - { - return $this->body->blob; - } - - /** - * Get the body of the request. - * - * @return array The body of the request. - * @throws RequestBodyHasMissingRequiredFields If the blob field is missing. - */ - public function getBody() - { - if (! isset($this->body->blob)) { - throw new RequestBodyHasMissingRequiredFields(implode(', ', ['blob'])); - } - - return $this->body - ->blob - ->getBlob(); - } - - /** - * Get the headers for the request. - * - * @return array The headers for the request. - */ - public function getHeaders() - { - return $this->headers; - } - - /** - * Set the headers for the request. - * - * @param array $headers The header/s for the request. - * @return $this - */ - public function setHeaders(array $headers) - { - $this->headers = array_diff_key( - $this->headers, - array_flip(array_keys($headers)) - ); - - $this->headers = array_merge( - $this->headers, - $headers - ); - - return $this; - } - - /** - * Get the HTTP method for the request. - * - * @return string The HTTP method for the request. - */ - public function getMethod() - { - return 'POST'; - } - - /** - * Get the URI for the request. - * - * @return string The URI for the request. - */ - public function getUri() - { - return '/com.atproto.repo.uploadBlob'; - } - - /** - * Check if authentication is required for the request. - * - * @return bool True if authentication is required, false otherwise. - */ - public function authRequired() - { - return true; - } - - /** - * Boot the request with authentication response. - * - * @param object $authResponse The authentication response. - */ - public function boot($authResponse) - { - $this->headers = array_merge($this->headers, [ - 'Authorization' => "Bearer $authResponse->accessJwt" - ]); - } -} diff --git a/src/API/Traits/ResourceSupport.php b/src/API/Traits/ResourceSupport.php deleted file mode 100644 index 6b428b4..0000000 --- a/src/API/Traits/ResourceSupport.php +++ /dev/null @@ -1,14 +0,0 @@ -validateCredentials($credentials); - $this->credentials = $this->filterCredentials($credentials); - } - - /** - * Validate the provided credentials. - * - * @param array $credentials The credentials to validate - * @throws InvalidArgumentException If required credentials are missing - */ - private function validateCredentials(array $credentials) - { - if (!isset($credentials['identifier']) || !isset($credentials['password'])) { - throw new InvalidArgumentException("Both 'identifier' and 'password' must be provided in credentials"); - } - } - - /** - * Filter the provided credentials to contain only necessary keys. - * - * @param array $credentials The credentials to filter - * @return array Filtered credentials containing only 'identifier' and 'password' - */ - private function filterCredentials(array $credentials) - { - return array_intersect_key( - $credentials, - array_flip(['identifier', 'password']) - ); - } - - /** - * Authenticate using the provided credentials. - * - * @param array $credentials The credentials for authentication - * @return mixed The authentication result - * @throws AuthFailed If authentication fails - */ - public function authenticate(array $credentials) - { - $this->init($credentials); - - $ch = curl_init(); - - curl_setopt_array($ch, [ - CURLOPT_URL => 'https://bsky.social/xrpc/com.atproto.server.createSession', - CURLOPT_RETURNTRANSFER => true, - CURLOPT_POST => true, - CURLOPT_POSTFIELDS => json_encode($this->credentials), - CURLOPT_HTTPHEADER => [ - 'Content-Type: application/json', - 'Accept: application/json', - ], - ]); - - $response = curl_exec($ch); - $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); - curl_close($ch); - - if ($statusCode !== 200) { - throw new AuthFailed("Authentication failed: " . ($response ? json_decode($response)->message : "Unknown error")); - } - - return json_decode($response); - } -} diff --git a/src/Builders/Bluesky/RecordBuilder.php b/src/Builders/Bluesky/RecordBuilder.php deleted file mode 100644 index a4bffd6..0000000 --- a/src/Builders/Bluesky/RecordBuilder.php +++ /dev/null @@ -1,232 +0,0 @@ -record = new stdClass(); - $this->record->text = ""; - - return $this; - } - - /** - * Adds text to the record. - * - * @param string $text The text to be added. - * - * @return $this - * @throws InvalidArgumentException - * - * @deprecated This method deprecated and will be removed in a future version. Use `text()` instead. - */ - public function addText($text) - { - trigger_error( - "This method deprecated and will be removed in a future version. Use `text()` instead.", - E_USER_DEPRECATED - ); - - if (! is_string($text)) { - throw new InvalidArgumentException("'text' must be string"); - } - - $this->record->text = (string) $this->record->text . "$text\n"; - - preg_match_all( - self::$urlRegex, - (string) $this->record->text, - $urlMatches, - PREG_OFFSET_CAPTURE - ); - - if (! empty($urlMatches)) { - $this->record->facets = []; - } - - foreach($urlMatches[0] as $match) { - $url = $match[0]; - $startPos = $match[1]; - $endPos = $startPos + strlen($url); - - $this->record->facets[] = [ - "index" => [ - "byteStart" => $startPos, - "byteEnd" => $endPos, - ], - "features" => [ - [ - "\$type" => "app.bsky.richtext.facet#link", - "uri" => $url - ] - ] - ]; - } - - return $this; - } - - public function text($text) - { - return $this->addText($text); - } - - /** - * Adds type to the record. - * - * @param string $type The type to be added. - * - * @return $this - * @throws InvalidArgumentException - * - * @deprecated This method deprecated and will be removed in a future version. Use `type()` instead. - */ - public function addType($type = 'app.bsky.feed.post') - { - trigger_error( - "This method deprecated and will be removed in a future version. Use `type()` instead.", - E_USER_DEPRECATED - ); - - if (! is_string($type)) { - throw new InvalidArgumentException("'type' must be string"); - } - - $acceptedTypes = ['app.bsky.feed.post']; - - if (! in_array($type, $acceptedTypes)) { - throw new InvalidArgumentException( - "'$type' is not a valid for 'type' value. It can only be one of the following: " . implode(', ', $acceptedTypes) - ); - } - - $this->record->type = $type; - - return $this; - } - - public function type($type = 'app.bsky.feed.post') - { - return $this->addType($type); - } - - /** - * Adds creation date to the record. - * - * @param DateTimeImmutable|null $createdAt The creation date to be added. - * - * @return $this - * @throws InvalidArgumentException - * - * @deprecated This method deprecated and will be removed in a future version. Use `createdAt()` instead. - */ - public function addCreatedAt($createdAt = null) - { - trigger_error( - "This method deprecated and will be removed in a future version. Use `createdAt()` instead.", - E_USER_DEPRECATED - ); - - if (! is_null($createdAt)) { - $createdAt = $createdAt->format('c'); - } else { - $createdAt = date('c'); - } - - $this->record->createdAt = $createdAt; - - return $this; - } - - public function createdAt(DateTimeImmutable $createdAt = null) - { - return $this->addCreatedAt($createdAt); - } - - /** - * Adds image to the record. - * - * @param string $blob The image blob. - * @param string $alt The alternative text for the image. - * - * @return $this - * @throws InvalidArgumentException - * - * @deprecated This method deprecated and will be removed in a future version. Use `image()` instead. - */ - public function addImage($blob, $alt = "") - { - trigger_error( - "This method deprecated and will be removed in a future version. Use `image()` instead.", - E_USER_DEPRECATED - ); - - if (! is_string($alt)) { - throw new InvalidArgumentException("'alt' must be a string"); - } - - if (! isset($this->record->embed)) { - $this->record->embed = (object) [ - "\$type" => "app.bsky.embed.images", - "images" => [] - ]; - } - - $this->record->embed->images[] = [ - "image" => $blob, - "alt" => $alt - ]; - - return $this; - } - - public function image($blob, $alt = "") - { - return $this->addImage($blob, $alt); - } - - /** - * Builds the record. - * - * @return stdClass The built record. - * - * @deprecated This method deprecated and will be removed in a future version. Use `build()` instead. - */ - public function buildRecord() - { - trigger_error( - "This method deprecated and will be removed in a future version. Use `build()` instead.", - E_USER_DEPRECATED - ); - - return $this->record; - } - - - public function build() - { - return $this->buildRecord(); - } -} diff --git a/src/Clients/BlueskyClient.php b/src/Clients/BlueskyClient.php deleted file mode 100644 index cfa6fd4..0000000 --- a/src/Clients/BlueskyClient.php +++ /dev/null @@ -1,279 +0,0 @@ -url = $url; - $this->request = $requestContract; - $this->authenticated = (object) []; - $this->authStrategy = new PasswordAuthentication(); - } - - /** - * Set the authentication strategy for the client. - * - * @param AuthStrategyContract $strategyContract The authentication strategy - * @return $this - * - * @deprecated This method is deprecated and will be removed in a future version. - * Authentication should be handled directly via `authenticate()` with credentials. - */ - public function setStrategy(AuthStrategyContract $strategyContract) - { - trigger_error( - "This method is deprecated and will be removed in a future version. Authentication should be handled directly via `authenticate()` with credentials.", - E_USER_DEPRECATED - ); - - $this->authStrategy = $strategyContract; - return $this; - } - - /** - * Set the request object for the client. - * - * @param RequestContract $requestContract The request object - * @return $this - */ - public function setRequest(RequestContract $requestContract) - { - $this->request = $requestContract; - return $this; - } - - /** - * Authenticate the client with provided credentials. - * - * @param array $credentials The authentication credentials - * @return mixed The authentication result - * @throws RuntimeException If $authStrategy is not set - * @throws AuthFailed If authentication failed - */ - public function authenticate($credentials) - { - if (! $this->authStrategy) { - throw new RuntimeException("You must set an authentication strategy first"); - } - - $this->authenticated = $this->authStrategy - ->authenticate($credentials); - - return $this->authenticated; - } - - /** - * Execute the request. - * - * @return object The response from the API - * @throws cURLException If cURL request fails - * @throws InvalidRequestException If the API request is invalid - * @throws InvalidTokenException If the token used for authentication is invalid - * @throws ExpiredTokenException If the token used for authentication has expired - * @throws AuthRequired If authentication is required for the request but not provided - * @throws UnsupportedHTTPMethod If the HTTP method specified in the request is not supported - * - * @deprecated This method will be renamed in the future for simplicity and to shorten method names. Use 'send()' - * instead. - */ - public function execute(): object - { - trigger_error( - "This method will be renamed in the future for simplicity and to shorten method names. Use 'send()' instead.", - E_USER_DEPRECATED - ); - - if ($this->request->authRequired() && empty($this->authenticated)) { - throw new AuthRequired("You must be authenticated to use this method"); - } - - $this->request->boot($this->authenticated); - - return $this->sendRequest($this->request); - } - - /** - * @throws UnsupportedHTTPMethod - * @throws cURLException - * @throws AuthRequired - * @throws InvalidRequestException - * @throws InvalidTokenException - * @throws ExpiredTokenException - * - * @return ResourceContract|object - */ - public function send(): object - { - if (! in_array(ResourceSupport::class, class_uses($this->request))) { - return $this->execute(); - } - - $response = json_decode( - json_encode($this->execute()), - true - ); - - return $this->request->resource($response); - } - - /** - * Get the request object associated with this client. - * - * @return RequestContract The request object - * - * @deprecated This method will be removed in a future version. Directly manipulate the request object before passing it to the client. Use the appropriate request methods for setting data instead of relying on this method. - */ - public function getRequest() - { - trigger_error( - "The 'getRequest()' method is deprecated and will be removed in a future version. Instead of using this method, please manipulate the request object directly before passing it to the client. Use the request-specific methods to set or modify data as needed.", - E_USER_DEPRECATED - ); - - return $this->request; - } - - /** - * Send the API request. - * - * @param RequestContract $request The request object - * @return object The response from the API - * @throws cURLException If cURL request fails - * @throws InvalidTokenException If the token used for authentication is invalid - * @throws InvalidRequestException If the API request is invalid - * @throws ExpiredTokenException If the token used for authentication has expired - * @throws UnsupportedHTTPMethod If the HTTP method specified in the request is not supported - */ - private function sendRequest($request): object - { - $curl = curl_init(); - - $headers = $request->getHeaders(); - array_walk($headers, function (&$value, $key) { - $value = sprintf('%s: %s', $key, $value); - }); - - curl_setopt_array($curl, [ - CURLOPT_URL => $this->url . $request->getURI(), - CURLOPT_RETURNTRANSFER => true, - CURLOPT_HTTPHEADER => $headers, - ]); - - $this->setRequestMethod($curl, $request); - - $response = curl_exec($curl); - - if (curl_errno($curl)) { - throw new cURLException(curl_error($curl)); - } - - $response = json_decode($response); - - if (curl_getinfo($curl, CURLINFO_HTTP_CODE) != 200) { - switch ($response->error) { - case "InvalidToken": - throw new InvalidTokenException( - $response->message - ); - - case "InvalidRequest": - throw new InvalidRequestException( - $response->message - ); - - case "ExpiredToken": - throw new ExpiredTokenException( - $response->message - ); - } - } - - curl_close($curl); - - return $response; - } - - /** - * Sets the request method for the cURL handle based on the HTTP method specified in the request object. - * - * @param resource $curl The cURL handle - * @param RequestContract $request The request object - * - * @throws UnsupportedHTTPMethod if the HTTP method specified in the request is not supported - */ - private function setRequestMethod($curl, $request) - { - switch ($request->getMethod()) { - case "POST": - curl_setopt_array($curl, [ - CURLOPT_POST => true, - CURLOPT_POSTFIELDS => $request->getBody(), - ]); - break; - case "GET": - curl_setopt( - $curl, - CURLOPT_URL, - sprintf( - '%s%s?%s', - $this->url, - $request->getUri(), - http_build_query($request->getBody()) - ) - ); - break; - default: - throw new UnsupportedHTTPMethod( - "The package does not support this method: " . $request->getMethod() - ); - } - } -} diff --git a/src/Contracts/AuthStrategyContract.php b/src/Contracts/AuthStrategyContract.php deleted file mode 100644 index bf4cf59..0000000 --- a/src/Contracts/AuthStrategyContract.php +++ /dev/null @@ -1,19 +0,0 @@ -getProperty('url'); - $property->setAccessible(true); - - $url = $property->getValue($client); - - $this->assertIsString($url); - $this->assertEquals('https://bsky.social/xrpc', $url); - } - - // Test constructor with custom URL - public function testConstructorWithCustomURL() - { - $expected = "https://shahmal1yev.com/api"; - $client = new BlueskyClient(new CreateRecord(), $expected); - - $reflection = new \ReflectionClass(BlueskyClient::class); - $property = $reflection->getProperty('url'); - $property->setAccessible(true); - - $url = $property->getValue($client); - - $this->assertIsString($url); - $this->assertEquals($expected, $url); - } - - // Test getRequest method - public function testGetRequestMethod() - { - $request = new CreateRecord(); - $client = new BlueskyClient($request); - - $this->assertInstanceOf(RequestContract::class, $client->getRequest()); - $this->assertInstanceOf(CreateRecord::class, $client->getRequest()); - $this->assertSame($request, $client->getRequest()); - } - - // Test authenticate method with valid credentials - public function testAuthenticateWithValidCredentials() - { - $client = new BlueskyClient(new CreateRecord()); - $client->setStrategy(new PasswordAuthentication()); - - $authenticated = $client->authenticate([ - 'identifier' => $_ENV["BLUESKY_IDENTIFIER"], - 'password' => $_ENV["BLUESKY_PASSWORD"] - ]); - - $this->assertIsObject($authenticated); - $this->assertNotNull($authenticated); - $this->assertIsString($authenticated->did); - $this->assertIsString($authenticated->accessJwt); - } - - // Test authenticate method with invalid credentials - public function testAuthenticateWithInvalidCredentials() - { - $this->expectException(AuthFailed::class); - $this->expectExceptionMessage("Authentication failed: "); - - $client = new BlueskyClient(new CreateRecord()); - $client->setStrategy(new PasswordAuthentication()); - - $client->authenticate([ - 'identifier' => 'invalid identifier', - 'password' => 'invalid password' - ]); - } - - // Test execute method with CreateRecord - public function testExecuteWithCreateRecord() - { - $request = new CreateRecord(); - - $recordBuilder = (new RecordBuilder()) - ->addText("Hello World! I am posted from PHP Unit tests for testing this URL adding to this post: \n1. https://www.fs-poster.com \n2. https://github.com/shahmal1yev/blueskysdk \n3. https://github.com/easypay/php-yigim") - ->addType() - ->addCreatedAt(); - - $request->setRecord($recordBuilder); - - $client = new BlueskyClient($request); - - $client->setStrategy(new PasswordAuthentication()) - ->authenticate([ - 'identifier' => $_ENV["BLUESKY_IDENTIFIER"], - 'password' => $_ENV["BLUESKY_PASSWORD"] - ]); - - $response = $client->execute(); - - $this->assertIsObject($response); - $this->assertNotEmpty($response); - $this->assertIsString($response->uri); - $this->assertIsString($response->cid); - } - - // Test execute method with UploadBlob - public function testExecuteWithUploadBlob() - { - $client = new BlueskyClient(new UploadBlob()); - - $client->setStrategy(new PasswordAuthentication()) - ->authenticate([ - 'identifier' => $_ENV["BLUESKY_IDENTIFIER"], - 'password' => $_ENV["BLUESKY_PASSWORD"] - ]); - - $client->getRequest()->setBlob('art/file.png'); - - $response = $client->execute(); - - $this->assertIsObject($response); - $this->assertNotEmpty($response); - } - - // Test execute method with GetProfile - public function testExecuteWithGetProfile() - { - $client = new BlueskyClient(new GetProfile()); - - $client->authenticate([ - 'identifier' => $_ENV["BLUESKY_IDENTIFIER"], - 'password' => $_ENV["BLUESKY_PASSWORD"] - ]); - - $client->getRequest()->setActor('shahmal1yevv.bsky.social'); - - $response = $client->execute(); - - $this->assertIsObject($response); - $this->assertNotNull($response); - $this->assertIsString($response->did); - $this->assertIsString($response->handle); - } - - // Test send method with GetProfile - public function testSendWithGetProfile() - { - $request = new GetProfile(); - - $request->setActor('shahmal1yevv.bsky.social'); - - $client = new BlueskyClient($request); - - $client->authenticate([ - 'identifier' => $_ENV["BLUESKY_IDENTIFIER"], - 'password' => $_ENV["BLUESKY_PASSWORD"] - ]); - - /** @var GetProfileResource $response */ - $response = $client->send(); - - $this->assertIsObject($response); - $this->assertNotNull($response); - $this->assertIsString($response->did()); - $this->assertIsString($response->handle()); - $this->assertInstanceOf(Carbon::class, $response->indexedAt()); - $this->assertInstanceOf(Carbon::class, $response->createdAt()); - - $associated = $response->associated(); - - $this->assertIsInt($associated->lists()); - $this->assertInstanceOf(AssociatedAsset::class, $associated); - } - - /** - * @throws UnsupportedHTTPMethod - * @throws cURLException - * @throws AuthFailed - * @throws AuthRequired - * @throws InvalidRequestException - * @throws ExpiredTokenException - * @throws InvalidTokenException - */ - public function testSendWithRequestWhichHasNotResourceSupport() - { - $request = (new UploadBlob())->setBlob('art/file.png'); - - $client = new BlueskyClient($request); - - $client->authenticate([ - 'identifier' => $_ENV["BLUESKY_IDENTIFIER"], - 'password' => $_ENV["BLUESKY_PASSWORD"] - ]); - - $response = $client->send(); - - $this->assertIsObject($response); - $this->assertNotEmpty($response); - } - - // Test execute method with both UploadBlob and CreateRecord - public function testExecuteWithUploadBlobAndCreateRecord() - { - $client = new BlueskyClient(new UploadBlob()); - - $client->setStrategy(new PasswordAuthentication()) - ->authenticate([ - 'identifier' => $_ENV["BLUESKY_IDENTIFIER"], - 'password' => $_ENV["BLUESKY_PASSWORD"] - ]); - - $client->getRequest() - ->setBlob('art/file.png') - ->setHeaders([ - 'Content-Type' => $client->getRequest() - ->getBlob() - ->getMimeType() - ]); - - $image = $client->execute(); - - $recordBuilder = (new RecordBuilder()) - ->addText("Hello World!") - ->addText("") - ->addText("I was sent to test the inclusion of these URLs in this post:") - ->addText("") - ->addText("1. https://www.fs-poster.com") - ->addText("2. https://github.com/shahmal1yev/blueskysdk") - ->addText("3. https://www.wordpress.php") - ->addType() - ->addImage($image->blob) - ->addImage($image->blob) - ->addCreatedAt(); - - $client->setRequest(new CreateRecord()); - - $client->getRequest()->setRecord($recordBuilder); - - $response = $client->execute(); - - $this->assertIsObject($response); - $this->assertNotEmpty($response); - $this->assertIsString($response->uri); - $this->assertIsString($response->cid); - } - - // Test setStrategy method - public function testSetStrategyMethod() - { - $authStrategy = new PasswordAuthentication(); - $client = new BlueskyClient(new CreateRecord()); - - $client->setStrategy($authStrategy); - - $reflection = new \ReflectionClass($client); - $property = $reflection->getProperty('authStrategy'); - $property->setAccessible(true); - - $this->assertInstanceOf(AuthStrategyContract::class, $property->getValue($client)); - $this->assertInstanceOf(PasswordAuthentication::class, $property->getValue($client)); - $this->assertSame($authStrategy, $property->getValue($client)); - } -} diff --git a/tests/Feature/ClientTest.php b/tests/Feature/ClientTest.php index 79030a7..42c9b9a 100644 --- a/tests/Feature/ClientTest.php +++ b/tests/Feature/ClientTest.php @@ -3,7 +3,7 @@ namespace Tests\Feature; use Atproto\Client; -use Atproto\Contracts\HTTP\Resources\ResourceContract; +use Atproto\Contracts\Resources\ResourceContract; use Atproto\Exceptions\BlueskyException; use Atproto\Exceptions\Http\Response\AuthenticationRequiredException; use Atproto\Exceptions\Http\Response\AuthMissingException; diff --git a/tests/Feature/HTTP/API/Requests/App/Bsky/Actor/GetProfilesTest.php b/tests/Feature/HTTP/API/Requests/App/Bsky/Actor/GetProfilesTest.php deleted file mode 100644 index a524822..0000000 --- a/tests/Feature/HTTP/API/Requests/App/Bsky/Actor/GetProfilesTest.php +++ /dev/null @@ -1,116 +0,0 @@ -client = new Client(); - - $this->request = $this->client - ->app() - ->bsky() - ->actor() - ->getProfiles() - ->forge(); - } - - /** - * @throws BlueskyException - */ - private function authenticate(): void - { - $username = $_ENV['BLUESKY_IDENTIFIER']; - $password = $_ENV['BLUESKY_PASSWORD']; - - $this->assertIsString($username); - $this->assertIsString($password); - - $this->client->authenticate($username, $password); - } - - /** - * @throws InvalidArgumentException - * @throws \Atproto\Exceptions\InvalidArgumentException - * @throws BlueskyException - */ - public function testGettingProfiles(): void - { - $this->authenticate(); - - $profiles = new GenericCollection(new StringType(), [ - $this->client->authenticated()->did() - ]); - - $response = $this->client - ->app() - ->bsky() - ->actor() - ->getProfiles() - ->forge() - ->actors($profiles) - ->build() - ->send(); - - $this->assertInstanceOf(GetProfilesResource::class, $response); - $this->assertSame($profiles->count(), $response->profiles()->count()); - - $actualDidArr = array_map(fn (ProfileAsset $profile) => $profile->did(), $response->profiles()->toArray()); - - $this->assertSame($profiles->toArray(), $actualDidArr); - } - - public function testGettingProfilesThrowsExceptionWhenAuthTokenIsMissing(): void - { - $this->expectException(BlueskyException::class); - $this->expectException(AuthMissingException::class); - $this->expectExceptionMessage("Authentication Required"); - - $this->request->send(); - } - - public function testGettingProfilesThrowsExceptionWhenAuthTokenIsInvalid(): void - { - $this->expectException(BlueskyException::class); - $this->expectException(InvalidTokenException::class); - $this->expectExceptionMessage("Malformed authorization header"); - $this->expectExceptionCode(400); - - $this->request->token('Bearer token')->send(); - } - - public function testGettingProfilesThrowsExceptionWhenActorsMissing(): void - { - $this->expectException(BlueskyException::class); - $this->expectException(MissingFieldProvidedException::class); - $this->expectExceptionMessage("Missing fields provided: actors"); - - $this->authenticate(); - - $request = (new GetProfiles($this->client))->build(); - - $request->send(); - } -} diff --git a/tests/Supports/NonPrimitiveAssetTest.php b/tests/Supports/NonPrimitiveAssetTest.php index 08fd401..21785e2 100644 --- a/tests/Supports/NonPrimitiveAssetTest.php +++ b/tests/Supports/NonPrimitiveAssetTest.php @@ -2,7 +2,7 @@ namespace Tests\Supports; -use Atproto\Contracts\HTTP\Resources\AssetContract; +use Atproto\Contracts\Resources\AssetContract; use GenericCollection\Exceptions\InvalidArgumentException; use ReflectionClass; use ReflectionException; diff --git a/tests/Unit/ClientTest.php b/tests/Unit/ClientTest.php index 7b6347d..b8c3b6a 100644 --- a/tests/Unit/ClientTest.php +++ b/tests/Unit/ClientTest.php @@ -3,7 +3,7 @@ namespace Tests\Unit; use Atproto\Client; -use Atproto\Contracts\RequestContract; +use Atproto\Contracts\Lexicons\RequestContract; use Atproto\Exceptions\Http\Request\RequestNotFoundException; use Atproto\Lexicons\APIRequest; use Atproto\Lexicons\Com\Atproto\Server\CreateSession; diff --git a/tests/Unit/DataModel/Blob/BlobTest.php b/tests/Unit/DataModel/Blob/BlobTest.php index 22a4656..faa71bd 100644 --- a/tests/Unit/DataModel/Blob/BlobTest.php +++ b/tests/Unit/DataModel/Blob/BlobTest.php @@ -6,8 +6,8 @@ use Atproto\DataModel\Blob\Blob; use Atproto\Exceptions\InvalidArgumentException; use Atproto\IPFS\CID\CID; -use Atproto\MultiFormats\MultiBase\MultiBase; -use Atproto\MultiFormats\MultiCodec; +use Atproto\IPFS\MultiFormats\MultiBase\MultiBase; +use Atproto\IPFS\MultiFormats\MultiCodec; use Atproto\Support\FileSupport; use finfo; use PHPUnit\Framework\TestCase; diff --git a/tests/Unit/IPFS/CID/CIDTest.php b/tests/Unit/IPFS/CID/CIDTest.php index 8f92f06..a74d379 100644 --- a/tests/Unit/IPFS/CID/CIDTest.php +++ b/tests/Unit/IPFS/CID/CIDTest.php @@ -4,9 +4,9 @@ use Atproto\IPFS\CID\CID; use Atproto\IPFS\CID\CIDVersion; -use Atproto\MultiFormats\MultiBase\Encoders\Base32Encoder; -use Atproto\MultiFormats\MultiBase\MultiBase; -use Atproto\MultiFormats\MultiCodec; +use Atproto\IPFS\MultiFormats\MultiBase\Encoders\Base32Encoder; +use Atproto\IPFS\MultiFormats\MultiBase\MultiBase; +use Atproto\IPFS\MultiFormats\MultiCodec; use PHPUnit\Framework\TestCase; use Tests\Supports\Reflection; diff --git a/tests/Unit/HTTP/API/APIRequestTest.php b/tests/Unit/Lexicons/APIRequestTest.php similarity index 97% rename from tests/Unit/HTTP/API/APIRequestTest.php rename to tests/Unit/Lexicons/APIRequestTest.php index 6674eee..ce639ce 100644 --- a/tests/Unit/HTTP/API/APIRequestTest.php +++ b/tests/Unit/Lexicons/APIRequestTest.php @@ -1,6 +1,6 @@ Date: Thu, 31 Oct 2024 03:07:34 +0400 Subject: [PATCH 44/58] Refactor: Rename and Standardize Lexicon Interfaces and Traits - **Renaming**: - `RequestNotFoundException` renamed to `LexiconNotFoundException` for consistency in exception naming. - Renamed `type_name` to `nsid` in `PostBuilderContract` to better align with lexicon naming conventions. - `Authentication` trait renamed to `AuthenticatedLexicon` for lexicons that require authentication, improving clarity. - **New Implementations**: - Introduced `LexiconContract` interface on all lexicons for unified structure. - Created a new `Lexicon` trait to prevent code duplication across lexicons. Enhancement: Add Serializable and Endpoint Traits - **New Traits**: - **Serializable**: Applied to all serializable classes to reduce code duplication. - **Endpoint**: Extends `Serializable` and applies to endpoint lexicons. - **AuthenticatedEndpoint**: Dedicated for lexicons that require authentication. - **New Interface - SerializableContract**: - **SerializableContract**: Introduced to support classes needing serialization, currently implementing `Stringable` and `JsonSerializable`. Future support for `dagCbor` is planned. - **LexiconContract**: Extends `SerializableContract` and applies to all lexicon classes within Atproto. Future updates will add `nsid` and other signatures. --- src/Contracts/LexiconBuilder.php | 9 ---- src/Contracts/LexiconContract.php | 2 +- .../App/Bsky/Embed/CaptionContract.php | 5 +- .../App/Bsky/Embed/EmbedInterface.php | 4 +- .../App/Bsky/Embed/ImageInterface.php | 5 +- .../App/Bsky/Feed/PostBuilderContract.php | 5 +- .../App/Bsky/RichText/ByteSliceContract.php | 4 +- .../App/Bsky/RichText/FacetContract.php | 5 +- src/Contracts/SerializableContract.php | 7 +++ ...ption.php => LexiconNotFoundException.php} | 2 +- src/Lexicons/App/Bsky/Actor/GetProfile.php | 7 +-- src/Lexicons/App/Bsky/Actor/GetProfiles.php | 7 +-- src/Lexicons/App/Bsky/Embed/BlobHandler.php | 48 ------------------- src/Lexicons/App/Bsky/Embed/Caption.php | 8 ++-- .../Embed/Collections/CaptionCollection.php | 4 +- .../Embed/Collections/EmbedCollection.php | 8 ++-- src/Lexicons/App/Bsky/Embed/External.php | 9 ++-- src/Lexicons/App/Bsky/Embed/Image.php | 8 ++-- src/Lexicons/App/Bsky/Embed/Record.php | 9 ++-- src/Lexicons/App/Bsky/Embed/Video.php | 9 ++-- src/Lexicons/App/Bsky/Feed/Post.php | 12 ++--- src/Lexicons/App/Bsky/Graph/GetFollowers.php | 6 ++- src/Lexicons/App/Bsky/RichText/ByteSlice.php | 3 ++ src/Lexicons/App/Bsky/RichText/Facet.php | 10 ++-- .../App/Bsky/RichText/FeatureAbstract.php | 5 +- src/Lexicons/App/Bsky/RichText/Tag.php | 2 + src/Lexicons/Com/Atproto/Label/SelfLabels.php | 14 +++--- .../Com/Atproto/Repo/CreateRecord.php | 9 +--- src/Lexicons/Com/Atproto/Repo/StrongRef.php | 13 ++--- src/Lexicons/Com/Atproto/Repo/UploadBlob.php | 6 ++- .../Com/Atproto/Server/CreateSession.php | 7 ++- ...tication.php => AuthenticatedEndpoint.php} | 4 +- src/Lexicons/Traits/Endpoint.php | 21 ++++++++ src/Lexicons/Traits/Serializable.php | 24 ++++++++++ src/Traits/Smith.php | 6 +-- .../Com/Atproto/Repo/CreateRecordTest.php | 4 +- tests/Unit/ClientTest.php | 6 +-- 37 files changed, 153 insertions(+), 164 deletions(-) delete mode 100644 src/Contracts/LexiconBuilder.php create mode 100644 src/Contracts/SerializableContract.php rename src/Exceptions/Http/Request/{RequestNotFoundException.php => LexiconNotFoundException.php} (63%) delete mode 100644 src/Lexicons/App/Bsky/Embed/BlobHandler.php rename src/Lexicons/Traits/{Authentication.php => AuthenticatedEndpoint.php} (94%) create mode 100644 src/Lexicons/Traits/Endpoint.php create mode 100644 src/Lexicons/Traits/Serializable.php diff --git a/src/Contracts/LexiconBuilder.php b/src/Contracts/LexiconBuilder.php deleted file mode 100644 index ae6024f..0000000 --- a/src/Contracts/LexiconBuilder.php +++ /dev/null @@ -1,9 +0,0 @@ -path = $path; - $this->handle(); - } - - /** - * @throws InvalidArgumentException - */ - private function handle(): void - { - $this->isFile(); - $this->isReadable(); - } - - /** - * @throws InvalidArgumentException - */ - private function isFile(): void - { - if (! is_file($this->path)) { - throw new InvalidArgumentException("$this->path is not a file."); - } - } - - /** - * @throws InvalidArgumentException - */ - private function isReadable(): void - { - if (! is_readable($this->path)) { - throw new InvalidArgumentException("$this->path is not readable."); - } - } -} diff --git a/src/Lexicons/App/Bsky/Embed/Caption.php b/src/Lexicons/App/Bsky/Embed/Caption.php index b67fc19..aab4028 100644 --- a/src/Lexicons/App/Bsky/Embed/Caption.php +++ b/src/Lexicons/App/Bsky/Embed/Caption.php @@ -5,9 +5,12 @@ use Atproto\Contracts\Lexicons\App\Bsky\Embed\CaptionContract; use Atproto\DataModel\Blob\Blob; use Atproto\Exceptions\InvalidArgumentException; +use Atproto\Lexicons\Traits\Serializable; class Caption implements CaptionContract { + use Serializable; + private const MAX_SIZE = 20000; private string $lang; @@ -65,9 +68,4 @@ public function jsonSerialize(): array 'file' => $this->file(), ]; } - - public function __toString(): string - { - return json_encode($this); - } } diff --git a/src/Lexicons/App/Bsky/Embed/Collections/CaptionCollection.php b/src/Lexicons/App/Bsky/Embed/Collections/CaptionCollection.php index 68487a5..fd65057 100644 --- a/src/Lexicons/App/Bsky/Embed/Collections/CaptionCollection.php +++ b/src/Lexicons/App/Bsky/Embed/Collections/CaptionCollection.php @@ -3,13 +3,15 @@ namespace Atproto\Lexicons\App\Bsky\Embed\Collections; use Atproto\Contracts\Lexicons\App\Bsky\Embed\CaptionContract; +use Atproto\Contracts\SerializableContract; use Atproto\Exceptions\InvalidArgumentException; use GenericCollection\GenericCollection; use JsonSerializable; -class CaptionCollection extends GenericCollection implements JsonSerializable +class CaptionCollection extends GenericCollection implements SerializableContract { use EmbedCollection; + private const MAX_SIZE = 20; protected function validator(): \Closure diff --git a/src/Lexicons/App/Bsky/Embed/Collections/EmbedCollection.php b/src/Lexicons/App/Bsky/Embed/Collections/EmbedCollection.php index e8c9e4c..dd460bc 100644 --- a/src/Lexicons/App/Bsky/Embed/Collections/EmbedCollection.php +++ b/src/Lexicons/App/Bsky/Embed/Collections/EmbedCollection.php @@ -3,9 +3,12 @@ namespace Atproto\Lexicons\App\Bsky\Embed\Collections; use Atproto\Exceptions\InvalidArgumentException; +use Atproto\Lexicons\Traits\Serializable; trait EmbedCollection { + use Serializable; + /** * @throws InvalidArgumentException */ @@ -42,9 +45,4 @@ public function jsonSerialize(): array { return $this->toArray(); } - - public function __toString(): string - { - return json_encode($this); - } } diff --git a/src/Lexicons/App/Bsky/Embed/External.php b/src/Lexicons/App/Bsky/Embed/External.php index 90b7d78..525f450 100644 --- a/src/Lexicons/App/Bsky/Embed/External.php +++ b/src/Lexicons/App/Bsky/Embed/External.php @@ -6,9 +6,13 @@ use Atproto\Contracts\Lexicons\App\Bsky\Embed\MediaContract; use Atproto\DataModel\Blob\Blob; use Atproto\Exceptions\InvalidArgumentException; +use Atproto\Lexicons\Traits\Endpoint; +use Atproto\Lexicons\Traits\Serializable; class External implements EmbedInterface, MediaContract { + use Serializable; + private string $uri; private string $title; private string $description; @@ -100,11 +104,6 @@ public function jsonSerialize(): array ]); } - public function __toString(): string - { - return json_encode($this); - } - public function type(): string { return 'app.bsky.embed.external'; diff --git a/src/Lexicons/App/Bsky/Embed/Image.php b/src/Lexicons/App/Bsky/Embed/Image.php index c2c1ae8..807ea4f 100644 --- a/src/Lexicons/App/Bsky/Embed/Image.php +++ b/src/Lexicons/App/Bsky/Embed/Image.php @@ -5,9 +5,12 @@ use Atproto\Contracts\Lexicons\App\Bsky\Embed\ImageInterface; use Atproto\DataModel\Blob\Blob; use Atproto\Exceptions\InvalidArgumentException; +use Atproto\Lexicons\Traits\Serializable; class Image implements ImageInterface { + use Serializable; + private Blob $file; private string $alt; private ?array $aspectRatio = null; @@ -73,9 +76,4 @@ public function size(): int { return $this->file->size(); } - - public function __toString(): string - { - return json_encode($this); - } } diff --git a/src/Lexicons/App/Bsky/Embed/Record.php b/src/Lexicons/App/Bsky/Embed/Record.php index f1cf13b..9cd2d11 100644 --- a/src/Lexicons/App/Bsky/Embed/Record.php +++ b/src/Lexicons/App/Bsky/Embed/Record.php @@ -4,9 +4,13 @@ use Atproto\Contracts\Lexicons\App\Bsky\Embed\EmbedInterface; use Atproto\Lexicons\Com\Atproto\Repo\StrongRef; +use Atproto\Lexicons\Traits\Endpoint; +use Atproto\Lexicons\Traits\Serializable; class Record implements EmbedInterface { + use Serializable; + private StrongRef $ref; public function __construct(StrongRef $ref) @@ -14,11 +18,6 @@ public function __construct(StrongRef $ref) $this->ref = $ref; } - public function __toString(): string - { - return json_encode($this); - } - public function jsonSerialize(): array { return [ diff --git a/src/Lexicons/App/Bsky/Embed/Video.php b/src/Lexicons/App/Bsky/Embed/Video.php index a7f96b9..b0413cd 100644 --- a/src/Lexicons/App/Bsky/Embed/Video.php +++ b/src/Lexicons/App/Bsky/Embed/Video.php @@ -7,9 +7,12 @@ use Atproto\DataModel\Blob\Blob; use Atproto\Exceptions\InvalidArgumentException; use Atproto\Lexicons\App\Bsky\Embed\Collections\CaptionCollection; +use Atproto\Lexicons\Traits\Serializable; class Video implements VideoInterface, MediaContract { + use Serializable; + private Blob $file; private ?string $alt = null; private CaptionCollection $captions; @@ -88,12 +91,6 @@ public function captions(CaptionCollection $captions = null) return $this; } - public function __toString(): string - { - $result = json_encode($this); - return $result; - } - public function type(): string { return 'app.bsky.embed.video'; diff --git a/src/Lexicons/App/Bsky/Feed/Post.php b/src/Lexicons/App/Bsky/Feed/Post.php index 9737904..bfc85c7 100644 --- a/src/Lexicons/App/Bsky/Feed/Post.php +++ b/src/Lexicons/App/Bsky/Feed/Post.php @@ -13,12 +13,15 @@ use Atproto\Lexicons\App\Bsky\RichText\FeatureFactory; use Atproto\Lexicons\Com\Atproto\Label\SelfLabels; use Atproto\Lexicons\Com\Atproto\Repo\StrongRef; +use Atproto\Lexicons\Traits\Serializable; use Carbon\Carbon; use DateTimeImmutable; class Post implements PostBuilderContract { - private const TYPE_NAME = 'app.bsky.feed.post'; + use Serializable; + + private const NSID = 'app.bsky.feed.post'; private const TEXT_LIMIT = 3000; private string $text = ''; @@ -200,7 +203,7 @@ public function createdAt(DateTimeImmutable $dateTime): PostBuilderContract public function jsonSerialize(): array { return array_filter([ - '$type' => self::TYPE_NAME, + '$type' => self::NSID, 'createdAt' => $this->getFormattedCreatedAt(), 'text' => $this->text, 'facets' => $this->facets->toArray(), @@ -212,11 +215,6 @@ public function jsonSerialize(): array ]); } - public function __toString(): string - { - return json_encode($this); - } - private function isString($item): bool { return is_scalar($item); diff --git a/src/Lexicons/App/Bsky/Graph/GetFollowers.php b/src/Lexicons/App/Bsky/Graph/GetFollowers.php index 7e8a890..c2a6040 100644 --- a/src/Lexicons/App/Bsky/Graph/GetFollowers.php +++ b/src/Lexicons/App/Bsky/Graph/GetFollowers.php @@ -2,15 +2,19 @@ namespace Atproto\Lexicons\App\Bsky\Graph; +use Atproto\Contracts\LexiconContract; use Atproto\Contracts\Lexicons\RequestContract; use Atproto\Contracts\Resources\ResourceContract; use Atproto\Exceptions\Http\MissingFieldProvidedException; use Atproto\Exceptions\InvalidArgumentException; use Atproto\Lexicons\APIRequest; +use Atproto\Lexicons\Traits\Endpoint; use Atproto\Resources\App\Bsky\Graph\GetFollowersResource; -class GetFollowers extends APIRequest +class GetFollowers extends APIRequest implements LexiconContract { + use Endpoint; + public function actor(string $actor = null) { if (is_null($actor)) { diff --git a/src/Lexicons/App/Bsky/RichText/ByteSlice.php b/src/Lexicons/App/Bsky/RichText/ByteSlice.php index 75884ec..8aa1393 100644 --- a/src/Lexicons/App/Bsky/RichText/ByteSlice.php +++ b/src/Lexicons/App/Bsky/RichText/ByteSlice.php @@ -3,9 +3,12 @@ namespace Atproto\Lexicons\App\Bsky\RichText; use Atproto\Contracts\Lexicons\App\Bsky\RichText\ByteSliceContract; +use Atproto\Lexicons\Traits\Serializable; class ByteSlice implements ByteSliceContract { + use Serializable; + private string $text; private string $added; diff --git a/src/Lexicons/App/Bsky/RichText/Facet.php b/src/Lexicons/App/Bsky/RichText/Facet.php index dfbb9a4..3b868c4 100644 --- a/src/Lexicons/App/Bsky/RichText/Facet.php +++ b/src/Lexicons/App/Bsky/RichText/Facet.php @@ -5,9 +5,12 @@ use Atproto\Collections\FeatureCollection; use Atproto\Contracts\Lexicons\App\Bsky\RichText\ByteSliceContract; use Atproto\Contracts\Lexicons\App\Bsky\RichText\FacetContract; +use Atproto\Lexicons\Traits\Serializable; class Facet implements FacetContract { + use Serializable; + private ByteSliceContract $byteSlice; private FeatureCollection $features; @@ -39,9 +42,4 @@ public function jsonSerialize(): array 'features' => $this->features->toArray() ]; } - - public function __toString(): string - { - return json_encode($this); - } -} +} \ No newline at end of file diff --git a/src/Lexicons/App/Bsky/RichText/FeatureAbstract.php b/src/Lexicons/App/Bsky/RichText/FeatureAbstract.php index bb50204..5f48ad3 100644 --- a/src/Lexicons/App/Bsky/RichText/FeatureAbstract.php +++ b/src/Lexicons/App/Bsky/RichText/FeatureAbstract.php @@ -2,10 +2,9 @@ namespace Atproto\Lexicons\App\Bsky\RichText; -use Atproto\Contracts\LexiconBuilder; -use Atproto\Contracts\Stringable; +use Atproto\Contracts\LexiconContract; -abstract class FeatureAbstract implements LexiconBuilder, Stringable +abstract class FeatureAbstract implements LexiconContract { protected string $reference; protected string $label; diff --git a/src/Lexicons/App/Bsky/RichText/Tag.php b/src/Lexicons/App/Bsky/RichText/Tag.php index 9f3291e..a2d39d9 100644 --- a/src/Lexicons/App/Bsky/RichText/Tag.php +++ b/src/Lexicons/App/Bsky/RichText/Tag.php @@ -2,6 +2,8 @@ namespace Atproto\Lexicons\App\Bsky\RichText; +use Atproto\Lexicons\Traits\Serializable; + class Tag extends FeatureAbstract { protected function schema(): array diff --git a/src/Lexicons/Com/Atproto/Label/SelfLabels.php b/src/Lexicons/Com/Atproto/Label/SelfLabels.php index 60489a2..9ab75a6 100644 --- a/src/Lexicons/Com/Atproto/Label/SelfLabels.php +++ b/src/Lexicons/Com/Atproto/Label/SelfLabels.php @@ -2,13 +2,16 @@ namespace Atproto\Lexicons\Com\Atproto\Label; -use Atproto\Contracts\Stringable; +use Atproto\Contracts\LexiconContract; +use Atproto\Contracts\SerializableContract; use Atproto\Exceptions\InvalidArgumentException; +use Atproto\Lexicons\Traits\Serializable; use GenericCollection\GenericCollection; -use JsonSerializable; -class SelfLabels extends GenericCollection implements JsonSerializable, Stringable +class SelfLabels extends GenericCollection implements LexiconContract { + use Serializable; + private const MAXLENGTH = 10; private const MAXLENGTH_BY_ITEM = 128; @@ -57,11 +60,6 @@ private function throw($exception): void ); } - public function __toString(): string - { - return json_encode($this); - } - public function jsonSerialize(): array { return $this->toArray(); diff --git a/src/Lexicons/Com/Atproto/Repo/CreateRecord.php b/src/Lexicons/Com/Atproto/Repo/CreateRecord.php index 151536f..b863619 100644 --- a/src/Lexicons/Com/Atproto/Repo/CreateRecord.php +++ b/src/Lexicons/Com/Atproto/Repo/CreateRecord.php @@ -9,12 +9,12 @@ use Atproto\Exceptions\Http\MissingFieldProvidedException; use Atproto\Exceptions\InvalidArgumentException; use Atproto\Lexicons\APIRequest; -use Atproto\Lexicons\Traits\Authentication; +use Atproto\Lexicons\Traits\AuthenticatedEndpoint; use Atproto\Resources\Com\Atproto\Repo\CreateRecordResource; class CreateRecord extends APIRequest implements LexiconContract { - use Authentication; + use AuthenticatedEndpoint; protected array $required = [ 'repo', @@ -125,11 +125,6 @@ public function resource(array $data): ResourceContract return new CreateRecordResource($data); } - public function __toString(): string - { - return json_encode($this); - } - public function jsonSerialize(): array { return array_filter([ diff --git a/src/Lexicons/Com/Atproto/Repo/StrongRef.php b/src/Lexicons/Com/Atproto/Repo/StrongRef.php index 037a584..39bc177 100644 --- a/src/Lexicons/Com/Atproto/Repo/StrongRef.php +++ b/src/Lexicons/Com/Atproto/Repo/StrongRef.php @@ -2,11 +2,13 @@ namespace Atproto\Lexicons\Com\Atproto\Repo; -use Atproto\Contracts\Stringable; -use JsonSerializable; +use Atproto\Contracts\LexiconContract; +use Atproto\Lexicons\Traits\Serializable; -class StrongRef implements JsonSerializable, Stringable +class StrongRef implements LexiconContract { + use Serializable; + private string $uri; private string $cid; @@ -45,9 +47,4 @@ public function jsonSerialize(): array 'cid' => $this->cid, ]; } - - public function __toString(): string - { - return json_encode($this); - } } diff --git a/src/Lexicons/Com/Atproto/Repo/UploadBlob.php b/src/Lexicons/Com/Atproto/Repo/UploadBlob.php index 10cb7ed..6d9a1fc 100644 --- a/src/Lexicons/Com/Atproto/Repo/UploadBlob.php +++ b/src/Lexicons/Com/Atproto/Repo/UploadBlob.php @@ -2,17 +2,21 @@ namespace Atproto\Lexicons\Com\Atproto\Repo; +use Atproto\Contracts\LexiconContract; use Atproto\Contracts\Lexicons\RequestContract; use Atproto\Contracts\Resources\ResourceContract; use Atproto\DataModel\Blob\Blob; use Atproto\Exceptions\Http\MissingFieldProvidedException; use Atproto\Exceptions\InvalidArgumentException; use Atproto\Lexicons\APIRequest; +use Atproto\Lexicons\Traits\AuthenticatedEndpoint; use Atproto\Resources\Com\Atproto\Repo\UploadBlobResource; use Atproto\Support\FileSupport; -class UploadBlob extends APIRequest +class UploadBlob extends APIRequest implements LexiconContract { + use AuthenticatedEndpoint; + protected function initialize(): void { parent::initialize(); diff --git a/src/Lexicons/Com/Atproto/Server/CreateSession.php b/src/Lexicons/Com/Atproto/Server/CreateSession.php index c5844c7..ebb85db 100644 --- a/src/Lexicons/Com/Atproto/Server/CreateSession.php +++ b/src/Lexicons/Com/Atproto/Server/CreateSession.php @@ -3,13 +3,18 @@ namespace Atproto\Lexicons\Com\Atproto\Server; use Atproto\Client; +use Atproto\Contracts\LexiconContract; use Atproto\Contracts\Lexicons\RequestContract; use Atproto\Contracts\Resources\ResourceContract; use Atproto\Lexicons\APIRequest; +use Atproto\Lexicons\Traits\Endpoint; +use Atproto\Lexicons\Traits\Serializable; use Atproto\Resources\Com\Atproto\Server\CreateSessionResource; -class CreateSession extends APIRequest +class CreateSession extends APIRequest implements LexiconContract { + use Endpoint; + public function __construct(Client $client, string $identifier, string $password) { parent::__construct($client); diff --git a/src/Lexicons/Traits/Authentication.php b/src/Lexicons/Traits/AuthenticatedEndpoint.php similarity index 94% rename from src/Lexicons/Traits/Authentication.php rename to src/Lexicons/Traits/AuthenticatedEndpoint.php index 4aeadd7..ec63d6a 100644 --- a/src/Lexicons/Traits/Authentication.php +++ b/src/Lexicons/Traits/AuthenticatedEndpoint.php @@ -6,8 +6,10 @@ use Atproto\Lexicons\APIRequest; use SplSubject; -trait Authentication +trait AuthenticatedEndpoint { + use Endpoint; + public function __construct(Client $client) { if (! is_subclass_of(static::class, APIRequest::class)) { diff --git a/src/Lexicons/Traits/Endpoint.php b/src/Lexicons/Traits/Endpoint.php new file mode 100644 index 0000000..7983ac9 --- /dev/null +++ b/src/Lexicons/Traits/Endpoint.php @@ -0,0 +1,21 @@ + $this->url(), + 'origin' => $this->origin(), + 'path' => $this->path(), + 'method' => $this->method(), + 'headers' => $this->headers(), + 'parameters' => $this->parameters(), + 'queryParameters' => $this->queryParameters(), + ]; + } +} diff --git a/src/Lexicons/Traits/Serializable.php b/src/Lexicons/Traits/Serializable.php new file mode 100644 index 0000000..1e16100 --- /dev/null +++ b/src/Lexicons/Traits/Serializable.php @@ -0,0 +1,24 @@ +request(); if (! class_exists($request)) { - throw new RequestNotFoundException("$request class does not exist."); + throw new LexiconNotFoundException("$request class does not exist."); } /** @var APIRequestContract $request */ diff --git a/tests/Feature/Lexicons/Com/Atproto/Repo/CreateRecordTest.php b/tests/Feature/Lexicons/Com/Atproto/Repo/CreateRecordTest.php index 0fd2434..e11a98d 100644 --- a/tests/Feature/Lexicons/Com/Atproto/Repo/CreateRecordTest.php +++ b/tests/Feature/Lexicons/Com/Atproto/Repo/CreateRecordTest.php @@ -23,8 +23,8 @@ public static function setUpBeforeClass(): void static::$client = new Client(); static::$client->authenticate( - getenv('BLUESKY_IDENTIFIER'), - getenv('BLUESKY_PASSWORD') + 'shahmal1yevv.bsky.social', + 'ucvlqcq8' ); } diff --git a/tests/Unit/ClientTest.php b/tests/Unit/ClientTest.php index b8c3b6a..c19859e 100644 --- a/tests/Unit/ClientTest.php +++ b/tests/Unit/ClientTest.php @@ -4,7 +4,7 @@ use Atproto\Client; use Atproto\Contracts\Lexicons\RequestContract; -use Atproto\Exceptions\Http\Request\RequestNotFoundException; +use Atproto\Exceptions\Http\Request\LexiconNotFoundException; use Atproto\Lexicons\APIRequest; use Atproto\Lexicons\Com\Atproto\Server\CreateSession; use Atproto\Resources\Com\Atproto\Server\CreateSessionResource; @@ -56,14 +56,14 @@ public function testForgeThrowsRequestNotFoundException(): void { $this->client->nonExistentMethod(); - $this->expectException(RequestNotFoundException::class); + $this->expectException(LexiconNotFoundException::class); $this->expectExceptionMessage("Atproto\\Lexicons\\NonExistentMethod class does not exist."); $this->client->forge(); } /** - * @throws RequestNotFoundException + * @throws LexiconNotFoundException */ public function testForgeReturnsRequestContract(): void { From 8a264a66e667f24e7f24662ae68b26f1a0a34ffa Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sun, 3 Nov 2024 05:52:13 +0400 Subject: [PATCH 45/58] refactor: standardize NSID handling with Lexicon trait --- src/Contracts/LexiconContract.php | 1 + .../App/Bsky/Embed/EmbedInterface.php | 1 - src/Lexicons/APIRequest.php | 19 +------------------ .../Embed/Collections/CaptionCollection.php | 8 +++++++- .../Embed/Collections/EmbedCollection.php | 8 -------- .../Embed/Collections/ImageCollection.php | 14 ++++++++------ src/Lexicons/App/Bsky/Embed/External.php | 12 +++--------- src/Lexicons/App/Bsky/Embed/Record.php | 12 +++--------- .../App/Bsky/Embed/RecordWithMedia.php | 7 +------ src/Lexicons/App/Bsky/Embed/Video.php | 11 +++-------- src/Lexicons/App/Bsky/Feed/Post.php | 10 +++++----- src/Lexicons/App/Bsky/RichText/Facet.php | 6 +++--- .../App/Bsky/RichText/FeatureAbstract.php | 7 ++++--- src/Lexicons/App/Bsky/RichText/Link.php | 5 ----- src/Lexicons/App/Bsky/RichText/Mention.php | 7 ------- src/Lexicons/App/Bsky/RichText/Tag.php | 7 ------- src/Lexicons/Com/Atproto/Label/SelfLabels.php | 3 +-- .../Com/Atproto/Repo/CreateRecord.php | 7 ------- src/Lexicons/Com/Atproto/Repo/StrongRef.php | 4 ++-- src/Lexicons/Com/Atproto/Repo/UploadBlob.php | 8 +++++--- .../Com/Atproto/Server/CreateSession.php | 3 +-- src/Lexicons/Traits/AuthenticatedEndpoint.php | 10 ++++++++++ src/Lexicons/Traits/Endpoint.php | 12 +++++++++++- src/Lexicons/Traits/Lexicon.php | 18 ++++++++++++++++++ .../App/Bsky/RichText/FeatureAbstractTest.php | 4 ++-- .../App/Bsky/RichText/FeatureTests.php | 2 +- 26 files changed, 90 insertions(+), 116 deletions(-) create mode 100644 src/Lexicons/Traits/Lexicon.php diff --git a/src/Contracts/LexiconContract.php b/src/Contracts/LexiconContract.php index 919b16d..6ba2a7d 100644 --- a/src/Contracts/LexiconContract.php +++ b/src/Contracts/LexiconContract.php @@ -4,4 +4,5 @@ interface LexiconContract extends SerializableContract { + public function nsid(): string; } diff --git a/src/Contracts/Lexicons/App/Bsky/Embed/EmbedInterface.php b/src/Contracts/Lexicons/App/Bsky/Embed/EmbedInterface.php index e305425..18732d6 100644 --- a/src/Contracts/Lexicons/App/Bsky/Embed/EmbedInterface.php +++ b/src/Contracts/Lexicons/App/Bsky/Embed/EmbedInterface.php @@ -6,5 +6,4 @@ interface EmbedInterface extends LexiconContract { - public function type(): string; } diff --git a/src/Lexicons/APIRequest.php b/src/Lexicons/APIRequest.php index ef82636..e1fc6d3 100644 --- a/src/Lexicons/APIRequest.php +++ b/src/Lexicons/APIRequest.php @@ -22,24 +22,7 @@ public function send(): ResourceContract return $this->resource(parent::send()); } - protected function initialize(): void - { - $this->origin(self::API_BASE_URL) - ->path($this->endpoint()) - ->headers(self::API_BASE_HEADERS); - } - - private function endpoint(): string - { - $endpointParts = explode("\\", $this->client->path()); - - $endpoint = array_reduce( - $endpointParts, - fn ($carry, $part) => $carry .= "." . lcfirst($part) - ); - - return sprintf("/xrpc/%s", trim($endpoint, ".")); - } + abstract protected function initialize(): void; abstract public function resource(array $data): ResourceContract; diff --git a/src/Lexicons/App/Bsky/Embed/Collections/CaptionCollection.php b/src/Lexicons/App/Bsky/Embed/Collections/CaptionCollection.php index fd65057..c8bd575 100644 --- a/src/Lexicons/App/Bsky/Embed/Collections/CaptionCollection.php +++ b/src/Lexicons/App/Bsky/Embed/Collections/CaptionCollection.php @@ -5,11 +5,12 @@ use Atproto\Contracts\Lexicons\App\Bsky\Embed\CaptionContract; use Atproto\Contracts\SerializableContract; use Atproto\Exceptions\InvalidArgumentException; +use Atproto\Lexicons\Traits\Serializable; use GenericCollection\GenericCollection; -use JsonSerializable; class CaptionCollection extends GenericCollection implements SerializableContract { + use Serializable; use EmbedCollection; private const MAX_SIZE = 20; @@ -24,4 +25,9 @@ protected function validator(): \Closure return true; }; } + + public function jsonSerialize(): array + { + return $this->toArray(); + } } diff --git a/src/Lexicons/App/Bsky/Embed/Collections/EmbedCollection.php b/src/Lexicons/App/Bsky/Embed/Collections/EmbedCollection.php index dd460bc..5354c99 100644 --- a/src/Lexicons/App/Bsky/Embed/Collections/EmbedCollection.php +++ b/src/Lexicons/App/Bsky/Embed/Collections/EmbedCollection.php @@ -3,12 +3,9 @@ namespace Atproto\Lexicons\App\Bsky\Embed\Collections; use Atproto\Exceptions\InvalidArgumentException; -use Atproto\Lexicons\Traits\Serializable; trait EmbedCollection { - use Serializable; - /** * @throws InvalidArgumentException */ @@ -40,9 +37,4 @@ private function throw($exception): void } abstract protected function validator(): \Closure; - - public function jsonSerialize(): array - { - return $this->toArray(); - } } diff --git a/src/Lexicons/App/Bsky/Embed/Collections/ImageCollection.php b/src/Lexicons/App/Bsky/Embed/Collections/ImageCollection.php index 15800bc..8000f6e 100644 --- a/src/Lexicons/App/Bsky/Embed/Collections/ImageCollection.php +++ b/src/Lexicons/App/Bsky/Embed/Collections/ImageCollection.php @@ -5,11 +5,13 @@ use Atproto\Contracts\Lexicons\App\Bsky\Embed\EmbedInterface; use Atproto\Contracts\Lexicons\App\Bsky\Embed\ImageInterface; use Atproto\Contracts\Lexicons\App\Bsky\Embed\MediaContract; +use Atproto\Lexicons\Traits\Lexicon; use GenericCollection\Exceptions\InvalidArgumentException; use GenericCollection\GenericCollection; class ImageCollection extends GenericCollection implements EmbedInterface, MediaContract { + use Lexicon; use EmbedCollection; private const MAX_LENGTH = 4; @@ -30,16 +32,16 @@ protected function validator(): \Closure }; } - public function type(): string - { - return 'app.bsky.embed.images'; - } - public function jsonSerialize(): array { return [ 'images' => $this->toArray(), - '$type' => $this->type(), + '$type' => $this->nsid(), ]; } + + public function nsid(): string + { + return 'app.bsky.embed.images'; + } } diff --git a/src/Lexicons/App/Bsky/Embed/External.php b/src/Lexicons/App/Bsky/Embed/External.php index 525f450..b57e883 100644 --- a/src/Lexicons/App/Bsky/Embed/External.php +++ b/src/Lexicons/App/Bsky/Embed/External.php @@ -6,12 +6,11 @@ use Atproto\Contracts\Lexicons\App\Bsky\Embed\MediaContract; use Atproto\DataModel\Blob\Blob; use Atproto\Exceptions\InvalidArgumentException; -use Atproto\Lexicons\Traits\Endpoint; -use Atproto\Lexicons\Traits\Serializable; +use Atproto\Lexicons\Traits\Lexicon; class External implements EmbedInterface, MediaContract { - use Serializable; + use Lexicon; private string $uri; private string $title; @@ -96,16 +95,11 @@ public function thumb(Blob $blob = null) public function jsonSerialize(): array { return array_filter([ - '$type' => $this->type(), + '$type' => $this->nsid(), 'uri' => $this->uri, 'title' => $this->title, 'description' => $this->description, 'blob' => ($b = $this->blob) ? $b : null, ]); } - - public function type(): string - { - return 'app.bsky.embed.external'; - } } diff --git a/src/Lexicons/App/Bsky/Embed/Record.php b/src/Lexicons/App/Bsky/Embed/Record.php index 9cd2d11..bf1131c 100644 --- a/src/Lexicons/App/Bsky/Embed/Record.php +++ b/src/Lexicons/App/Bsky/Embed/Record.php @@ -4,12 +4,11 @@ use Atproto\Contracts\Lexicons\App\Bsky\Embed\EmbedInterface; use Atproto\Lexicons\Com\Atproto\Repo\StrongRef; -use Atproto\Lexicons\Traits\Endpoint; -use Atproto\Lexicons\Traits\Serializable; +use Atproto\Lexicons\Traits\Lexicon; class Record implements EmbedInterface { - use Serializable; + use Lexicon; private StrongRef $ref; @@ -21,13 +20,8 @@ public function __construct(StrongRef $ref) public function jsonSerialize(): array { return [ - '$type' => $this->type(), + '$type' => $this->nsid(), 'record' => $this->ref, ]; } - - public function type(): string - { - return 'app.bsky.embed.record'; - } } diff --git a/src/Lexicons/App/Bsky/Embed/RecordWithMedia.php b/src/Lexicons/App/Bsky/Embed/RecordWithMedia.php index 509abf0..498f3fc 100644 --- a/src/Lexicons/App/Bsky/Embed/RecordWithMedia.php +++ b/src/Lexicons/App/Bsky/Embed/RecordWithMedia.php @@ -29,13 +29,8 @@ public function media(MediaContract $media = null) public function jsonSerialize(): array { return array_merge(parent::jsonSerialize(), [ - '$type' => $this->type(), + '$type' => $this->nsid(), 'media' => $this->media, ]); } - - public function type(): string - { - return 'app.bsky.embed.recordWithMedia'; - } } diff --git a/src/Lexicons/App/Bsky/Embed/Video.php b/src/Lexicons/App/Bsky/Embed/Video.php index b0413cd..43aee4e 100644 --- a/src/Lexicons/App/Bsky/Embed/Video.php +++ b/src/Lexicons/App/Bsky/Embed/Video.php @@ -7,11 +7,11 @@ use Atproto\DataModel\Blob\Blob; use Atproto\Exceptions\InvalidArgumentException; use Atproto\Lexicons\App\Bsky\Embed\Collections\CaptionCollection; -use Atproto\Lexicons\Traits\Serializable; +use Atproto\Lexicons\Traits\Lexicon; class Video implements VideoInterface, MediaContract { - use Serializable; + use Lexicon; private Blob $file; private ?string $alt = null; @@ -38,7 +38,7 @@ public function __construct(Blob $file) public function jsonSerialize(): array { $result = array_filter([ - '$type' => $this->type(), + '$type' => $this->nsid(), 'alt' => $this->alt() ?: null, 'video' => $this->file, 'aspectRatio' => $this->aspectRatio() ?: null, @@ -90,9 +90,4 @@ public function captions(CaptionCollection $captions = null) return $this; } - - public function type(): string - { - return 'app.bsky.embed.video'; - } } diff --git a/src/Lexicons/App/Bsky/Feed/Post.php b/src/Lexicons/App/Bsky/Feed/Post.php index bfc85c7..1277fac 100644 --- a/src/Lexicons/App/Bsky/Feed/Post.php +++ b/src/Lexicons/App/Bsky/Feed/Post.php @@ -13,15 +13,13 @@ use Atproto\Lexicons\App\Bsky\RichText\FeatureFactory; use Atproto\Lexicons\Com\Atproto\Label\SelfLabels; use Atproto\Lexicons\Com\Atproto\Repo\StrongRef; -use Atproto\Lexicons\Traits\Serializable; +use Atproto\Lexicons\Traits\Lexicon; use Carbon\Carbon; use DateTimeImmutable; class Post implements PostBuilderContract { - use Serializable; - - private const NSID = 'app.bsky.feed.post'; + use Lexicon; private const TEXT_LIMIT = 3000; private string $text = ''; @@ -150,6 +148,8 @@ public function tags(array $tags): PostBuilderContract if (mb_strlen($tag) > 640) { return true; } + + return false; }); if (! empty($invalid)) { @@ -203,7 +203,7 @@ public function createdAt(DateTimeImmutable $dateTime): PostBuilderContract public function jsonSerialize(): array { return array_filter([ - '$type' => self::NSID, + '$type' => $this->nsid(), 'createdAt' => $this->getFormattedCreatedAt(), 'text' => $this->text, 'facets' => $this->facets->toArray(), diff --git a/src/Lexicons/App/Bsky/RichText/Facet.php b/src/Lexicons/App/Bsky/RichText/Facet.php index 3b868c4..29ac758 100644 --- a/src/Lexicons/App/Bsky/RichText/Facet.php +++ b/src/Lexicons/App/Bsky/RichText/Facet.php @@ -5,11 +5,11 @@ use Atproto\Collections\FeatureCollection; use Atproto\Contracts\Lexicons\App\Bsky\RichText\ByteSliceContract; use Atproto\Contracts\Lexicons\App\Bsky\RichText\FacetContract; -use Atproto\Lexicons\Traits\Serializable; +use Atproto\Lexicons\Traits\Lexicon; class Facet implements FacetContract { - use Serializable; + use Lexicon; private ByteSliceContract $byteSlice; @@ -42,4 +42,4 @@ public function jsonSerialize(): array 'features' => $this->features->toArray() ]; } -} \ No newline at end of file +} diff --git a/src/Lexicons/App/Bsky/RichText/FeatureAbstract.php b/src/Lexicons/App/Bsky/RichText/FeatureAbstract.php index 5f48ad3..62657bb 100644 --- a/src/Lexicons/App/Bsky/RichText/FeatureAbstract.php +++ b/src/Lexicons/App/Bsky/RichText/FeatureAbstract.php @@ -3,9 +3,12 @@ namespace Atproto\Lexicons\App\Bsky\RichText; use Atproto\Contracts\LexiconContract; +use Atproto\Lexicons\Traits\Lexicon; abstract class FeatureAbstract implements LexiconContract { + use Lexicon; + protected string $reference; protected string $label; @@ -21,10 +24,8 @@ public function __construct(string $reference, string $label = null) final public function jsonSerialize(): array { - return ['type' => $this->type()] + $this->schema(); + return ['type' => $this->nsid()] + $this->schema(); } - abstract protected function type(): string; - abstract protected function schema(): array; } diff --git a/src/Lexicons/App/Bsky/RichText/Link.php b/src/Lexicons/App/Bsky/RichText/Link.php index f23945e..80ceebd 100644 --- a/src/Lexicons/App/Bsky/RichText/Link.php +++ b/src/Lexicons/App/Bsky/RichText/Link.php @@ -16,9 +16,4 @@ public function __toString(): string { return $this->label; } - - protected function type(): string - { - return "link"; - } } diff --git a/src/Lexicons/App/Bsky/RichText/Mention.php b/src/Lexicons/App/Bsky/RichText/Mention.php index 989626b..2b12f6b 100644 --- a/src/Lexicons/App/Bsky/RichText/Mention.php +++ b/src/Lexicons/App/Bsky/RichText/Mention.php @@ -4,8 +4,6 @@ class Mention extends FeatureAbstract { - protected ?string $type = 'mention'; - protected function schema(): array { return [ @@ -18,9 +16,4 @@ public function __toString(): string { return "@$this->label"; } - - protected function type(): string - { - return 'mention'; - } } diff --git a/src/Lexicons/App/Bsky/RichText/Tag.php b/src/Lexicons/App/Bsky/RichText/Tag.php index a2d39d9..d56b27b 100644 --- a/src/Lexicons/App/Bsky/RichText/Tag.php +++ b/src/Lexicons/App/Bsky/RichText/Tag.php @@ -2,8 +2,6 @@ namespace Atproto\Lexicons\App\Bsky\RichText; -use Atproto\Lexicons\Traits\Serializable; - class Tag extends FeatureAbstract { protected function schema(): array @@ -18,9 +16,4 @@ public function __toString(): string { return "#$this->label"; } - - protected function type(): string - { - return 'tag'; - } } diff --git a/src/Lexicons/Com/Atproto/Label/SelfLabels.php b/src/Lexicons/Com/Atproto/Label/SelfLabels.php index 9ab75a6..ff56887 100644 --- a/src/Lexicons/Com/Atproto/Label/SelfLabels.php +++ b/src/Lexicons/Com/Atproto/Label/SelfLabels.php @@ -2,13 +2,12 @@ namespace Atproto\Lexicons\Com\Atproto\Label; -use Atproto\Contracts\LexiconContract; use Atproto\Contracts\SerializableContract; use Atproto\Exceptions\InvalidArgumentException; use Atproto\Lexicons\Traits\Serializable; use GenericCollection\GenericCollection; -class SelfLabels extends GenericCollection implements LexiconContract +class SelfLabels extends GenericCollection implements SerializableContract { use Serializable; diff --git a/src/Lexicons/Com/Atproto/Repo/CreateRecord.php b/src/Lexicons/Com/Atproto/Repo/CreateRecord.php index b863619..43d1040 100644 --- a/src/Lexicons/Com/Atproto/Repo/CreateRecord.php +++ b/src/Lexicons/Com/Atproto/Repo/CreateRecord.php @@ -22,13 +22,6 @@ class CreateRecord extends APIRequest implements LexiconContract 'record' ]; - protected function initialize(): void - { - parent::initialize(); - - $this->method('POST'); - } - public function repo(string $repo = null) { if (is_null($repo)) { diff --git a/src/Lexicons/Com/Atproto/Repo/StrongRef.php b/src/Lexicons/Com/Atproto/Repo/StrongRef.php index 39bc177..b4c07ea 100644 --- a/src/Lexicons/Com/Atproto/Repo/StrongRef.php +++ b/src/Lexicons/Com/Atproto/Repo/StrongRef.php @@ -3,11 +3,11 @@ namespace Atproto\Lexicons\Com\Atproto\Repo; use Atproto\Contracts\LexiconContract; -use Atproto\Lexicons\Traits\Serializable; +use Atproto\Lexicons\Traits\Lexicon; class StrongRef implements LexiconContract { - use Serializable; + use Lexicon; private string $uri; private string $cid; diff --git a/src/Lexicons/Com/Atproto/Repo/UploadBlob.php b/src/Lexicons/Com/Atproto/Repo/UploadBlob.php index 6d9a1fc..06caf6a 100644 --- a/src/Lexicons/Com/Atproto/Repo/UploadBlob.php +++ b/src/Lexicons/Com/Atproto/Repo/UploadBlob.php @@ -19,9 +19,11 @@ class UploadBlob extends APIRequest implements LexiconContract protected function initialize(): void { - parent::initialize(); - $this->method('POST') - ->header('Content-Type', '*/*'); + $this->origin(self::API_BASE_URL) + ->headers(self::API_BASE_HEADERS) + ->header('Content-Type', '*/*') + ->path(sprintf("/xrpc/%s", $this->nsid())) + ->method($this->method); } /** diff --git a/src/Lexicons/Com/Atproto/Server/CreateSession.php b/src/Lexicons/Com/Atproto/Server/CreateSession.php index ebb85db..8acc0f5 100644 --- a/src/Lexicons/Com/Atproto/Server/CreateSession.php +++ b/src/Lexicons/Com/Atproto/Server/CreateSession.php @@ -8,7 +8,6 @@ use Atproto\Contracts\Resources\ResourceContract; use Atproto\Lexicons\APIRequest; use Atproto\Lexicons\Traits\Endpoint; -use Atproto\Lexicons\Traits\Serializable; use Atproto\Resources\Com\Atproto\Server\CreateSessionResource; class CreateSession extends APIRequest implements LexiconContract @@ -19,7 +18,7 @@ public function __construct(Client $client, string $identifier, string $password { parent::__construct($client); - $this->method('POST')->origin('https://bsky.social/')->parameters([ + $this->parameters([ 'identifier' => $identifier, 'password' => $password, ]); diff --git a/src/Lexicons/Traits/AuthenticatedEndpoint.php b/src/Lexicons/Traits/AuthenticatedEndpoint.php index ec63d6a..e347c65 100644 --- a/src/Lexicons/Traits/AuthenticatedEndpoint.php +++ b/src/Lexicons/Traits/AuthenticatedEndpoint.php @@ -16,6 +16,8 @@ public function __construct(Client $client) return; } + $this->method = 'POST'; + parent::__construct($client); $this->update($client); } @@ -40,4 +42,12 @@ public function token(string $token = null) return $this; } + + protected function initialize(): void + { + $this->origin(self::API_BASE_URL) + ->headers(self::API_BASE_HEADERS) + ->path(sprintf("/xrpc/%s", $this->nsid())) + ->method($this->method); + } } diff --git a/src/Lexicons/Traits/Endpoint.php b/src/Lexicons/Traits/Endpoint.php index 7983ac9..2dcd99c 100644 --- a/src/Lexicons/Traits/Endpoint.php +++ b/src/Lexicons/Traits/Endpoint.php @@ -4,7 +4,9 @@ trait Endpoint { - use Serializable; + use Lexicon; + + protected string $method = 'GET'; public function jsonSerialize(): array { @@ -18,4 +20,12 @@ public function jsonSerialize(): array 'queryParameters' => $this->queryParameters(), ]; } + + protected function initialize(): void + { + $this->origin(self::API_BASE_URL) + ->headers(self::API_BASE_HEADERS) + ->path(sprintf("/xrpc/%s", $this->nsid())) + ->method($this->method); + } } diff --git a/src/Lexicons/Traits/Lexicon.php b/src/Lexicons/Traits/Lexicon.php new file mode 100644 index 0000000..190df89 --- /dev/null +++ b/src/Lexicons/Traits/Lexicon.php @@ -0,0 +1,18 @@ +getMockBuilder(FeatureAbstract::class) ->setConstructorArgs(['reference', 'label']) - ->onlyMethods(['schema', 'type']) + ->onlyMethods(['schema', 'nsid']) ->getMockForAbstractClass(); $schema = ['key' => 'value']; @@ -42,7 +42,7 @@ public function testJsonSerializeReturnsCorrectArray() ->willReturn($schema); $mock->expects($this->once()) - ->method('type') + ->method('nsid') ->willReturn('feature'); $this->assertSame( diff --git a/tests/Unit/Lexicons/App/Bsky/RichText/FeatureTests.php b/tests/Unit/Lexicons/App/Bsky/RichText/FeatureTests.php index b6237d5..1cad091 100644 --- a/tests/Unit/Lexicons/App/Bsky/RichText/FeatureTests.php +++ b/tests/Unit/Lexicons/App/Bsky/RichText/FeatureTests.php @@ -25,7 +25,7 @@ public function setUp(): void public function testTypeReturnsCorrectType(): void { $feature = $this->feature($this->reference); - $method = $this->method('type', $feature); + $method = $this->method('nsid', $feature); $expected = $this->type; $this->assertSame( From 5cfc5db4ece634372400e5bdd86ee7c2b6f46e4d Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sun, 3 Nov 2024 05:59:41 +0400 Subject: [PATCH 46/58] fix: refactor RichText feature serialization because they are not a lexicon --- .../App/Bsky/RichText/FeatureAbstract.php | 7 ------- src/Lexicons/App/Bsky/RichText/Link.php | 2 +- src/Lexicons/App/Bsky/RichText/Mention.php | 2 +- src/Lexicons/App/Bsky/RichText/Tag.php | 2 +- .../App/Bsky/RichText/FeatureAbstractTest.php | 11 +++-------- .../Lexicons/App/Bsky/RichText/FeatureTests.php | 17 ----------------- 6 files changed, 6 insertions(+), 35 deletions(-) diff --git a/src/Lexicons/App/Bsky/RichText/FeatureAbstract.php b/src/Lexicons/App/Bsky/RichText/FeatureAbstract.php index 62657bb..97593a7 100644 --- a/src/Lexicons/App/Bsky/RichText/FeatureAbstract.php +++ b/src/Lexicons/App/Bsky/RichText/FeatureAbstract.php @@ -21,11 +21,4 @@ public function __construct(string $reference, string $label = null) $this->reference = $reference; $this->label = $label; } - - final public function jsonSerialize(): array - { - return ['type' => $this->nsid()] + $this->schema(); - } - - abstract protected function schema(): array; } diff --git a/src/Lexicons/App/Bsky/RichText/Link.php b/src/Lexicons/App/Bsky/RichText/Link.php index 80ceebd..1f8afc0 100644 --- a/src/Lexicons/App/Bsky/RichText/Link.php +++ b/src/Lexicons/App/Bsky/RichText/Link.php @@ -4,7 +4,7 @@ class Link extends FeatureAbstract { - protected function schema(): array + public function jsonSerialize(): array { return [ "label" => $this->label, diff --git a/src/Lexicons/App/Bsky/RichText/Mention.php b/src/Lexicons/App/Bsky/RichText/Mention.php index 2b12f6b..9c499d1 100644 --- a/src/Lexicons/App/Bsky/RichText/Mention.php +++ b/src/Lexicons/App/Bsky/RichText/Mention.php @@ -4,7 +4,7 @@ class Mention extends FeatureAbstract { - protected function schema(): array + public function jsonSerialize(): array { return [ 'label' => "@$this->label", diff --git a/src/Lexicons/App/Bsky/RichText/Tag.php b/src/Lexicons/App/Bsky/RichText/Tag.php index d56b27b..67209b7 100644 --- a/src/Lexicons/App/Bsky/RichText/Tag.php +++ b/src/Lexicons/App/Bsky/RichText/Tag.php @@ -4,7 +4,7 @@ class Tag extends FeatureAbstract { - protected function schema(): array + public function jsonSerialize(): array { return [ "label" => "#$this->label", diff --git a/tests/Unit/Lexicons/App/Bsky/RichText/FeatureAbstractTest.php b/tests/Unit/Lexicons/App/Bsky/RichText/FeatureAbstractTest.php index 437c84d..3b33fab 100644 --- a/tests/Unit/Lexicons/App/Bsky/RichText/FeatureAbstractTest.php +++ b/tests/Unit/Lexicons/App/Bsky/RichText/FeatureAbstractTest.php @@ -18,7 +18,6 @@ public function testConstructorAssignsReferenceAndLabel() { $mock = $this->getMockBuilder(FeatureAbstract::class) ->setConstructorArgs(['reference', 'label']) - ->onlyMethods(['schema']) ->getMockForAbstractClass(); $reference = $this->getPropertyValue('reference', $mock); @@ -32,21 +31,17 @@ public function testJsonSerializeReturnsCorrectArray() { $mock = $this->getMockBuilder(FeatureAbstract::class) ->setConstructorArgs(['reference', 'label']) - ->onlyMethods(['schema', 'nsid']) + ->onlyMethods(['jsonSerialize']) ->getMockForAbstractClass(); $schema = ['key' => 'value']; $mock->expects($this->once()) - ->method('schema') + ->method('jsonSerialize') ->willReturn($schema); - $mock->expects($this->once()) - ->method('nsid') - ->willReturn('feature'); - $this->assertSame( - ['type' => 'feature'] + $schema, + $schema, $mock->jsonSerialize() ); } diff --git a/tests/Unit/Lexicons/App/Bsky/RichText/FeatureTests.php b/tests/Unit/Lexicons/App/Bsky/RichText/FeatureTests.php index 1cad091..2c537e7 100644 --- a/tests/Unit/Lexicons/App/Bsky/RichText/FeatureTests.php +++ b/tests/Unit/Lexicons/App/Bsky/RichText/FeatureTests.php @@ -19,21 +19,6 @@ public function setUp(): void $this->reference = 'reference'; } - /** - * @throws ReflectionException - */ - public function testTypeReturnsCorrectType(): void - { - $feature = $this->feature($this->reference); - $method = $this->method('nsid', $feature); - $expected = $this->type; - - $this->assertSame( - $expected, - $method->invoke($feature) - ); - } - public function test__toStringReturnsCorrectLabelWhenPassedBothParameters(): void { $feature = $this->feature($this->reference, $this->label); @@ -60,7 +45,6 @@ public function testSchemaReturnsCorrectSchemaWhenPassedBothParameters(): void $feature = $this->feature($this->reference, $this->label); $expected = [ - 'type' => $this->type, 'label' => $this->prefix . $this->label, $this->key => $this->reference, ]; @@ -78,7 +62,6 @@ public function testSchemaReturnsCorrectSchemaWhenPassedSingleParameter(): void private function schema(string $label): array { return [ - 'type' => $this->type, 'label' => $this->prefix . $label, $this->key => $this->reference, ]; From 21822c47f051128de483ca534c19b7f27f501ddf Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sun, 3 Nov 2024 06:00:44 +0400 Subject: [PATCH 47/58] fix: remove hardcoded credentials from test --- tests/Feature/Lexicons/Com/Atproto/Repo/CreateRecordTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Feature/Lexicons/Com/Atproto/Repo/CreateRecordTest.php b/tests/Feature/Lexicons/Com/Atproto/Repo/CreateRecordTest.php index e11a98d..0fd2434 100644 --- a/tests/Feature/Lexicons/Com/Atproto/Repo/CreateRecordTest.php +++ b/tests/Feature/Lexicons/Com/Atproto/Repo/CreateRecordTest.php @@ -23,8 +23,8 @@ public static function setUpBeforeClass(): void static::$client = new Client(); static::$client->authenticate( - 'shahmal1yevv.bsky.social', - 'ucvlqcq8' + getenv('BLUESKY_IDENTIFIER'), + getenv('BLUESKY_PASSWORD') ); } From 0fd1a3f34a9937b22c864fd985f90ed4ea7483a3 Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sun, 3 Nov 2024 06:03:45 +0400 Subject: [PATCH 48/58] Update workflow: remove the 'continue-on-error' flag from feature tests and add secrets a environment variables --- .github/workflows/php.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index f3b430b..a108bbd 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -16,6 +16,11 @@ jobs: matrix: php-version: ['7.4', '8.0', '8.1'] name: PHP ${{ matrix.php-version }} Test + + env: + BLUESKY_IDENTIFIER: ${{ secrets.BLUESKY_IDENTIFIER }} + BLUESKY_PASSWORD: ${{ secrets.BLUESKY_PASSWORD }} + steps: - uses: shivammathur/setup-php@v2 with: @@ -43,7 +48,6 @@ jobs: - name: Run Feature Tests run: composer run-script test-feature - continue-on-error: true - name: Static Analyse run: composer run-script analyse \ No newline at end of file From b19ea29219134b563b70585b720f7079252af48e Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sun, 3 Nov 2024 06:14:30 +0400 Subject: [PATCH 49/58] refactor: use getenv() instead of $_ENV superglobal --- tests/Feature/ClientTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Feature/ClientTest.php b/tests/Feature/ClientTest.php index 42c9b9a..a0fa951 100644 --- a/tests/Feature/ClientTest.php +++ b/tests/Feature/ClientTest.php @@ -33,8 +33,8 @@ public function setUp(): void */ public function testGetProfile(): void { - $username = $_ENV['BLUESKY_IDENTIFIER']; - $password = $_ENV['BLUESKY_PASSWORD']; + $username = getenv('BLUESKY_IDENTIFIER'); + $password = getenv('BLUESKY_PASSWORD'); $this->assertIsString($username); $this->assertIsString($password); @@ -106,8 +106,8 @@ public function testObserverNotificationOnAuthentication(): void ->forge(); $this->client->authenticate( - $_ENV['BLUESKY_IDENTIFIER'], - $_ENV['BLUESKY_PASSWORD'] + getenv('BLUESKY_IDENTIFIER'), + getenv('BLUESKY_PASSWORD') ); $response = $request->actor($this->client->authenticated()->did()) From 9bde17e0d5c2a3b6cfab404af58302c3d69469b7 Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sun, 3 Nov 2024 06:29:11 +0400 Subject: [PATCH 50/58] fix: standardize HTTP methods in API endpoints - Use explicit HTTP method definitions in each endpoint - Remove hardcoded POST method from AuthenticatedEndpoint trait - Add AuthenticatedEndpoint to GetFollowers endpoint - Fix initialization order in CreateSession endpoint --- src/Lexicons/App/Bsky/Graph/GetFollowers.php | 3 ++- src/Lexicons/Com/Atproto/Repo/CreateRecord.php | 8 ++++++++ src/Lexicons/Com/Atproto/Repo/UploadBlob.php | 2 +- src/Lexicons/Com/Atproto/Server/CreateSession.php | 2 +- src/Lexicons/Traits/AuthenticatedEndpoint.php | 2 -- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Lexicons/App/Bsky/Graph/GetFollowers.php b/src/Lexicons/App/Bsky/Graph/GetFollowers.php index c2a6040..91610c7 100644 --- a/src/Lexicons/App/Bsky/Graph/GetFollowers.php +++ b/src/Lexicons/App/Bsky/Graph/GetFollowers.php @@ -8,12 +8,13 @@ use Atproto\Exceptions\Http\MissingFieldProvidedException; use Atproto\Exceptions\InvalidArgumentException; use Atproto\Lexicons\APIRequest; +use Atproto\Lexicons\Traits\AuthenticatedEndpoint; use Atproto\Lexicons\Traits\Endpoint; use Atproto\Resources\App\Bsky\Graph\GetFollowersResource; class GetFollowers extends APIRequest implements LexiconContract { - use Endpoint; + use AuthenticatedEndpoint; public function actor(string $actor = null) { diff --git a/src/Lexicons/Com/Atproto/Repo/CreateRecord.php b/src/Lexicons/Com/Atproto/Repo/CreateRecord.php index 43d1040..59c6adc 100644 --- a/src/Lexicons/Com/Atproto/Repo/CreateRecord.php +++ b/src/Lexicons/Com/Atproto/Repo/CreateRecord.php @@ -22,6 +22,14 @@ class CreateRecord extends APIRequest implements LexiconContract 'record' ]; + protected function initialize(): void + { + $this->origin(self::API_BASE_URL) + ->headers(self::API_BASE_HEADERS) + ->path(sprintf("/xrpc/%s", $this->nsid())) + ->method('POST'); + } + public function repo(string $repo = null) { if (is_null($repo)) { diff --git a/src/Lexicons/Com/Atproto/Repo/UploadBlob.php b/src/Lexicons/Com/Atproto/Repo/UploadBlob.php index 06caf6a..9a5a92e 100644 --- a/src/Lexicons/Com/Atproto/Repo/UploadBlob.php +++ b/src/Lexicons/Com/Atproto/Repo/UploadBlob.php @@ -23,7 +23,7 @@ protected function initialize(): void ->headers(self::API_BASE_HEADERS) ->header('Content-Type', '*/*') ->path(sprintf("/xrpc/%s", $this->nsid())) - ->method($this->method); + ->method('POST'); } /** diff --git a/src/Lexicons/Com/Atproto/Server/CreateSession.php b/src/Lexicons/Com/Atproto/Server/CreateSession.php index 8acc0f5..10de78c 100644 --- a/src/Lexicons/Com/Atproto/Server/CreateSession.php +++ b/src/Lexicons/Com/Atproto/Server/CreateSession.php @@ -18,7 +18,7 @@ public function __construct(Client $client, string $identifier, string $password { parent::__construct($client); - $this->parameters([ + $this->method('POST')->parameters([ 'identifier' => $identifier, 'password' => $password, ]); diff --git a/src/Lexicons/Traits/AuthenticatedEndpoint.php b/src/Lexicons/Traits/AuthenticatedEndpoint.php index e347c65..461170c 100644 --- a/src/Lexicons/Traits/AuthenticatedEndpoint.php +++ b/src/Lexicons/Traits/AuthenticatedEndpoint.php @@ -16,8 +16,6 @@ public function __construct(Client $client) return; } - $this->method = 'POST'; - parent::__construct($client); $this->update($client); } From 89669480b7a1a8a729215b01d6245012ad00a8ad Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sun, 3 Nov 2024 08:52:47 +0400 Subject: [PATCH 51/58] refactor: improve RichText handling and blob upload --- src/Lexicons/App/Bsky/Feed/Post.php | 4 +- .../App/Bsky/RichText/FeatureAbstract.php | 21 +++++ src/Lexicons/App/Bsky/RichText/Link.php | 2 +- src/Lexicons/App/Bsky/RichText/Mention.php | 2 +- .../{FeatureFactory.php => RichText.php} | 2 +- src/Lexicons/App/Bsky/RichText/Tag.php | 2 +- src/Lexicons/Com/Atproto/Repo/UploadBlob.php | 15 +++- .../Com/Atproto/Repo/CreateRecordTest.php | 86 ++++++++----------- .../App/Bsky/RichText/FeatureTests.php | 4 + 9 files changed, 80 insertions(+), 58 deletions(-) rename src/Lexicons/App/Bsky/RichText/{FeatureFactory.php => RichText.php} (95%) diff --git a/src/Lexicons/App/Bsky/Feed/Post.php b/src/Lexicons/App/Bsky/Feed/Post.php index 1277fac..469535c 100644 --- a/src/Lexicons/App/Bsky/Feed/Post.php +++ b/src/Lexicons/App/Bsky/Feed/Post.php @@ -10,7 +10,7 @@ use Atproto\Lexicons\App\Bsky\RichText\ByteSlice; use Atproto\Lexicons\App\Bsky\RichText\Facet; use Atproto\Lexicons\App\Bsky\RichText\FeatureAbstract; -use Atproto\Lexicons\App\Bsky\RichText\FeatureFactory; +use Atproto\Lexicons\App\Bsky\RichText\RichText; use Atproto\Lexicons\Com\Atproto\Label\SelfLabels; use Atproto\Lexicons\Com\Atproto\Repo\StrongRef; use Atproto\Lexicons\Traits\Lexicon; @@ -272,7 +272,7 @@ private function processItem($item): void */ private function addFeatureItem(string $type, string $reference, ?string $label): PostBuilderContract { - $feature = FeatureFactory::{$type}($reference, $label); + $feature = RichText::{$type}($reference, $label); $this->addFeature($feature); return $this; diff --git a/src/Lexicons/App/Bsky/RichText/FeatureAbstract.php b/src/Lexicons/App/Bsky/RichText/FeatureAbstract.php index 97593a7..ab71af2 100644 --- a/src/Lexicons/App/Bsky/RichText/FeatureAbstract.php +++ b/src/Lexicons/App/Bsky/RichText/FeatureAbstract.php @@ -4,6 +4,7 @@ use Atproto\Contracts\LexiconContract; use Atproto\Lexicons\Traits\Lexicon; +use Atproto\Lexicons\Traits\Serializable; abstract class FeatureAbstract implements LexiconContract { @@ -21,4 +22,24 @@ public function __construct(string $reference, string $label = null) $this->reference = $reference; $this->label = $label; } + + public function jsonSerialize(): array + { + return ['$type' => sprintf("%s#%s", $this->nsid(), $this->type())] + $this->schema(); + } + + public function nsid(): string + { + return 'app.bsky.richtext.facet'; + } + + public function type(): string + { + $namespace = static::class; + $parts = explode('\\', $namespace); + + return strtolower(end($parts)); + } + + abstract protected function schema(): array; } diff --git a/src/Lexicons/App/Bsky/RichText/Link.php b/src/Lexicons/App/Bsky/RichText/Link.php index 1f8afc0..80ceebd 100644 --- a/src/Lexicons/App/Bsky/RichText/Link.php +++ b/src/Lexicons/App/Bsky/RichText/Link.php @@ -4,7 +4,7 @@ class Link extends FeatureAbstract { - public function jsonSerialize(): array + protected function schema(): array { return [ "label" => $this->label, diff --git a/src/Lexicons/App/Bsky/RichText/Mention.php b/src/Lexicons/App/Bsky/RichText/Mention.php index 9c499d1..2b12f6b 100644 --- a/src/Lexicons/App/Bsky/RichText/Mention.php +++ b/src/Lexicons/App/Bsky/RichText/Mention.php @@ -4,7 +4,7 @@ class Mention extends FeatureAbstract { - public function jsonSerialize(): array + protected function schema(): array { return [ 'label' => "@$this->label", diff --git a/src/Lexicons/App/Bsky/RichText/FeatureFactory.php b/src/Lexicons/App/Bsky/RichText/RichText.php similarity index 95% rename from src/Lexicons/App/Bsky/RichText/FeatureFactory.php rename to src/Lexicons/App/Bsky/RichText/RichText.php index 3000d05..3a1fcc1 100644 --- a/src/Lexicons/App/Bsky/RichText/FeatureFactory.php +++ b/src/Lexicons/App/Bsky/RichText/RichText.php @@ -2,7 +2,7 @@ namespace Atproto\Lexicons\App\Bsky\RichText; -class FeatureFactory +class RichText { public static function link(string $reference, string $label = null): Link { diff --git a/src/Lexicons/App/Bsky/RichText/Tag.php b/src/Lexicons/App/Bsky/RichText/Tag.php index 67209b7..d56b27b 100644 --- a/src/Lexicons/App/Bsky/RichText/Tag.php +++ b/src/Lexicons/App/Bsky/RichText/Tag.php @@ -4,7 +4,7 @@ class Tag extends FeatureAbstract { - public function jsonSerialize(): array + protected function schema(): array { return [ "label" => "#$this->label", diff --git a/src/Lexicons/Com/Atproto/Repo/UploadBlob.php b/src/Lexicons/Com/Atproto/Repo/UploadBlob.php index 9a5a92e..2f541db 100644 --- a/src/Lexicons/Com/Atproto/Repo/UploadBlob.php +++ b/src/Lexicons/Com/Atproto/Repo/UploadBlob.php @@ -32,18 +32,27 @@ protected function initialize(): void public function blob(string $blob = null) { if (is_null($blob)) { - return hex2bin($this->parameter('blob')); + return $this->parameter('blob'); } $blob = (! mb_check_encoding($blob, 'UTF-8')) ? $blob : (new FileSupport($blob))->getBlob(); - $this->parameter('blob', bin2hex($blob)); + $this->parameter('blob', $blob); return $this; } + public function parameters($parameters = null) + { + if (is_bool($parameters)) { + return $this->parameters['blob'] ?: ''; + } + + parent::parameters($parameters); + } + public function token(string $token = null) { if (is_null($token)) { @@ -76,7 +85,7 @@ public function build(): RequestContract public function resource(array $data): ResourceContract { return new UploadBlobResource([ - 'blob' => Blob::viaBinary(hex2bin($this->parameter('blob'))) + 'blob' => Blob::viaBinary($this->parameter('blob')) ]); } } diff --git a/tests/Feature/Lexicons/Com/Atproto/Repo/CreateRecordTest.php b/tests/Feature/Lexicons/Com/Atproto/Repo/CreateRecordTest.php index 0fd2434..3b16764 100644 --- a/tests/Feature/Lexicons/Com/Atproto/Repo/CreateRecordTest.php +++ b/tests/Feature/Lexicons/Com/Atproto/Repo/CreateRecordTest.php @@ -9,6 +9,10 @@ use Atproto\Exceptions\InvalidArgumentException; use Atproto\Lexicons\App\Bsky\Embed\Collections\ImageCollection; use Atproto\Lexicons\App\Bsky\Embed\Image; +use Atproto\Lexicons\App\Bsky\RichText\RichText; +use Atproto\Lexicons\App\Bsky\RichText\Link; +use Atproto\Lexicons\App\Bsky\RichText\Mention; +use Atproto\Lexicons\App\Bsky\RichText\Tag; use Atproto\Lexicons\Com\Atproto\Repo\CreateRecord; use Atproto\Support\Arr; use Atproto\Support\FileSupport; @@ -21,7 +25,6 @@ class CreateRecordTest extends TestCase public static function setUpBeforeClass(): void { static::$client = new Client(); - static::$client->authenticate( getenv('BLUESKY_IDENTIFIER'), getenv('BLUESKY_PASSWORD') @@ -35,39 +38,6 @@ public function testBuildCreateRecordRequestWithPost(): void { $client = static::$client; - $post = $client->app()->bsky()->feed()->post()->forge()->text( - "Hello World! ", - "This post was sent from a feature test of the BlueSky PHP SDK ", - ); - - $this->assertInstanceOf(PostBuilderContract::class, $post); - - $createRecord = $client->com()->atproto()->repo()->createRecord()->forge() - ->record($post) - ->repo($client->authenticated()->did()) - ->collection('app.bsky.feed.post'); - - $this->assertInstanceOf(CreateRecord::class, $createRecord); - - $serializedPost = json_decode($post, true); - $actualPost = Arr::get(json_decode($createRecord, true), 'record'); - - $this->assertSame($serializedPost, $actualPost); - - $response = $createRecord->send(); - - $this->assertIsString($response->uri()); - - echo $response->uri(); - } - - /** - * @throws BlueskyException - */ - public function testSendPostWithBlobUsingPostBuilderAPI(): void - { - $client = static::$client; - /** @var Blob $uploadBlob */ $uploadedBlob = $client->com() ->atproto() @@ -75,37 +45,55 @@ public function testSendPostWithBlobUsingPostBuilderAPI(): void ->uploadBlob() ->forge() // Atproto\Lexicons\Com\Atproto\Repo\UploadBlob ->token($client->authenticated()->accessJwt()) - ->blob(__DIR__.'/../../../../../../art/file.png') + ->blob(__DIR__.'/../../../../../../art/logo-small.webp') ->build() ->send() // Atproto\Resources\Com\Atproto\Repo\UploadBlobResource ->blob(); - $this->assertInstanceOf(Blob::class, $uploadedBlob); - $post = $client->app() ->bsky() ->feed() ->post() ->forge() - ->text("Hello World!") + ->text( + "Hello World! ", + "This post was sent from a feature test of the ", + RichText::link('https://github.com/shahmal1yev/blueskysdk', 'BlueSky PHP SDK'), + '. You can read the docs from ', + RichText::link('https://blueskysdk.shahmal1yev.dev', 'here'), + '. Author? Yes, ', + RichText::mention('did:plc:bdkw6ic5ugy6ni4pqvljcpva', 'here'), + ' it is. ', + RichText::tag('https://bsky.app/hashtag/php', 'php'), + " ", + RichText::tag('https://bsky.app/hashtag/sdk', 'sdk'), + " ", + RichText::tag('https://bsky.app/hashtag/bluesky', 'bluesky'), + ) ->embed(new ImageCollection([ - new Image($uploadedBlob, "Alt text") + new Image($uploadedBlob, "PHP BlueSky SDK Logo") ])); + $this->assertInstanceOf(PostBuilderContract::class, $post); - $createdRecord = $client->com() - ->atproto() - ->repo() - ->createRecord() - ->forge() - ->record($post) + /** @var CreateRecord $createRecord */ + $createRecord = $client->com()->atproto()->repo()->createRecord()->forge(); + + $createRecord->record($post) ->repo($client->authenticated()->did()) - ->collection('app.bsky.feed.post') - ->build() - ->send(); + ->collection($post->nsid()); - $this->assertIsString($createdRecord->uri()); + $this->assertInstanceOf(CreateRecord::class, $createRecord); + + $serializedPost = json_decode($post, true); + $actualPost = Arr::get(json_decode($createRecord, true), 'record'); + + $this->assertSame($serializedPost, $actualPost); + + $response = $createRecord->send(); + + $this->assertIsString($response->uri()); } /** diff --git a/tests/Unit/Lexicons/App/Bsky/RichText/FeatureTests.php b/tests/Unit/Lexicons/App/Bsky/RichText/FeatureTests.php index 2c537e7..cf07f59 100644 --- a/tests/Unit/Lexicons/App/Bsky/RichText/FeatureTests.php +++ b/tests/Unit/Lexicons/App/Bsky/RichText/FeatureTests.php @@ -10,6 +10,8 @@ trait FeatureTests { use Reflection; + private string $nsid = 'app.bsky.richtext.facet'; + private string $label; private string $reference; @@ -45,6 +47,7 @@ public function testSchemaReturnsCorrectSchemaWhenPassedBothParameters(): void $feature = $this->feature($this->reference, $this->label); $expected = [ + '$type' => $feature->nsid() . "#" . $feature->type(), 'label' => $this->prefix . $this->label, $this->key => $this->reference, ]; @@ -62,6 +65,7 @@ public function testSchemaReturnsCorrectSchemaWhenPassedSingleParameter(): void private function schema(string $label): array { return [ + '$type' => sprintf("%s#%s", $this->nsid, $this->type), 'label' => $this->prefix . $label, $this->key => $this->reference, ]; From 8cff56880da5408b53d50871165f1066606e5e67 Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Thu, 7 Nov 2024 00:15:54 +0400 Subject: [PATCH 52/58] refactor: rename Resource to Response and Asset to Object for better semantics --- README.md | 16 +++---- .../Types/NonPrimitive/FollowerAssetType.php | 4 +- .../Types/NonPrimitive/LabelAssetType.php | 4 +- .../Types/NonPrimitive/ProfileAssetType.php | 4 +- .../{AssetContract.php => ObjectContract.php} | 2 +- ...ourceContract.php => ResponseContract.php} | 2 +- src/Lexicons/APIRequest.php | 8 ++-- src/Lexicons/App/Bsky/Actor/GetProfile.php | 8 ++-- src/Lexicons/App/Bsky/Actor/GetProfiles.php | 8 ++-- src/Lexicons/App/Bsky/Graph/GetFollowers.php | 8 ++-- .../Com/Atproto/Repo/CreateRecord.php | 8 ++-- src/Lexicons/Com/Atproto/Repo/UploadBlob.php | 8 ++-- .../Com/Atproto/Server/CreateSession.php | 8 ++-- src/Lexicons/Traits/RequestHandler.php | 4 +- .../App/Bsky/Actor/GetProfileResource.php | 33 ------------- .../App/Bsky/Actor/GetProfilesResource.php | 21 --------- .../App/Bsky/Graph/GetFollowersResource.php | 30 ------------ src/Resources/Assets/AssociatedAsset.php | 34 -------------- src/Resources/Assets/BlockingByListAsset.php | 23 --------- src/Resources/Assets/ChatAsset.php | 26 ---------- src/Resources/Assets/CreatorAsset.php | 28 ----------- src/Resources/Assets/DatetimeAsset.php | 16 ------- src/Resources/Assets/FollowerAsset.php | 21 --------- .../Assets/JoinedViaStarterPackAsset.php | 40 ---------------- src/Resources/Assets/KnownFollowersAsset.php | 26 ---------- src/Resources/Assets/LabelAsset.php | 38 --------------- src/Resources/Assets/MutedByListAsset.php | 23 --------- src/Resources/Assets/ProfileAsset.php | 11 ----- src/Resources/Assets/SubjectAsset.php | 11 ----- src/Resources/Assets/UserAsset.php | 47 ------------------- src/Resources/Assets/ViewerAsset.php | 41 ---------------- .../Com/Atproto/Repo/CreateRecordResource.php | 11 ----- .../Com/Atproto/Repo/UploadBlobResource.php | 14 ------ .../App/Bsky/Actor/GetProfileResponse.php | 33 +++++++++++++ .../App/Bsky/Actor/GetProfilesResponse.php | 21 +++++++++ .../App/Bsky/Graph/GetFollowersResponse.php | 30 ++++++++++++ .../BaseResponse.php} | 8 ++-- .../Com/Atproto/Repo/CreateRecordResponse.php | 11 +++++ .../Com/Atproto/Repo/UploadBlobResponse.php | 14 ++++++ .../Atproto/Server/CreateSessionResponse.php} | 10 ++-- src/Responses/Objects/AssociatedObject.php | 34 ++++++++++++++ .../Objects/BaseObject.php} | 8 ++-- .../Objects/BlockingByListObject.php | 23 +++++++++ .../Objects}/ByListAsset.php | 18 +++---- src/Responses/Objects/ChatObject.php | 26 ++++++++++ .../Objects}/CollectionAsset.php | 8 ++-- src/Responses/Objects/CreatorObject.php | 28 +++++++++++ src/Responses/Objects/DatetimeObject.php | 16 +++++++ src/Responses/Objects/FollowerObject.php | 21 +++++++++ .../Objects/FollowersObject.php} | 10 ++-- .../Objects/JoinedViaStarterPackObject.php | 40 ++++++++++++++++ .../Objects/KnownFollowersObject.php | 26 ++++++++++ src/Responses/Objects/LabelObject.php | 38 +++++++++++++++ .../Objects/LabelsObject.php} | 10 ++-- src/Responses/Objects/MutedByListObject.php | 23 +++++++++ src/Responses/Objects/ProfileObject.php | 11 +++++ .../Objects/ProfilesObject.php} | 10 ++-- src/Responses/Objects/SubjectObject.php | 11 +++++ src/Responses/Objects/UserObject.php | 47 +++++++++++++++++++ src/Responses/Objects/ViewerObject.php | 41 ++++++++++++++++ src/Traits/Authentication.php | 8 ++-- tests/Feature/ClientTest.php | 18 +++---- .../App/Bsky/Graph/GetFollowersTest.php | 4 +- tests/Supports/ByListAssetTest.php | 8 ++-- tests/Supports/NonPrimitiveAssetTest.php | 4 +- tests/Supports/UserAssetTest.php | 12 ++--- tests/Unit/ClientTest.php | 4 +- .../App/Bsky/Actor/GetProfilesTest.php | 6 +-- .../App/Bsky/Graph/GetFollowersTest.php | 6 +-- .../Assets/BlockingByListAssetTest.php | 21 --------- .../Resources/Assets/CreatorAssetTest.php | 17 ------- .../Resources/Assets/FollowerAssetTest.php | 23 --------- .../Resources/Assets/MutedByListAssetTest.php | 21 --------- .../Unit/Resources/Assets/ViewerAssetTest.php | 45 ------------------ .../Bsky/Actor/GetProfileResponseTest.php} | 30 ++++++------ .../Assets/AssociatedObjectTest.php} | 14 +++--- .../Assets/BaseObjectTest.php} | 22 ++++----- .../Assets/BlockingByListObjectTest.php | 21 +++++++++ .../Assets/ChatObjectTest.php} | 10 ++-- .../Assets/CollectionObjectTest.php} | 38 +++++++-------- .../Responses/Assets/CreatorObjectTest.php | 17 +++++++ .../Assets/DatetimeObjectTest.php} | 12 ++--- .../Responses/Assets/FollowerObjectTest.php | 23 +++++++++ .../Assets/FollowersObjectTest.php} | 46 +++++++++--------- .../JoinedViaStarterPackObjectTest.php} | 18 +++---- .../Assets/KnownFollowersObjectTest.php} | 14 +++--- .../Assets/LabelObjectTest.php} | 12 ++--- .../Assets/LabelsObjectTest.php} | 20 ++++---- .../Assets/MutedByListObjectTest.php | 21 +++++++++ .../Assets/UserObjectTest.php} | 40 ++++++++-------- .../Responses/Assets/ViewerObjectTest.php | 45 ++++++++++++++++++ .../BaseResponseTest.php} | 30 ++++++------ 92 files changed, 896 insertions(+), 896 deletions(-) rename src/Contracts/Resources/{AssetContract.php => ObjectContract.php} (81%) rename src/Contracts/Resources/{ResourceContract.php => ResponseContract.php} (95%) delete mode 100644 src/Resources/App/Bsky/Actor/GetProfileResource.php delete mode 100644 src/Resources/App/Bsky/Actor/GetProfilesResource.php delete mode 100644 src/Resources/App/Bsky/Graph/GetFollowersResource.php delete mode 100644 src/Resources/Assets/AssociatedAsset.php delete mode 100644 src/Resources/Assets/BlockingByListAsset.php delete mode 100644 src/Resources/Assets/ChatAsset.php delete mode 100644 src/Resources/Assets/CreatorAsset.php delete mode 100644 src/Resources/Assets/DatetimeAsset.php delete mode 100644 src/Resources/Assets/FollowerAsset.php delete mode 100644 src/Resources/Assets/JoinedViaStarterPackAsset.php delete mode 100644 src/Resources/Assets/KnownFollowersAsset.php delete mode 100644 src/Resources/Assets/LabelAsset.php delete mode 100644 src/Resources/Assets/MutedByListAsset.php delete mode 100644 src/Resources/Assets/ProfileAsset.php delete mode 100644 src/Resources/Assets/SubjectAsset.php delete mode 100644 src/Resources/Assets/UserAsset.php delete mode 100644 src/Resources/Assets/ViewerAsset.php delete mode 100644 src/Resources/Com/Atproto/Repo/CreateRecordResource.php delete mode 100644 src/Resources/Com/Atproto/Repo/UploadBlobResource.php create mode 100644 src/Responses/App/Bsky/Actor/GetProfileResponse.php create mode 100644 src/Responses/App/Bsky/Actor/GetProfilesResponse.php create mode 100644 src/Responses/App/Bsky/Graph/GetFollowersResponse.php rename src/{Resources/BaseResource.php => Responses/BaseResponse.php} (90%) create mode 100644 src/Responses/Com/Atproto/Repo/CreateRecordResponse.php create mode 100644 src/Responses/Com/Atproto/Repo/UploadBlobResponse.php rename src/{Resources/Com/Atproto/Server/CreateSessionResource.php => Responses/Com/Atproto/Server/CreateSessionResponse.php} (69%) create mode 100644 src/Responses/Objects/AssociatedObject.php rename src/{Resources/Assets/BaseAsset.php => Responses/Objects/BaseObject.php} (65%) create mode 100644 src/Responses/Objects/BlockingByListObject.php rename src/{Resources/Assets => Responses/Objects}/ByListAsset.php (58%) create mode 100644 src/Responses/Objects/ChatObject.php rename src/{Resources/Assets => Responses/Objects}/CollectionAsset.php (74%) create mode 100644 src/Responses/Objects/CreatorObject.php create mode 100644 src/Responses/Objects/DatetimeObject.php create mode 100644 src/Responses/Objects/FollowerObject.php rename src/{Resources/Assets/FollowersAsset.php => Responses/Objects/FollowersObject.php} (62%) create mode 100644 src/Responses/Objects/JoinedViaStarterPackObject.php create mode 100644 src/Responses/Objects/KnownFollowersObject.php create mode 100644 src/Responses/Objects/LabelObject.php rename src/{Resources/Assets/LabelsAsset.php => Responses/Objects/LabelsObject.php} (62%) create mode 100644 src/Responses/Objects/MutedByListObject.php create mode 100644 src/Responses/Objects/ProfileObject.php rename src/{Resources/Assets/ProfilesAsset.php => Responses/Objects/ProfilesObject.php} (62%) create mode 100644 src/Responses/Objects/SubjectObject.php create mode 100644 src/Responses/Objects/UserObject.php create mode 100644 src/Responses/Objects/ViewerObject.php delete mode 100644 tests/Unit/Resources/Assets/BlockingByListAssetTest.php delete mode 100644 tests/Unit/Resources/Assets/CreatorAssetTest.php delete mode 100644 tests/Unit/Resources/Assets/FollowerAssetTest.php delete mode 100644 tests/Unit/Resources/Assets/MutedByListAssetTest.php delete mode 100644 tests/Unit/Resources/Assets/ViewerAssetTest.php rename tests/Unit/{Resources/App/Bsky/Actor/GetProfileResourceTest.php => Responses/App/Bsky/Actor/GetProfileResponseTest.php} (56%) rename tests/Unit/{Resources/Assets/AssociatedAssetTest.php => Responses/Assets/AssociatedObjectTest.php} (71%) rename tests/Unit/{Resources/Assets/BaseAssetTest.php => Responses/Assets/BaseObjectTest.php} (64%) create mode 100644 tests/Unit/Responses/Assets/BlockingByListObjectTest.php rename tests/Unit/{Resources/Assets/ChatAssetTest.php => Responses/Assets/ChatObjectTest.php} (56%) rename tests/Unit/{Resources/Assets/CollectionAssetTest.php => Responses/Assets/CollectionObjectTest.php} (64%) create mode 100644 tests/Unit/Responses/Assets/CreatorObjectTest.php rename tests/Unit/{Resources/Assets/DatetimeAssetTest.php => Responses/Assets/DatetimeObjectTest.php} (79%) create mode 100644 tests/Unit/Responses/Assets/FollowerObjectTest.php rename tests/Unit/{Resources/Assets/FollowersAssetTest.php => Responses/Assets/FollowersObjectTest.php} (75%) rename tests/Unit/{Resources/Assets/JoinedViaStarterPackAssetTest.php => Responses/Assets/JoinedViaStarterPackObjectTest.php} (73%) rename tests/Unit/{Resources/Assets/KnownFollowersAssetTest.php => Responses/Assets/KnownFollowersObjectTest.php} (67%) rename tests/Unit/{Resources/Assets/LabelAssetTest.php => Responses/Assets/LabelObjectTest.php} (83%) rename tests/Unit/{Resources/Assets/LabelsAssetTest.php => Responses/Assets/LabelsObjectTest.php} (77%) create mode 100644 tests/Unit/Responses/Assets/MutedByListObjectTest.php rename tests/Unit/{Resources/Assets/UserAssetTest.php => Responses/Assets/UserObjectTest.php} (74%) create mode 100644 tests/Unit/Responses/Assets/ViewerObjectTest.php rename tests/Unit/{Resources/BaseResourceTest.php => Responses/BaseResponseTest.php} (58%) diff --git a/README.md b/README.md index 444d39b..5167fff 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ First, instantiate the `Client` class and authenticate using your BlueSky creden ```php use Atproto\Client; -use Atproto\Resources\Com\Atproto\Server\CreateSessionResource; +use Atproto\Responses\Com\Atproto\Server\CreateSessionResponse; $client = new Client(); @@ -50,7 +50,7 @@ $client = new Client(); $client->authenticate($identifier, $password); // Once authenticated, you can retrieve the user's session resource -/** @var CreateSessionResource $session */ +/** @var CreateSessionResponse $session */ $session = $client->authenticated(); ``` @@ -94,17 +94,17 @@ $createdAt = $profile->createdAt(); BlueSky SDK allows you to access complex assets like followers and labels directly through the resource instances. ```php -use Atproto\Resources\Assets\FollowersAsset; -use Atproto\Resources\Assets\FollowerAsset; +use Atproto\Responses\Objects\FollowersObject; +use Atproto\Responses\Objects\FollowerObject; // Fetch the user's followers -/** @var FollowersAsset $followers */ +/** @var FollowersObject $followers */ $followers = $profile->viewer() ->knownFollowers() ->followers(); foreach ($followers as $follower) { - /** @var FollowerAsset $follower */ + /** @var FollowerObject $follower */ echo $follower->displayName() . " - Created at: " . $follower->createdAt()->format(DATE_ATOM) . "\n"; } ``` @@ -116,7 +116,7 @@ Here is a more complete example of fetching and displaying profile information, ```php use Atproto\Client; use Atproto\API\App\Bsky\Actor\GetProfile; -use Atproto\Resources\App\Bsky\Actor\GetProfileResource; +use Atproto\Responses\App\Bsky\Actor\GetProfileResponse; $client->authenticate('user@example.com', 'password'); @@ -127,7 +127,7 @@ $client->app() ->forge(); // ->actor($client->authenticated()->did()); -/** @var GetProfileResource $user */ +/** @var GetProfileResponse $user */ $user = $client->send(); // Output profile details diff --git a/src/Collections/Types/NonPrimitive/FollowerAssetType.php b/src/Collections/Types/NonPrimitive/FollowerAssetType.php index 9e156e3..fff2403 100644 --- a/src/Collections/Types/NonPrimitive/FollowerAssetType.php +++ b/src/Collections/Types/NonPrimitive/FollowerAssetType.php @@ -2,13 +2,13 @@ namespace Atproto\Collections\Types\NonPrimitive; -use Atproto\Resources\Assets\FollowerAsset; +use Atproto\Responses\Objects\FollowerObject; use GenericCollection\Interfaces\TypeInterface; class FollowerAssetType implements TypeInterface { public function validate($value): bool { - return $value instanceof FollowerAsset; + return $value instanceof FollowerObject; } } diff --git a/src/Collections/Types/NonPrimitive/LabelAssetType.php b/src/Collections/Types/NonPrimitive/LabelAssetType.php index 03cfec6..d555be4 100644 --- a/src/Collections/Types/NonPrimitive/LabelAssetType.php +++ b/src/Collections/Types/NonPrimitive/LabelAssetType.php @@ -2,13 +2,13 @@ namespace Atproto\Collections\Types\NonPrimitive; -use Atproto\Resources\Assets\LabelAsset; +use Atproto\Responses\Objects\LabelObject; use GenericCollection\Interfaces\TypeInterface; class LabelAssetType implements TypeInterface { public function validate($value): bool { - return $value instanceof LabelAsset; + return $value instanceof LabelObject; } } diff --git a/src/Collections/Types/NonPrimitive/ProfileAssetType.php b/src/Collections/Types/NonPrimitive/ProfileAssetType.php index b64bf70..8f87cb3 100644 --- a/src/Collections/Types/NonPrimitive/ProfileAssetType.php +++ b/src/Collections/Types/NonPrimitive/ProfileAssetType.php @@ -2,13 +2,13 @@ namespace Atproto\Collections\Types\NonPrimitive; -use Atproto\Resources\Assets\ProfileAsset; +use Atproto\Responses\Objects\ProfileObject; use GenericCollection\Interfaces\TypeInterface; class ProfileAssetType implements TypeInterface { public function validate($value): bool { - return $value instanceof ProfileAsset; + return $value instanceof ProfileObject; } } diff --git a/src/Contracts/Resources/AssetContract.php b/src/Contracts/Resources/ObjectContract.php similarity index 81% rename from src/Contracts/Resources/AssetContract.php rename to src/Contracts/Resources/ObjectContract.php index a283e43..a2648d7 100644 --- a/src/Contracts/Resources/AssetContract.php +++ b/src/Contracts/Resources/ObjectContract.php @@ -2,7 +2,7 @@ namespace Atproto\Contracts\Resources; -interface AssetContract +interface ObjectContract { public function cast(); public function revert(); diff --git a/src/Contracts/Resources/ResourceContract.php b/src/Contracts/Resources/ResponseContract.php similarity index 95% rename from src/Contracts/Resources/ResourceContract.php rename to src/Contracts/Resources/ResponseContract.php index 816375d..abc52e6 100644 --- a/src/Contracts/Resources/ResourceContract.php +++ b/src/Contracts/Resources/ResponseContract.php @@ -12,7 +12,7 @@ * @see CreateRecord * @see UploadBlob */ -interface ResourceContract +interface ResponseContract { /** * @param string $name diff --git a/src/Lexicons/APIRequest.php b/src/Lexicons/APIRequest.php index e1fc6d3..9c6e427 100644 --- a/src/Lexicons/APIRequest.php +++ b/src/Lexicons/APIRequest.php @@ -4,7 +4,7 @@ use Atproto\Client; use Atproto\Contracts\Lexicons\APIRequestContract; -use Atproto\Contracts\Resources\ResourceContract; +use Atproto\Contracts\Resources\ResponseContract; use SplSubject; abstract class APIRequest extends Request implements APIRequestContract @@ -17,14 +17,14 @@ public function __construct(Client $client) $this->initialize(); } - public function send(): ResourceContract + public function send(): ResponseContract { - return $this->resource(parent::send()); + return $this->response(parent::send()); } abstract protected function initialize(): void; - abstract public function resource(array $data): ResourceContract; + abstract public function response(array $data): ResponseContract; public function update(SplSubject $subject): void { diff --git a/src/Lexicons/App/Bsky/Actor/GetProfile.php b/src/Lexicons/App/Bsky/Actor/GetProfile.php index 5307585..0adf153 100644 --- a/src/Lexicons/App/Bsky/Actor/GetProfile.php +++ b/src/Lexicons/App/Bsky/Actor/GetProfile.php @@ -4,12 +4,12 @@ use Atproto\Contracts\LexiconContract; use Atproto\Contracts\Lexicons\RequestContract; -use Atproto\Contracts\Resources\ResourceContract; +use Atproto\Contracts\Resources\ResponseContract; use Atproto\Exceptions\Http\MissingFieldProvidedException; use Atproto\Exceptions\Http\Response\AuthMissingException; use Atproto\Lexicons\APIRequest; use Atproto\Lexicons\Traits\AuthenticatedEndpoint; -use Atproto\Resources\App\Bsky\Actor\GetProfileResource; +use Atproto\Responses\App\Bsky\Actor\GetProfileResponse; use Exception; class GetProfile extends APIRequest implements LexiconContract @@ -60,8 +60,8 @@ public function build(): RequestContract return $this; } - public function resource(array $data): ResourceContract + public function response(array $data): ResponseContract { - return new GetProfileResource($data); + return new GetProfileResponse($data); } } diff --git a/src/Lexicons/App/Bsky/Actor/GetProfiles.php b/src/Lexicons/App/Bsky/Actor/GetProfiles.php index 72a4793..0bb137a 100644 --- a/src/Lexicons/App/Bsky/Actor/GetProfiles.php +++ b/src/Lexicons/App/Bsky/Actor/GetProfiles.php @@ -4,13 +4,13 @@ use Atproto\Contracts\LexiconContract; use Atproto\Contracts\Lexicons\RequestContract; -use Atproto\Contracts\Resources\ResourceContract; +use Atproto\Contracts\Resources\ResponseContract; use Atproto\Exceptions\Auth\AuthRequired; use Atproto\Exceptions\Http\MissingFieldProvidedException; use Atproto\Exceptions\InvalidArgumentException; use Atproto\Lexicons\APIRequest; use Atproto\Lexicons\Traits\AuthenticatedEndpoint; -use Atproto\Resources\App\Bsky\Actor\GetProfilesResource; +use Atproto\Responses\App\Bsky\Actor\GetProfilesResponse; use GenericCollection\Interfaces\GenericCollectionInterface; use GenericCollection\Types\Primitive\StringType; @@ -20,9 +20,9 @@ class GetProfiles extends APIRequest implements LexiconContract private ?GenericCollectionInterface $actors = null; - public function resource(array $data): ResourceContract + public function response(array $data): ResponseContract { - return new GetProfilesResource($data); + return new GetProfilesResponse($data); } /** diff --git a/src/Lexicons/App/Bsky/Graph/GetFollowers.php b/src/Lexicons/App/Bsky/Graph/GetFollowers.php index 91610c7..ffb0aa7 100644 --- a/src/Lexicons/App/Bsky/Graph/GetFollowers.php +++ b/src/Lexicons/App/Bsky/Graph/GetFollowers.php @@ -4,13 +4,13 @@ use Atproto\Contracts\LexiconContract; use Atproto\Contracts\Lexicons\RequestContract; -use Atproto\Contracts\Resources\ResourceContract; +use Atproto\Contracts\Resources\ResponseContract; use Atproto\Exceptions\Http\MissingFieldProvidedException; use Atproto\Exceptions\InvalidArgumentException; use Atproto\Lexicons\APIRequest; use Atproto\Lexicons\Traits\AuthenticatedEndpoint; use Atproto\Lexicons\Traits\Endpoint; -use Atproto\Resources\App\Bsky\Graph\GetFollowersResource; +use Atproto\Responses\App\Bsky\Graph\GetFollowersResponse; class GetFollowers extends APIRequest implements LexiconContract { @@ -56,9 +56,9 @@ public function cursor(string $cursor = null) return $this; } - public function resource(array $data): ResourceContract + public function response(array $data): ResponseContract { - return new GetFollowersResource($data); + return new GetFollowersResponse($data); } /** diff --git a/src/Lexicons/Com/Atproto/Repo/CreateRecord.php b/src/Lexicons/Com/Atproto/Repo/CreateRecord.php index 59c6adc..6b1c13b 100644 --- a/src/Lexicons/Com/Atproto/Repo/CreateRecord.php +++ b/src/Lexicons/Com/Atproto/Repo/CreateRecord.php @@ -5,12 +5,12 @@ use Atproto\Contracts\LexiconContract; use Atproto\Contracts\Lexicons\App\Bsky\Feed\PostBuilderContract; use Atproto\Contracts\Lexicons\RequestContract; -use Atproto\Contracts\Resources\ResourceContract; +use Atproto\Contracts\Resources\ResponseContract; use Atproto\Exceptions\Http\MissingFieldProvidedException; use Atproto\Exceptions\InvalidArgumentException; use Atproto\Lexicons\APIRequest; use Atproto\Lexicons\Traits\AuthenticatedEndpoint; -use Atproto\Resources\Com\Atproto\Repo\CreateRecordResource; +use Atproto\Responses\Com\Atproto\Repo\CreateRecordResponse; class CreateRecord extends APIRequest implements LexiconContract { @@ -121,9 +121,9 @@ public function build(): RequestContract return $this; } - public function resource(array $data): ResourceContract + public function response(array $data): ResponseContract { - return new CreateRecordResource($data); + return new CreateRecordResponse($data); } public function jsonSerialize(): array diff --git a/src/Lexicons/Com/Atproto/Repo/UploadBlob.php b/src/Lexicons/Com/Atproto/Repo/UploadBlob.php index 2f541db..4efa836 100644 --- a/src/Lexicons/Com/Atproto/Repo/UploadBlob.php +++ b/src/Lexicons/Com/Atproto/Repo/UploadBlob.php @@ -4,13 +4,13 @@ use Atproto\Contracts\LexiconContract; use Atproto\Contracts\Lexicons\RequestContract; -use Atproto\Contracts\Resources\ResourceContract; +use Atproto\Contracts\Resources\ResponseContract; use Atproto\DataModel\Blob\Blob; use Atproto\Exceptions\Http\MissingFieldProvidedException; use Atproto\Exceptions\InvalidArgumentException; use Atproto\Lexicons\APIRequest; use Atproto\Lexicons\Traits\AuthenticatedEndpoint; -use Atproto\Resources\Com\Atproto\Repo\UploadBlobResource; +use Atproto\Responses\Com\Atproto\Repo\UploadBlobResponse; use Atproto\Support\FileSupport; class UploadBlob extends APIRequest implements LexiconContract @@ -82,9 +82,9 @@ public function build(): RequestContract return $this; } - public function resource(array $data): ResourceContract + public function response(array $data): ResponseContract { - return new UploadBlobResource([ + return new UploadBlobResponse([ 'blob' => Blob::viaBinary($this->parameter('blob')) ]); } diff --git a/src/Lexicons/Com/Atproto/Server/CreateSession.php b/src/Lexicons/Com/Atproto/Server/CreateSession.php index 10de78c..7fd5dec 100644 --- a/src/Lexicons/Com/Atproto/Server/CreateSession.php +++ b/src/Lexicons/Com/Atproto/Server/CreateSession.php @@ -5,10 +5,10 @@ use Atproto\Client; use Atproto\Contracts\LexiconContract; use Atproto\Contracts\Lexicons\RequestContract; -use Atproto\Contracts\Resources\ResourceContract; +use Atproto\Contracts\Resources\ResponseContract; use Atproto\Lexicons\APIRequest; use Atproto\Lexicons\Traits\Endpoint; -use Atproto\Resources\Com\Atproto\Server\CreateSessionResource; +use Atproto\Responses\Com\Atproto\Server\CreateSessionResponse; class CreateSession extends APIRequest implements LexiconContract { @@ -29,8 +29,8 @@ public function build(): RequestContract return $this; } - public function resource(array $data): ResourceContract + public function response(array $data): ResponseContract { - return new CreateSessionResource($data); + return new CreateSessionResponse($data); } } diff --git a/src/Lexicons/Traits/RequestHandler.php b/src/Lexicons/Traits/RequestHandler.php index 9be41e8..dd0b6f6 100644 --- a/src/Lexicons/Traits/RequestHandler.php +++ b/src/Lexicons/Traits/RequestHandler.php @@ -2,13 +2,13 @@ namespace Atproto\Lexicons\Traits; -use Atproto\Contracts\Resources\ResourceContract; +use Atproto\Contracts\Resources\ResponseContract; use Atproto\Exceptions\BlueskyException; use Atproto\Exceptions\cURLException; trait RequestHandler { - /** @var resource|ResourceContract $resource */ + /** @var resource|ResponseContract $resource */ private $resource; /** @var array $responseHeaders */ diff --git a/src/Resources/App/Bsky/Actor/GetProfileResource.php b/src/Resources/App/Bsky/Actor/GetProfileResource.php deleted file mode 100644 index e087373..0000000 --- a/src/Resources/App/Bsky/Actor/GetProfileResource.php +++ /dev/null @@ -1,33 +0,0 @@ - ProfilesAsset::class - ]; - } -} diff --git a/src/Resources/App/Bsky/Graph/GetFollowersResource.php b/src/Resources/App/Bsky/Graph/GetFollowersResource.php deleted file mode 100644 index 3db3eb8..0000000 --- a/src/Resources/App/Bsky/Graph/GetFollowersResource.php +++ /dev/null @@ -1,30 +0,0 @@ -content = $content; - } - - protected function casts(): array - { - return [ - 'followers' => FollowersAsset::class, - 'subject' => SubjectAsset::class, - ]; - } -} diff --git a/src/Resources/Assets/AssociatedAsset.php b/src/Resources/Assets/AssociatedAsset.php deleted file mode 100644 index 43c3532..0000000 --- a/src/Resources/Assets/AssociatedAsset.php +++ /dev/null @@ -1,34 +0,0 @@ -content = $content; - } - - protected function casts(): array - { - return [ - 'chat' => ChatAsset::class, - ]; - } -} diff --git a/src/Resources/Assets/BlockingByListAsset.php b/src/Resources/Assets/BlockingByListAsset.php deleted file mode 100644 index 1ad6a52..0000000 --- a/src/Resources/Assets/BlockingByListAsset.php +++ /dev/null @@ -1,23 +0,0 @@ -content = $content; - } - - public function cast(): self - { - return $this; - } -} diff --git a/src/Resources/Assets/CreatorAsset.php b/src/Resources/Assets/CreatorAsset.php deleted file mode 100644 index 3ecaeba..0000000 --- a/src/Resources/Assets/CreatorAsset.php +++ /dev/null @@ -1,28 +0,0 @@ -value); - } -} diff --git a/src/Resources/Assets/FollowerAsset.php b/src/Resources/Assets/FollowerAsset.php deleted file mode 100644 index 9b4c284..0000000 --- a/src/Resources/Assets/FollowerAsset.php +++ /dev/null @@ -1,21 +0,0 @@ -content = $content; - } - - public function casts(): array - { - return [ - 'creator' => CreatorAsset::class, - 'labels' => LabelsAsset::class, - 'indexedAt' => DatetimeAsset::class, - ]; - } -} diff --git a/src/Resources/Assets/KnownFollowersAsset.php b/src/Resources/Assets/KnownFollowersAsset.php deleted file mode 100644 index 7c588df..0000000 --- a/src/Resources/Assets/KnownFollowersAsset.php +++ /dev/null @@ -1,26 +0,0 @@ -content = $content; - } - - protected function casts(): array - { - return [ - 'followers' => FollowersAsset::class, - ]; - } -} diff --git a/src/Resources/Assets/LabelAsset.php b/src/Resources/Assets/LabelAsset.php deleted file mode 100644 index 16b3a5e..0000000 --- a/src/Resources/Assets/LabelAsset.php +++ /dev/null @@ -1,38 +0,0 @@ -content = $content; - } - - public function casts(): array - { - return [ - 'cts' => DatetimeAsset::class, - 'exp' => DatetimeAsset::class, - ]; - } -} diff --git a/src/Resources/Assets/MutedByListAsset.php b/src/Resources/Assets/MutedByListAsset.php deleted file mode 100644 index 8843faf..0000000 --- a/src/Resources/Assets/MutedByListAsset.php +++ /dev/null @@ -1,23 +0,0 @@ -content = $content; - } - - protected function casts(): array - { - return [ - 'associated' => AssociatedAsset::class, - 'indexedAt' => DatetimeAsset::class, - 'joinedViaStarterPack' => JoinedViaStarterPackAsset::class, - 'createdAt' => DatetimeAsset::class, - 'viewer' => ViewerAsset::class, - 'labels' => LabelsAsset::class, - ]; - } -} diff --git a/src/Resources/Assets/ViewerAsset.php b/src/Resources/Assets/ViewerAsset.php deleted file mode 100644 index 37582c1..0000000 --- a/src/Resources/Assets/ViewerAsset.php +++ /dev/null @@ -1,41 +0,0 @@ -content = $content; - } - - public function casts(): array - { - return [ - 'mutedByList' => MutedByListAsset::class, - 'blockingByList' => BlockingByListAsset::class, - 'knownFollowers' => KnownFollowersAsset::class, - 'labels' => LabelsAsset::class, - ]; - } -} diff --git a/src/Resources/Com/Atproto/Repo/CreateRecordResource.php b/src/Resources/Com/Atproto/Repo/CreateRecordResource.php deleted file mode 100644 index 3b94621..0000000 --- a/src/Resources/Com/Atproto/Repo/CreateRecordResource.php +++ /dev/null @@ -1,11 +0,0 @@ - ProfilesObject::class + ]; + } +} diff --git a/src/Responses/App/Bsky/Graph/GetFollowersResponse.php b/src/Responses/App/Bsky/Graph/GetFollowersResponse.php new file mode 100644 index 0000000..197ed3f --- /dev/null +++ b/src/Responses/App/Bsky/Graph/GetFollowersResponse.php @@ -0,0 +1,30 @@ +content = $content; + } + + protected function casts(): array + { + return [ + 'followers' => FollowersObject::class, + 'subject' => SubjectObject::class, + ]; + } +} diff --git a/src/Resources/BaseResource.php b/src/Responses/BaseResponse.php similarity index 90% rename from src/Resources/BaseResource.php rename to src/Responses/BaseResponse.php index 25a7c4c..ce7964b 100644 --- a/src/Resources/BaseResource.php +++ b/src/Responses/BaseResponse.php @@ -1,13 +1,13 @@ content, $name); if (in_array(Castable::class, class_uses_recursive(static::class))) { - /** @var ?AssetContract $cast */ + /** @var ?ObjectContract $cast */ $asset = Arr::get($this->casts(), $name); if ($asset) { diff --git a/src/Responses/Com/Atproto/Repo/CreateRecordResponse.php b/src/Responses/Com/Atproto/Repo/CreateRecordResponse.php new file mode 100644 index 0000000..2332e27 --- /dev/null +++ b/src/Responses/Com/Atproto/Repo/CreateRecordResponse.php @@ -0,0 +1,11 @@ +content = $content; + } + + protected function casts(): array + { + return [ + 'chat' => ChatObject::class, + ]; + } +} diff --git a/src/Resources/Assets/BaseAsset.php b/src/Responses/Objects/BaseObject.php similarity index 65% rename from src/Resources/Assets/BaseAsset.php rename to src/Responses/Objects/BaseObject.php index 6f17505..3713e30 100644 --- a/src/Resources/Assets/BaseAsset.php +++ b/src/Responses/Objects/BaseObject.php @@ -1,10 +1,10 @@ cast(); } - public function cast(): AssetContract + public function cast(): ObjectContract { return $this; } diff --git a/src/Responses/Objects/BlockingByListObject.php b/src/Responses/Objects/BlockingByListObject.php new file mode 100644 index 0000000..1f8cb85 --- /dev/null +++ b/src/Responses/Objects/BlockingByListObject.php @@ -0,0 +1,23 @@ + LabelsAsset::class, - 'viewer' => ViewerAsset::class, - 'indexedAt' => DatetimeAsset::class, + 'labels' => LabelsObject::class, + 'viewer' => ViewerObject::class, + 'indexedAt' => DatetimeObject::class, ]; } } diff --git a/src/Responses/Objects/ChatObject.php b/src/Responses/Objects/ChatObject.php new file mode 100644 index 0000000..79cebcd --- /dev/null +++ b/src/Responses/Objects/ChatObject.php @@ -0,0 +1,26 @@ +content = $content; + } + + public function cast(): self + { + return $this; + } +} diff --git a/src/Resources/Assets/CollectionAsset.php b/src/Responses/Objects/CollectionAsset.php similarity index 74% rename from src/Resources/Assets/CollectionAsset.php rename to src/Responses/Objects/CollectionAsset.php index 2602dc5..5b40161 100644 --- a/src/Resources/Assets/CollectionAsset.php +++ b/src/Responses/Objects/CollectionAsset.php @@ -1,13 +1,13 @@ value); + } +} diff --git a/src/Responses/Objects/FollowerObject.php b/src/Responses/Objects/FollowerObject.php new file mode 100644 index 0000000..0b2723d --- /dev/null +++ b/src/Responses/Objects/FollowerObject.php @@ -0,0 +1,21 @@ +content = $content; + } + + public function casts(): array + { + return [ + 'creator' => CreatorObject::class, + 'labels' => LabelsObject::class, + 'indexedAt' => DatetimeObject::class, + ]; + } +} diff --git a/src/Responses/Objects/KnownFollowersObject.php b/src/Responses/Objects/KnownFollowersObject.php new file mode 100644 index 0000000..dc2a030 --- /dev/null +++ b/src/Responses/Objects/KnownFollowersObject.php @@ -0,0 +1,26 @@ +content = $content; + } + + protected function casts(): array + { + return [ + 'followers' => FollowersObject::class, + ]; + } +} diff --git a/src/Responses/Objects/LabelObject.php b/src/Responses/Objects/LabelObject.php new file mode 100644 index 0000000..cc82696 --- /dev/null +++ b/src/Responses/Objects/LabelObject.php @@ -0,0 +1,38 @@ +content = $content; + } + + public function casts(): array + { + return [ + 'cts' => DatetimeObject::class, + 'exp' => DatetimeObject::class, + ]; + } +} diff --git a/src/Resources/Assets/LabelsAsset.php b/src/Responses/Objects/LabelsObject.php similarity index 62% rename from src/Resources/Assets/LabelsAsset.php rename to src/Responses/Objects/LabelsObject.php index 55f7904..cc27747 100644 --- a/src/Resources/Assets/LabelsAsset.php +++ b/src/Responses/Objects/LabelsObject.php @@ -1,23 +1,23 @@ content = $content; + } + + protected function casts(): array + { + return [ + 'associated' => AssociatedObject::class, + 'indexedAt' => DatetimeObject::class, + 'joinedViaStarterPack' => JoinedViaStarterPackObject::class, + 'createdAt' => DatetimeObject::class, + 'viewer' => ViewerObject::class, + 'labels' => LabelsObject::class, + ]; + } +} diff --git a/src/Responses/Objects/ViewerObject.php b/src/Responses/Objects/ViewerObject.php new file mode 100644 index 0000000..646fdf5 --- /dev/null +++ b/src/Responses/Objects/ViewerObject.php @@ -0,0 +1,41 @@ +content = $content; + } + + public function casts(): array + { + return [ + 'mutedByList' => MutedByListObject::class, + 'blockingByList' => BlockingByListObject::class, + 'knownFollowers' => KnownFollowersObject::class, + 'labels' => LabelsObject::class, + ]; + } +} diff --git a/src/Traits/Authentication.php b/src/Traits/Authentication.php index 11b11ac..1b5d8bd 100644 --- a/src/Traits/Authentication.php +++ b/src/Traits/Authentication.php @@ -3,13 +3,13 @@ namespace Atproto\Traits; use Atproto\Exceptions\BlueskyException; -use Atproto\Resources\Com\Atproto\Server\CreateSessionResource; +use Atproto\Responses\Com\Atproto\Server\CreateSessionResponse; use SplObjectStorage; use SplObserver; trait Authentication { - private ?CreateSessionResource $authenticated = null; + private ?CreateSessionResponse $authenticated = null; private SplObjectStorage $observers; public function __construct() @@ -24,7 +24,7 @@ public function authenticate(string $identifier, string $password): void { $request = $this->com()->atproto()->server()->createSession()->forge($identifier, $password); - /** @var CreateSessionResource $response */ + /** @var CreateSessionResponse $response */ $response = $request->send(); $this->authenticated = $response; @@ -32,7 +32,7 @@ public function authenticate(string $identifier, string $password): void $this->notify(); } - public function authenticated(): ?CreateSessionResource + public function authenticated(): ?CreateSessionResponse { return $this->authenticated; } diff --git a/tests/Feature/ClientTest.php b/tests/Feature/ClientTest.php index a0fa951..15219e4 100644 --- a/tests/Feature/ClientTest.php +++ b/tests/Feature/ClientTest.php @@ -3,12 +3,12 @@ namespace Tests\Feature; use Atproto\Client; -use Atproto\Contracts\Resources\ResourceContract; +use Atproto\Contracts\Resources\ResponseContract; use Atproto\Exceptions\BlueskyException; use Atproto\Exceptions\Http\Response\AuthenticationRequiredException; use Atproto\Exceptions\Http\Response\AuthMissingException; -use Atproto\Resources\App\Bsky\Actor\GetProfileResource; -use Atproto\Resources\Com\Atproto\Server\CreateSessionResource; +use Atproto\Responses\App\Bsky\Actor\GetProfileResponse; +use Atproto\Responses\Com\Atproto\Server\CreateSessionResponse; use Carbon\Carbon; use PHPUnit\Framework\TestCase; use ReflectionException; @@ -44,10 +44,10 @@ public function testGetProfile(): void $password ); - /** @var CreateSessionResource $authenticated */ + /** @var CreateSessionResponse $authenticated */ $authenticated = $this->getPropertyValue('authenticated', $this->client); - $this->assertInstanceOf(ResourceContract::class, $authenticated); + $this->assertInstanceOf(ResponseContract::class, $authenticated); $this->assertIsString($authenticated->handle()); $this->assertSame($username, $authenticated->handle()); @@ -61,8 +61,8 @@ public function testGetProfile(): void ->actor($this->client->authenticated()->did()) ->send(); - $this->assertInstanceOf(ResourceContract::class, $profile); - $this->assertInstanceOf(GetProfileResource::class, $profile); + $this->assertInstanceOf(ResponseContract::class, $profile); + $this->assertInstanceOf(GetProfileResponse::class, $profile); $this->assertInstanceOf(Carbon::class, $profile->createdAt()); } @@ -114,7 +114,7 @@ public function testObserverNotificationOnAuthentication(): void ->build() ->send(); - $this->assertInstanceOf(ResourceContract::class, $response); - $this->assertInstanceOf(GetProfileResource::class, $response); + $this->assertInstanceOf(ResponseContract::class, $response); + $this->assertInstanceOf(GetProfileResponse::class, $response); } } diff --git a/tests/Feature/Lexicons/App/Bsky/Graph/GetFollowersTest.php b/tests/Feature/Lexicons/App/Bsky/Graph/GetFollowersTest.php index 88e9c29..8256390 100644 --- a/tests/Feature/Lexicons/App/Bsky/Graph/GetFollowersTest.php +++ b/tests/Feature/Lexicons/App/Bsky/Graph/GetFollowersTest.php @@ -3,7 +3,7 @@ namespace Tests\Feature\Lexicons\App\Bsky\Graph; use Atproto\Client; -use Atproto\Resources\Assets\FollowersAsset; +use Atproto\Responses\Objects\FollowersObject; use PHPUnit\Framework\TestCase; class GetFollowersTest extends TestCase @@ -36,6 +36,6 @@ public function testGetFollowers() $response = $request->send(); $this->assertSame($client->authenticated()->did(), $response->subject()->did()); - $this->assertInstanceOf(FollowersAsset::class, $response->followers()); + $this->assertInstanceOf(FollowersObject::class, $response->followers()); } } diff --git a/tests/Supports/ByListAssetTest.php b/tests/Supports/ByListAssetTest.php index afd74db..0b7cb44 100644 --- a/tests/Supports/ByListAssetTest.php +++ b/tests/Supports/ByListAssetTest.php @@ -2,8 +2,8 @@ namespace Tests\Supports; -use Atproto\Resources\Assets\LabelsAsset; -use Atproto\Resources\Assets\ViewerAsset; +use Atproto\Responses\Objects\LabelsObject; +use Atproto\Responses\Objects\ViewerObject; use Carbon\Carbon; trait ByListAssetTest @@ -27,8 +27,8 @@ public function nonPrimitiveAssetsProvider(): array list($this->faker) = self::getData(); return [ - ['labels', LabelsAsset::class, []], - ['viewer', ViewerAsset::class, []], + ['labels', LabelsObject::class, []], + ['viewer', ViewerObject::class, []], ['indexedAt', Carbon::class, $this->faker->dateTime->format(DATE_ATOM)], ]; } diff --git a/tests/Supports/NonPrimitiveAssetTest.php b/tests/Supports/NonPrimitiveAssetTest.php index 21785e2..feb2ea6 100644 --- a/tests/Supports/NonPrimitiveAssetTest.php +++ b/tests/Supports/NonPrimitiveAssetTest.php @@ -2,7 +2,7 @@ namespace Tests\Supports; -use Atproto\Contracts\Resources\AssetContract; +use Atproto\Contracts\Resources\ObjectContract; use GenericCollection\Exceptions\InvalidArgumentException; use ReflectionClass; use ReflectionException; @@ -27,7 +27,7 @@ public function testNonPrimitiveAssets(string $name, string $expectedAsset, $val $this->assertTrue(true); - if (! $actualAsset instanceof AssetContract) { + if (! $actualAsset instanceof ObjectContract) { return; } diff --git a/tests/Supports/UserAssetTest.php b/tests/Supports/UserAssetTest.php index 637154c..b0bacce 100644 --- a/tests/Supports/UserAssetTest.php +++ b/tests/Supports/UserAssetTest.php @@ -2,9 +2,9 @@ namespace Tests\Supports; -use Atproto\Resources\Assets\AssociatedAsset; -use Atproto\Resources\Assets\JoinedViaStarterPackAsset; -use Atproto\Resources\Assets\ViewerAsset; +use Atproto\Responses\Objects\AssociatedObject; +use Atproto\Responses\Objects\JoinedViaStarterPackObject; +use Atproto\Responses\Objects\ViewerObject; use GenericCollection\Interfaces\GenericCollectionInterface; trait UserAssetTest @@ -32,9 +32,9 @@ public function primitiveAssetsProvider(): array public function nonPrimitiveAssetsProvider(): array { return [ - ['associated', AssociatedAsset::class, []], - ['joinedViaStarterPack', JoinedViaStarterPackAsset::class, []], - ['viewer', ViewerAsset::class, []], + ['associated', AssociatedObject::class, []], + ['joinedViaStarterPack', JoinedViaStarterPackObject::class, []], + ['viewer', ViewerObject::class, []], ['labels', GenericCollectionInterface::class, []], ]; } diff --git a/tests/Unit/ClientTest.php b/tests/Unit/ClientTest.php index c19859e..fd15366 100644 --- a/tests/Unit/ClientTest.php +++ b/tests/Unit/ClientTest.php @@ -7,7 +7,7 @@ use Atproto\Exceptions\Http\Request\LexiconNotFoundException; use Atproto\Lexicons\APIRequest; use Atproto\Lexicons\Com\Atproto\Server\CreateSession; -use Atproto\Resources\Com\Atproto\Server\CreateSessionResource; +use Atproto\Responses\Com\Atproto\Server\CreateSessionResponse; use PHPUnit\Framework\TestCase; use ReflectionException; use SplObserver; @@ -163,7 +163,7 @@ private function mockAuthenticate() $mockCreateSession->expects($this->once()) ->method('send') - ->willReturn($this->createMock(CreateSessionResource::class)); + ->willReturn($this->createMock(CreateSessionResponse::class)); $this->client = $this->getMockBuilder(Client::class) ->onlyMethods(['forge']) diff --git a/tests/Unit/Lexicons/App/Bsky/Actor/GetProfilesTest.php b/tests/Unit/Lexicons/App/Bsky/Actor/GetProfilesTest.php index 3d4204f..3812c8d 100644 --- a/tests/Unit/Lexicons/App/Bsky/Actor/GetProfilesTest.php +++ b/tests/Unit/Lexicons/App/Bsky/Actor/GetProfilesTest.php @@ -7,7 +7,7 @@ use Atproto\Exceptions\Http\MissingFieldProvidedException; use Atproto\Exceptions\InvalidArgumentException; use Atproto\Lexicons\App\Bsky\Actor\GetProfiles; -use Atproto\Resources\App\Bsky\Actor\GetProfilesResource; +use Atproto\Responses\App\Bsky\Actor\GetProfilesResponse; use GenericCollection\GenericCollection; use GenericCollection\Types\Primitive\StringType; use PHPUnit\Framework\TestCase; @@ -88,7 +88,7 @@ public function testBuildSucceeds(): void public function testResourceMethodReturnsCorrectInstance(): void { $data = ['actors' => []]; - $resource = $this->request->resource($data); - $this->assertInstanceOf(GetProfilesResource::class, $resource, 'Resource method should return an instance of GetProfilesResource.'); + $resource = $this->request->response($data); + $this->assertInstanceOf(GetProfilesResponse::class, $resource, 'Resource method should return an instance of GetProfilesResource.'); } } diff --git a/tests/Unit/Lexicons/App/Bsky/Graph/GetFollowersTest.php b/tests/Unit/Lexicons/App/Bsky/Graph/GetFollowersTest.php index 9dbe78f..09644be 100644 --- a/tests/Unit/Lexicons/App/Bsky/Graph/GetFollowersTest.php +++ b/tests/Unit/Lexicons/App/Bsky/Graph/GetFollowersTest.php @@ -3,7 +3,7 @@ namespace Tests\Unit\Lexicons\App\Bsky\Graph; use Atproto\Client; -use Atproto\Contracts\Resources\ResourceContract; +use Atproto\Contracts\Resources\ResponseContract; use Atproto\Exceptions\Http\MissingFieldProvidedException; use Atproto\Exceptions\Http\Response\AuthMissingException; use Atproto\Exceptions\InvalidArgumentException; @@ -91,8 +91,8 @@ public function testBuildSucceedsWithRequiredParameters() public function testResourceMethodReturnsCorrectInstance() { $data = ['followers' => []]; - $resource = $this->request->resource($data); - $this->assertInstanceOf(ResourceContract::class, $resource, 'Resource method should return an instance of ResourceContract.'); + $resource = $this->request->response($data); + $this->assertInstanceOf(ResponseContract::class, $resource, 'Resource method should return an instance of ResourceContract.'); } public function testLimitGetterReturnsNullWhenNotSet() diff --git a/tests/Unit/Resources/Assets/BlockingByListAssetTest.php b/tests/Unit/Resources/Assets/BlockingByListAssetTest.php deleted file mode 100644 index 24de5a3..0000000 --- a/tests/Unit/Resources/Assets/BlockingByListAssetTest.php +++ /dev/null @@ -1,21 +0,0 @@ -faker) = self::getData(); return [ - ['associated', AssociatedAsset::class, ['data' => $this->faker->uuid]], - ['joinedViaStarterPack', JoinedViaStarterPackAsset::class, ['data' => $this->faker->uuid]], - ['viewer', ViewerAsset::class, ['data' => $this->faker->uuid]], + ['associated', AssociatedObject::class, ['data' => $this->faker->uuid]], + ['joinedViaStarterPack', JoinedViaStarterPackObject::class, ['data' => $this->faker->uuid]], + ['viewer', ViewerObject::class, ['data' => $this->faker->uuid]], ['labels', GenericCollectionInterface::class, [ ['cts' => $this->faker->dateTime], ['exp' => $this->faker->dateTime], ]], - ['indexedAt', DatetimeAsset::class, $this->faker->dateTime], - ['createdAt', DatetimeAsset::class, $this->faker->dateTime], + ['indexedAt', DatetimeObject::class, $this->faker->dateTime], + ['createdAt', DatetimeObject::class, $this->faker->dateTime], ]; } - protected function resource(array $data): ResourceContract + protected function resource(array $data): ResponseContract { - return new GetProfileResource($data); + return new GetProfileResponse($data); } } diff --git a/tests/Unit/Resources/Assets/AssociatedAssetTest.php b/tests/Unit/Responses/Assets/AssociatedObjectTest.php similarity index 71% rename from tests/Unit/Resources/Assets/AssociatedAssetTest.php rename to tests/Unit/Responses/Assets/AssociatedObjectTest.php index c85dc7f..8e804af 100644 --- a/tests/Unit/Resources/Assets/AssociatedAssetTest.php +++ b/tests/Unit/Responses/Assets/AssociatedObjectTest.php @@ -1,15 +1,15 @@ faker) = self::getData(); return [ - ['chat', ChatAsset::class, ['allowIncoming' => $this->faker->shuffleString]], + ['chat', ChatObject::class, ['allowIncoming' => $this->faker->shuffleString]], ]; } /** * @throws InvalidArgumentException */ - protected function resource($data): AssociatedAsset + protected function resource($data): AssociatedObject { - return new AssociatedAsset($data); + return new AssociatedObject($data); } } diff --git a/tests/Unit/Resources/Assets/BaseAssetTest.php b/tests/Unit/Responses/Assets/BaseObjectTest.php similarity index 64% rename from tests/Unit/Resources/Assets/BaseAssetTest.php rename to tests/Unit/Responses/Assets/BaseObjectTest.php index 42008ce..e17a407 100644 --- a/tests/Unit/Resources/Assets/BaseAssetTest.php +++ b/tests/Unit/Responses/Assets/BaseObjectTest.php @@ -1,21 +1,21 @@ asset->cast(); - $this->assertInstanceOf(AssetContract::class, $result); + $this->assertInstanceOf(ObjectContract::class, $result); $this->assertSame($this->asset, $result); } @@ -47,13 +47,13 @@ public function testRevertReturnsValue() /** * @throws InvalidArgumentException */ - protected function resource(array $data): TestableAsset + protected function resource(array $data): TestableObject { - return new TestableAsset($data); + return new TestableObject($data); } } -class TestableAsset implements AssetContract +class TestableObject implements ObjectContract { - use BaseAsset; + use BaseObject; } diff --git a/tests/Unit/Responses/Assets/BlockingByListObjectTest.php b/tests/Unit/Responses/Assets/BlockingByListObjectTest.php new file mode 100644 index 0000000..a1f514f --- /dev/null +++ b/tests/Unit/Responses/Assets/BlockingByListObjectTest.php @@ -0,0 +1,21 @@ +assertInstanceOf(TestCollectionAsset::class, $this->collectionAsset); + $this->assertInstanceOf(TestCollectionObject::class, $this->collectionAsset); } public function testCastMethod() { $result = $this->collectionAsset->cast(); - $this->assertInstanceOf(TestCollectionAsset::class, $result); + $this->assertInstanceOf(TestCollectionObject::class, $result); } public function testGetMethod() { foreach($this->collectionAsset as $item) { - $this->assertInstanceOf(ExampleAsset::class, $item); + $this->assertInstanceOf(ExampleObject::class, $item); } } @@ -71,13 +71,13 @@ public function testTypeMethod() /** * @throws InvalidArgumentException */ - protected function resource(array $data): TestCollectionAsset + protected function resource(array $data): TestCollectionObject { - return new TestCollectionAsset($data); + return new TestCollectionObject($data); } } -class TestCollectionAsset extends GenericCollection implements AssetContract +class TestCollectionObject extends GenericCollection implements ObjectContract { use CollectionAsset; @@ -86,9 +86,9 @@ public function __construct(array $content) parent::__construct(new ExampleAssetType(), $content); } - public function item($data): AssetContract + public function item($data): ObjectContract { - return new ExampleAsset($data); + return new ExampleObject($data); } public function type(): TypeInterface @@ -97,7 +97,7 @@ public function type(): TypeInterface } } -class ExampleAsset implements AssetContract +class ExampleObject implements ObjectContract { protected $value; @@ -106,7 +106,7 @@ public function __construct($value) $this->value = $value; } - public function cast(): ExampleAsset + public function cast(): ExampleObject { return $this; } @@ -121,6 +121,6 @@ class ExampleAssetType implements TypeInterface { public function validate($value): bool { - return $value instanceof ExampleAsset; + return $value instanceof ExampleObject; } } diff --git a/tests/Unit/Responses/Assets/CreatorObjectTest.php b/tests/Unit/Responses/Assets/CreatorObjectTest.php new file mode 100644 index 0000000..f3eded2 --- /dev/null +++ b/tests/Unit/Responses/Assets/CreatorObjectTest.php @@ -0,0 +1,17 @@ +resource([]); $actual = $instance; - $expected = DatetimeAsset::class; + $expected = DatetimeObject::class; $this->assertInstanceOf($expected, $actual); } @@ -49,8 +49,8 @@ public function testCastThrowsExceptionWhenPassingInvalidDateFormat(): void /** * @throws InvalidArgumentException */ - protected function resource(array $data): DatetimeAsset + protected function resource(array $data): DatetimeObject { - return new DatetimeAsset(current($data)); + return new DatetimeObject(current($data)); } } diff --git a/tests/Unit/Responses/Assets/FollowerObjectTest.php b/tests/Unit/Responses/Assets/FollowerObjectTest.php new file mode 100644 index 0000000..f512266 --- /dev/null +++ b/tests/Unit/Responses/Assets/FollowerObjectTest.php @@ -0,0 +1,23 @@ +resource([]); - $this->assertAssetInstance($instance, FollowersAsset::class); + $this->assertAssetInstance($instance, FollowersObject::class); } /** @@ -53,7 +53,7 @@ public function testAssetWithPrimitiveTypes(): void $followers = $this->resource($data); foreach ($data as $index => $datum) { - /** @var FollowerAsset $follower */ + /** @var FollowerObject $follower */ $follower = $followers->get($index); $this->assertFollowerMatchesData($follower, $datum); } @@ -76,9 +76,9 @@ public function testAssetWithNonPrimitiveTypes(): void /** * @throws InvalidArgumentException */ - protected function resource(array $data): FollowersAsset + protected function resource(array $data): FollowersObject { - return new FollowersAsset($data); + return new FollowersObject($data); } protected function generateFollowerData(): array @@ -109,14 +109,14 @@ protected function generateComplexFollowerData(): array protected function assertAssetInstance($instance, string $class): void { $this->assertInstanceOf(GenericCollectionInterface::class, $instance); - $this->assertInstanceOf(AssetContract::class, $instance); + $this->assertInstanceOf(ObjectContract::class, $instance); $this->assertInstanceOf($class, $instance); } /** * @throws BadAssetCallException */ - protected function assertFollowerMatchesData(FollowerAsset $follower, array $data): void + protected function assertFollowerMatchesData(FollowerObject $follower, array $data): void { foreach ($data as $key => $value) { $this->assertSame($follower->$key(), $value); @@ -124,7 +124,7 @@ protected function assertFollowerMatchesData(FollowerAsset $follower, array $dat } } - protected function assertFollowerMatchesComplexData(FollowerAsset $follower): void + protected function assertFollowerMatchesComplexData(FollowerObject $follower): void { list(, , $schema) = self::getData(); @@ -143,23 +143,23 @@ protected static function getData(): array $schema = [ 'associated' => [ - 'caster' => AssociatedAsset::class, - 'casted' => AssociatedAsset::class, + 'caster' => AssociatedObject::class, + 'casted' => AssociatedObject::class, 'value' => [] ], 'viewer' => [ - 'caster' => ViewerAsset::class, - 'casted' => ViewerAsset::class, + 'caster' => ViewerObject::class, + 'casted' => ViewerObject::class, 'value' => [] ], 'createdAt' => [ - 'caster' => DatetimeAsset::class, + 'caster' => DatetimeObject::class, 'casted' => Carbon::class, 'value' => $faker->dateTime->format(DATE_ATOM) ], "labels" => [ - 'caster' => LabelsAsset::class, - 'casted' => LabelsAsset::class, + 'caster' => LabelsObject::class, + 'casted' => LabelsObject::class, 'value' => [] ] ]; diff --git a/tests/Unit/Resources/Assets/JoinedViaStarterPackAssetTest.php b/tests/Unit/Responses/Assets/JoinedViaStarterPackObjectTest.php similarity index 73% rename from tests/Unit/Resources/Assets/JoinedViaStarterPackAssetTest.php rename to tests/Unit/Responses/Assets/JoinedViaStarterPackObjectTest.php index 10d9066..b0b214c 100644 --- a/tests/Unit/Resources/Assets/JoinedViaStarterPackAssetTest.php +++ b/tests/Unit/Responses/Assets/JoinedViaStarterPackObjectTest.php @@ -1,17 +1,17 @@ faker) = self::getData(); return [ - ['creator', CreatorAsset::class, []], - ['labels', LabelsAsset::class, []], + ['creator', CreatorObject::class, []], + ['labels', LabelsObject::class, []], ['indexedAt', Carbon::class, $this->faker->dateTime->format(DATE_ATOM)], ]; } diff --git a/tests/Unit/Resources/Assets/KnownFollowersAssetTest.php b/tests/Unit/Responses/Assets/KnownFollowersObjectTest.php similarity index 67% rename from tests/Unit/Resources/Assets/KnownFollowersAssetTest.php rename to tests/Unit/Responses/Assets/KnownFollowersObjectTest.php index 384ab00..cb25e1c 100644 --- a/tests/Unit/Resources/Assets/KnownFollowersAssetTest.php +++ b/tests/Unit/Responses/Assets/KnownFollowersObjectTest.php @@ -1,15 +1,15 @@ numberBetween(1, 20); return [ - ['followers', FollowersAsset::class, [array_map(fn () => [ + ['followers', FollowersObject::class, [array_map(fn () => [ 'displayName' => $faker->name, ], range(1, $count))]], ]; diff --git a/tests/Unit/Resources/Assets/LabelAssetTest.php b/tests/Unit/Responses/Assets/LabelObjectTest.php similarity index 83% rename from tests/Unit/Resources/Assets/LabelAssetTest.php rename to tests/Unit/Responses/Assets/LabelObjectTest.php index f581f1e..14c10ce 100644 --- a/tests/Unit/Resources/Assets/LabelAssetTest.php +++ b/tests/Unit/Responses/Assets/LabelObjectTest.php @@ -1,8 +1,8 @@ [ - 'caster' => DatetimeAsset::class, + 'caster' => DatetimeObject::class, 'casted' => Carbon::class, 'value' => $faker->dateTime->format(DATE_ATOM) ], 'exp' => [ - 'caster' => DatetimeAsset::class, + 'caster' => DatetimeObject::class, 'casted' => Carbon::class, 'value' => $faker->dateTime->format(DATE_ATOM) ], diff --git a/tests/Unit/Responses/Assets/MutedByListObjectTest.php b/tests/Unit/Responses/Assets/MutedByListObjectTest.php new file mode 100644 index 0000000..7d43426 --- /dev/null +++ b/tests/Unit/Responses/Assets/MutedByListObjectTest.php @@ -0,0 +1,21 @@ +assertEquals(50, $this->userAsset->followsCount()); $this->assertEquals(10, $this->userAsset->postsCount()); - $this->assertInstanceOf(AssociatedAsset::class, $this->userAsset->associated()); - $this->assertInstanceOf(JoinedViaStarterPackAsset::class, $this->userAsset->joinedViaStarterPack()); + $this->assertInstanceOf(AssociatedObject::class, $this->userAsset->associated()); + $this->assertInstanceOf(JoinedViaStarterPackObject::class, $this->userAsset->joinedViaStarterPack()); $this->assertInstanceOf(Carbon::class, $this->userAsset->indexedAt()); $this->assertInstanceOf(Carbon::class, $this->userAsset->createdAt()); - $this->assertInstanceOf(ViewerAsset::class, $this->userAsset->viewer()); - $this->assertInstanceOf(LabelsAsset::class, $this->userAsset->labels()); + $this->assertInstanceOf(ViewerObject::class, $this->userAsset->viewer()); + $this->assertInstanceOf(LabelsObject::class, $this->userAsset->labels()); } public function testCastsMethod() @@ -110,12 +110,12 @@ public function testCastsMethod() $this->assertArrayHasKey('viewer', $casts); $this->assertArrayHasKey('labels', $casts); - $this->assertEquals(AssociatedAsset::class, $casts['associated']); - $this->assertEquals(DatetimeAsset::class, $casts['indexedAt']); - $this->assertEquals(JoinedViaStarterPackAsset::class, $casts['joinedViaStarterPack']); - $this->assertEquals(DatetimeAsset::class, $casts['createdAt']); - $this->assertEquals(ViewerAsset::class, $casts['viewer']); - $this->assertEquals(LabelsAsset::class, $casts['labels']); + $this->assertEquals(AssociatedObject::class, $casts['associated']); + $this->assertEquals(DatetimeObject::class, $casts['indexedAt']); + $this->assertEquals(JoinedViaStarterPackObject::class, $casts['joinedViaStarterPack']); + $this->assertEquals(DatetimeObject::class, $casts['createdAt']); + $this->assertEquals(ViewerObject::class, $casts['viewer']); + $this->assertEquals(LabelsObject::class, $casts['labels']); } /** @@ -129,5 +129,5 @@ protected function resource(array $data): TestUserAsset class TestUserAsset { - use UserAsset; + use UserObject; } diff --git a/tests/Unit/Responses/Assets/ViewerObjectTest.php b/tests/Unit/Responses/Assets/ViewerObjectTest.php new file mode 100644 index 0000000..95acf14 --- /dev/null +++ b/tests/Unit/Responses/Assets/ViewerObjectTest.php @@ -0,0 +1,45 @@ +resource = new TestableResource([ + $this->resource = new TestableResponse([ 'example' => 'some value', ]); } @@ -27,7 +27,7 @@ public function testGetMethodWithExistingAsset() { $result = $this->resource->get('example'); - $this->assertInstanceOf(ExampleAsset::class, $result); + $this->assertInstanceOf(ExampleObject::class, $result); } public function testGetMethodWithNonExistingAsset() @@ -47,25 +47,25 @@ public function testMagicCall() { $result = $this->resource->example(); - $this->assertInstanceOf(ExampleAsset::class, $result); + $this->assertInstanceOf(ExampleObject::class, $result); } } -class TestableResource implements ResourceContract +class TestableResponse implements ResponseContract { - use BaseResource; + use BaseResponse; use Castable; protected function casts(): array { return [ - 'example' => ExampleAsset::class + 'example' => ExampleObject::class ]; } } -class ExampleAsset implements AssetContract +class ExampleObject implements ObjectContract { - use BaseAsset; + use BaseObject; } From 9eace036dacfd5d89f23e4e70ab65423c1a4d1ca Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sat, 9 Nov 2024 02:19:55 +0400 Subject: [PATCH 53/58] refactor: improve object and response contract hierarchy --- src/Contracts/Resources/ObjectContract.php | 2 +- src/Contracts/Resources/ResponseContract.php | 2 +- src/Responses/BaseResponse.php | 10 +++++----- src/Responses/Objects/AssociatedObject.php | 5 +---- src/Responses/Objects/BaseObject.php | 3 +++ src/Responses/Objects/BlockingByListObject.php | 5 ++--- .../Objects/{ByListAsset.php => ByListObject.php} | 4 +--- src/Responses/Objects/ChatObject.php | 5 +---- .../{CollectionAsset.php => CollectionObject.php} | 9 ++++++++- src/Responses/Objects/CreatorObject.php | 3 +-- src/Responses/Objects/FollowerObject.php | 3 +-- src/Responses/Objects/FollowersObject.php | 2 +- src/Responses/Objects/JoinedViaStarterPackObject.php | 5 +---- src/Responses/Objects/KnownFollowersObject.php | 2 -- src/Responses/Objects/LabelObject.php | 5 +---- src/Responses/Objects/LabelsObject.php | 2 +- src/Responses/Objects/MutedByListObject.php | 5 ++--- src/Responses/Objects/ProfileObject.php | 3 +-- src/Responses/Objects/ProfilesObject.php | 2 +- src/Responses/Objects/SubjectObject.php | 3 +-- src/Responses/Objects/UserObject.php | 2 -- src/Responses/Objects/ViewerObject.php | 5 +---- tests/Supports/NonPrimitiveAssetTest.php | 4 ++++ tests/Unit/Responses/Assets/CollectionObjectTest.php | 7 +++++-- 24 files changed, 44 insertions(+), 54 deletions(-) rename src/Responses/Objects/{ByListAsset.php => ByListObject.php} (90%) rename src/Responses/Objects/{CollectionAsset.php => CollectionObject.php} (77%) diff --git a/src/Contracts/Resources/ObjectContract.php b/src/Contracts/Resources/ObjectContract.php index a2648d7..0b8610a 100644 --- a/src/Contracts/Resources/ObjectContract.php +++ b/src/Contracts/Resources/ObjectContract.php @@ -2,7 +2,7 @@ namespace Atproto\Contracts\Resources; -interface ObjectContract +interface ObjectContract extends ResponseContract { public function cast(); public function revert(); diff --git a/src/Contracts/Resources/ResponseContract.php b/src/Contracts/Resources/ResponseContract.php index abc52e6..bd3e81a 100644 --- a/src/Contracts/Resources/ResponseContract.php +++ b/src/Contracts/Resources/ResponseContract.php @@ -20,7 +20,7 @@ interface ResponseContract * * @throws BadAssetCallException If the asset does not exist on resource. */ - public function get(string $name); + public function get($offset); /** * @param string $name diff --git a/src/Responses/BaseResponse.php b/src/Responses/BaseResponse.php index ce7964b..bb57314 100644 --- a/src/Responses/BaseResponse.php +++ b/src/Responses/BaseResponse.php @@ -30,19 +30,19 @@ public function __call(string $name, array $arguments) } /** - * @param string $name + * @param string $offset * * @return mixed * * @throws BadAssetCallException */ - public function get(string $name) + public function get($offset) { - if (! $this->exist($name)) { - throw new BadAssetCallException($name); + if (! $this->exist($offset)) { + throw new BadAssetCallException($offset); } - return $this->parse($name); + return $this->parse($offset); } public function exist(string $name): bool diff --git a/src/Responses/Objects/AssociatedObject.php b/src/Responses/Objects/AssociatedObject.php index b70da26..01bbdd1 100644 --- a/src/Responses/Objects/AssociatedObject.php +++ b/src/Responses/Objects/AssociatedObject.php @@ -3,8 +3,6 @@ namespace Atproto\Responses\Objects; use Atproto\Contracts\Resources\ObjectContract; -use Atproto\Contracts\Resources\ResponseContract; -use Atproto\Responses\BaseResponse; use Atproto\Traits\Castable; /** @@ -14,9 +12,8 @@ * @method bool labeler() * @method ChatObject chat() */ -class AssociatedObject implements ResponseContract, ObjectContract +class AssociatedObject implements ObjectContract { - use BaseResponse; use BaseObject; use Castable; diff --git a/src/Responses/Objects/BaseObject.php b/src/Responses/Objects/BaseObject.php index 3713e30..f1c92f1 100644 --- a/src/Responses/Objects/BaseObject.php +++ b/src/Responses/Objects/BaseObject.php @@ -3,9 +3,12 @@ namespace Atproto\Responses\Objects; use Atproto\Contracts\Resources\ObjectContract; +use Atproto\Responses\BaseResponse; trait BaseObject { + use BaseResponse; + /** @var mixed */ protected $value; diff --git a/src/Responses/Objects/BlockingByListObject.php b/src/Responses/Objects/BlockingByListObject.php index 1f8cb85..7badcf9 100644 --- a/src/Responses/Objects/BlockingByListObject.php +++ b/src/Responses/Objects/BlockingByListObject.php @@ -3,7 +3,6 @@ namespace Atproto\Responses\Objects; use Atproto\Contracts\Resources\ObjectContract; -use Atproto\Contracts\Resources\ResponseContract; use Carbon\Carbon; /** @@ -17,7 +16,7 @@ * @method ViewerObject viewer() * @method Carbon indexedAt() */ -class BlockingByListObject implements ResponseContract, ObjectContract +class BlockingByListObject implements ObjectContract { - use ByListAsset; + use ByListObject; } diff --git a/src/Responses/Objects/ByListAsset.php b/src/Responses/Objects/ByListObject.php similarity index 90% rename from src/Responses/Objects/ByListAsset.php rename to src/Responses/Objects/ByListObject.php index 878bd58..d8b2166 100644 --- a/src/Responses/Objects/ByListAsset.php +++ b/src/Responses/Objects/ByListObject.php @@ -2,7 +2,6 @@ namespace Atproto\Responses\Objects; -use Atproto\Responses\BaseResponse; use Atproto\Traits\Castable; use Carbon\Carbon; @@ -17,9 +16,8 @@ * @method ViewerObject viewer() * @method Carbon indexedAt() */ -trait ByListAsset +trait ByListObject { - use BaseResponse; use BaseObject; use Castable; diff --git a/src/Responses/Objects/ChatObject.php b/src/Responses/Objects/ChatObject.php index 79cebcd..51cb684 100644 --- a/src/Responses/Objects/ChatObject.php +++ b/src/Responses/Objects/ChatObject.php @@ -3,15 +3,12 @@ namespace Atproto\Responses\Objects; use Atproto\Contracts\Resources\ObjectContract; -use Atproto\Contracts\Resources\ResponseContract; -use Atproto\Responses\BaseResponse; /** * @method string allowingIncoming() */ -class ChatObject implements ResponseContract, ObjectContract +class ChatObject implements ObjectContract { - use BaseResponse; use BaseObject; public function __construct(array $content) diff --git a/src/Responses/Objects/CollectionAsset.php b/src/Responses/Objects/CollectionObject.php similarity index 77% rename from src/Responses/Objects/CollectionAsset.php rename to src/Responses/Objects/CollectionObject.php index 5b40161..7763c21 100644 --- a/src/Responses/Objects/CollectionAsset.php +++ b/src/Responses/Objects/CollectionObject.php @@ -3,15 +3,17 @@ namespace Atproto\Responses\Objects; use Atproto\Contracts\Resources\ObjectContract; +use Atproto\Support\Arr; use GenericCollection\Interfaces\TypeInterface; -trait CollectionAsset +trait CollectionObject { use BaseObject; public function __construct(array $content) { $this->value = $content; + $this->content = $content; parent::__construct( $this->type(), @@ -21,6 +23,11 @@ public function __construct(array $content) ); } + private function parse($offset) + { + return Arr::get($this->collection, $offset); + } + public function cast(): self { return $this; diff --git a/src/Responses/Objects/CreatorObject.php b/src/Responses/Objects/CreatorObject.php index 17455d4..01429d8 100644 --- a/src/Responses/Objects/CreatorObject.php +++ b/src/Responses/Objects/CreatorObject.php @@ -3,7 +3,6 @@ namespace Atproto\Responses\Objects; use Atproto\Contracts\Resources\ObjectContract; -use Atproto\Contracts\Resources\ResponseContract; /** * @method string did() @@ -22,7 +21,7 @@ * @method ViewerObject viewer() * @method LabelsObject labels() */ -class CreatorObject implements ResponseContract, ObjectContract +class CreatorObject implements ObjectContract { use UserObject; } diff --git a/src/Responses/Objects/FollowerObject.php b/src/Responses/Objects/FollowerObject.php index 0b2723d..f5396e9 100644 --- a/src/Responses/Objects/FollowerObject.php +++ b/src/Responses/Objects/FollowerObject.php @@ -3,7 +3,6 @@ namespace Atproto\Responses\Objects; use Atproto\Contracts\Resources\ObjectContract; -use Atproto\Contracts\Resources\ResponseContract; /** * @method string did() @@ -15,7 +14,7 @@ * @method ViewerObject viewer() * @method LabelsObject labels() */ -class FollowerObject implements ResponseContract, ObjectContract +class FollowerObject implements ObjectContract { use UserObject; } diff --git a/src/Responses/Objects/FollowersObject.php b/src/Responses/Objects/FollowersObject.php index 4032459..47fc8d3 100644 --- a/src/Responses/Objects/FollowersObject.php +++ b/src/Responses/Objects/FollowersObject.php @@ -10,7 +10,7 @@ class FollowersObject extends GenericCollection implements ObjectContract { - use CollectionAsset; + use CollectionObject; /** * @throws InvalidArgumentException diff --git a/src/Responses/Objects/JoinedViaStarterPackObject.php b/src/Responses/Objects/JoinedViaStarterPackObject.php index bb78b3e..05edf7c 100644 --- a/src/Responses/Objects/JoinedViaStarterPackObject.php +++ b/src/Responses/Objects/JoinedViaStarterPackObject.php @@ -3,8 +3,6 @@ namespace Atproto\Responses\Objects; use Atproto\Contracts\Resources\ObjectContract; -use Atproto\Contracts\Resources\ResponseContract; -use Atproto\Responses\BaseResponse; use Atproto\Traits\Castable; use Carbon\Carbon; @@ -18,9 +16,8 @@ * @method LabelsObject labels() * @method Carbon indexedAt() */ -class JoinedViaStarterPackObject implements ResponseContract, ObjectContract +class JoinedViaStarterPackObject implements ObjectContract { - use BaseResponse; use BaseObject; use Castable; diff --git a/src/Responses/Objects/KnownFollowersObject.php b/src/Responses/Objects/KnownFollowersObject.php index dc2a030..a551219 100644 --- a/src/Responses/Objects/KnownFollowersObject.php +++ b/src/Responses/Objects/KnownFollowersObject.php @@ -3,12 +3,10 @@ namespace Atproto\Responses\Objects; use Atproto\Contracts\Resources\ObjectContract; -use Atproto\Responses\BaseResponse; use Atproto\Traits\Castable; class KnownFollowersObject implements ObjectContract { - use BaseResponse; use BaseObject; use Castable; diff --git a/src/Responses/Objects/LabelObject.php b/src/Responses/Objects/LabelObject.php index cc82696..115c91e 100644 --- a/src/Responses/Objects/LabelObject.php +++ b/src/Responses/Objects/LabelObject.php @@ -3,8 +3,6 @@ namespace Atproto\Responses\Objects; use Atproto\Contracts\Resources\ObjectContract; -use Atproto\Contracts\Resources\ResponseContract; -use Atproto\Responses\BaseResponse; use Atproto\Traits\Castable; /** @@ -17,9 +15,8 @@ * @method DatetimeObject cts * @method DatetimeObject exp */ -class LabelObject implements ResponseContract, ObjectContract +class LabelObject implements ObjectContract { - use BaseResponse; use BaseObject; use Castable; diff --git a/src/Responses/Objects/LabelsObject.php b/src/Responses/Objects/LabelsObject.php index cc27747..1f390d5 100644 --- a/src/Responses/Objects/LabelsObject.php +++ b/src/Responses/Objects/LabelsObject.php @@ -10,7 +10,7 @@ class LabelsObject extends GenericCollection implements ObjectContract { - use CollectionAsset; + use CollectionObject; /** * @throws InvalidArgumentException diff --git a/src/Responses/Objects/MutedByListObject.php b/src/Responses/Objects/MutedByListObject.php index 40e1bc5..9285cb2 100644 --- a/src/Responses/Objects/MutedByListObject.php +++ b/src/Responses/Objects/MutedByListObject.php @@ -3,7 +3,6 @@ namespace Atproto\Responses\Objects; use Atproto\Contracts\Resources\ObjectContract; -use Atproto\Contracts\Resources\ResponseContract; use Carbon\Carbon; /** @@ -17,7 +16,7 @@ * @method ViewerObject viewer() * @method Carbon indexedAt() */ -class MutedByListObject implements ResponseContract, ObjectContract +class MutedByListObject implements ObjectContract { - use ByListAsset; + use ByListObject; } diff --git a/src/Responses/Objects/ProfileObject.php b/src/Responses/Objects/ProfileObject.php index cdd39d1..f31d10d 100644 --- a/src/Responses/Objects/ProfileObject.php +++ b/src/Responses/Objects/ProfileObject.php @@ -3,9 +3,8 @@ namespace Atproto\Responses\Objects; use Atproto\Contracts\Resources\ObjectContract; -use Atproto\Contracts\Resources\ResponseContract; -class ProfileObject implements ResponseContract, ObjectContract +class ProfileObject implements ObjectContract { use UserObject; } diff --git a/src/Responses/Objects/ProfilesObject.php b/src/Responses/Objects/ProfilesObject.php index 1b5908f..00d5f8e 100644 --- a/src/Responses/Objects/ProfilesObject.php +++ b/src/Responses/Objects/ProfilesObject.php @@ -10,7 +10,7 @@ class ProfilesObject extends GenericCollection implements ObjectContract { - use CollectionAsset; + use CollectionObject; /** * @throws InvalidArgumentException diff --git a/src/Responses/Objects/SubjectObject.php b/src/Responses/Objects/SubjectObject.php index 6b4c9ae..8546c0b 100644 --- a/src/Responses/Objects/SubjectObject.php +++ b/src/Responses/Objects/SubjectObject.php @@ -3,9 +3,8 @@ namespace Atproto\Responses\Objects; use Atproto\Contracts\Resources\ObjectContract; -use Atproto\Contracts\Resources\ResponseContract; -class SubjectObject implements ResponseContract, ObjectContract +class SubjectObject implements ObjectContract { use UserObject; } diff --git a/src/Responses/Objects/UserObject.php b/src/Responses/Objects/UserObject.php index a22b7d2..faf400c 100644 --- a/src/Responses/Objects/UserObject.php +++ b/src/Responses/Objects/UserObject.php @@ -2,7 +2,6 @@ namespace Atproto\Responses\Objects; -use Atproto\Responses\BaseResponse; use Atproto\Traits\Castable; /** @@ -24,7 +23,6 @@ */ trait UserObject { - use BaseResponse; use BaseObject; use Castable; diff --git a/src/Responses/Objects/ViewerObject.php b/src/Responses/Objects/ViewerObject.php index 646fdf5..6cfa461 100644 --- a/src/Responses/Objects/ViewerObject.php +++ b/src/Responses/Objects/ViewerObject.php @@ -3,8 +3,6 @@ namespace Atproto\Responses\Objects; use Atproto\Contracts\Resources\ObjectContract; -use Atproto\Contracts\Resources\ResponseContract; -use Atproto\Responses\BaseResponse; use Atproto\Traits\Castable; /** @@ -18,9 +16,8 @@ * @method KnownFollowersObject knownFollowers * @method LabelsObject labels */ -class ViewerObject implements ResponseContract, ObjectContract +class ViewerObject implements ObjectContract { - use BaseResponse; use BaseObject; use Castable; diff --git a/tests/Supports/NonPrimitiveAssetTest.php b/tests/Supports/NonPrimitiveAssetTest.php index feb2ea6..adb4931 100644 --- a/tests/Supports/NonPrimitiveAssetTest.php +++ b/tests/Supports/NonPrimitiveAssetTest.php @@ -21,6 +21,10 @@ trait NonPrimitiveAssetTest */ public function testNonPrimitiveAssets(string $name, string $expectedAsset, $value): void { + if ($name === 'labels') { + ; + } + $data = [$name => $value]; $actualAsset = $this->resource($data)->$name(); diff --git a/tests/Unit/Responses/Assets/CollectionObjectTest.php b/tests/Unit/Responses/Assets/CollectionObjectTest.php index daa66e0..71bced5 100644 --- a/tests/Unit/Responses/Assets/CollectionObjectTest.php +++ b/tests/Unit/Responses/Assets/CollectionObjectTest.php @@ -3,7 +3,8 @@ namespace Tests\Unit\Responses\Assets; use Atproto\Contracts\Resources\ObjectContract; -use Atproto\Responses\Objects\CollectionAsset; +use Atproto\Responses\Objects\BaseObject; +use Atproto\Responses\Objects\CollectionObject; use GenericCollection\Exceptions\InvalidArgumentException; use GenericCollection\GenericCollection; use GenericCollection\Interfaces\TypeInterface; @@ -79,7 +80,7 @@ protected function resource(array $data): TestCollectionObject class TestCollectionObject extends GenericCollection implements ObjectContract { - use CollectionAsset; + use CollectionObject; public function __construct(array $content) { @@ -99,6 +100,8 @@ public function type(): TypeInterface class ExampleObject implements ObjectContract { + use BaseObject; + protected $value; public function __construct($value) From e77c0e2f7a759f4dc67b5bab7bffa96cca0196ef Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sat, 9 Nov 2024 02:42:58 +0400 Subject: [PATCH 54/58] test: add integration test for GetProfiles endpoint --- src/Collections/ActorCollection.php | 14 ++++++ .../App/Bsky/Actor/GetProfilesTest.php | 49 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 src/Collections/ActorCollection.php create mode 100644 tests/Feature/Lexicons/App/Bsky/Actor/GetProfilesTest.php diff --git a/src/Collections/ActorCollection.php b/src/Collections/ActorCollection.php new file mode 100644 index 0000000..8122595 --- /dev/null +++ b/src/Collections/ActorCollection.php @@ -0,0 +1,14 @@ +authenticate( + getenv('BLUESKY_IDENTIFIER'), + getenv('BLUESKY_PASSWORD'), + ); + } + + /** + * @throws InvalidArgumentException + */ + public function testGetProfiles(): void + { + $request = static::$client->app() + ->bsky() + ->actor() + ->getProfiles() + ->forge() + ->actors(new ActorCollection([ + static::$client->authenticated()->did() + ])) + ->build(); + + $response = $request->send(); + + $this->assertInstanceOf(GetProfilesResponse::class, $response); + $this->assertInstanceOf(ProfilesObject::class, $response->profiles()); + $this->assertInstanceOf(ProfileObject::class, $response->profiles()->get(0)); + } +} From 4af03c7d95734f7ba7f65c71bc4b00bbd4068561 Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sat, 9 Nov 2024 02:54:31 +0400 Subject: [PATCH 55/58] refactor: simplify collection type validation - Remove unnecessary TypeInterface classes for collection validation - Replace *AssetType classes with closure type validation - Update CollectionObject trait to use Closure instead of TypeInterface - Simplify type validation in collection objects using instanceof checks - Remove redundant test for type method --- .../Types/NonPrimitive/FollowerAssetType.php | 14 -------------- .../Types/NonPrimitive/LabelAssetType.php | 14 -------------- .../Types/NonPrimitive/ProfileAssetType.php | 14 -------------- src/Responses/Objects/CollectionObject.php | 4 ++-- src/Responses/Objects/FollowersObject.php | 7 +++---- src/Responses/Objects/LabelsObject.php | 7 +++---- src/Responses/Objects/ProfilesObject.php | 7 +++---- .../Unit/Responses/Assets/CollectionObjectTest.php | 13 +++---------- 8 files changed, 14 insertions(+), 66 deletions(-) delete mode 100644 src/Collections/Types/NonPrimitive/FollowerAssetType.php delete mode 100644 src/Collections/Types/NonPrimitive/LabelAssetType.php delete mode 100644 src/Collections/Types/NonPrimitive/ProfileAssetType.php diff --git a/src/Collections/Types/NonPrimitive/FollowerAssetType.php b/src/Collections/Types/NonPrimitive/FollowerAssetType.php deleted file mode 100644 index fff2403..0000000 --- a/src/Collections/Types/NonPrimitive/FollowerAssetType.php +++ /dev/null @@ -1,14 +0,0 @@ - $value instanceof FollowerObject; } } diff --git a/src/Responses/Objects/LabelsObject.php b/src/Responses/Objects/LabelsObject.php index 1f390d5..fcedb57 100644 --- a/src/Responses/Objects/LabelsObject.php +++ b/src/Responses/Objects/LabelsObject.php @@ -2,11 +2,10 @@ namespace Atproto\Responses\Objects; -use Atproto\Collections\Types\NonPrimitive\LabelAssetType; use Atproto\Contracts\Resources\ObjectContract; +use Closure; use GenericCollection\Exceptions\InvalidArgumentException; use GenericCollection\GenericCollection; -use GenericCollection\Interfaces\TypeInterface; class LabelsObject extends GenericCollection implements ObjectContract { @@ -20,8 +19,8 @@ protected function item($data): ObjectContract return new LabelObject($data); } - protected function type(): TypeInterface + protected function type(): Closure { - return new LabelAssetType(); + return fn ($value): bool => $value instanceof LabelObject; } } diff --git a/src/Responses/Objects/ProfilesObject.php b/src/Responses/Objects/ProfilesObject.php index 00d5f8e..0aa1f72 100644 --- a/src/Responses/Objects/ProfilesObject.php +++ b/src/Responses/Objects/ProfilesObject.php @@ -2,11 +2,10 @@ namespace Atproto\Responses\Objects; -use Atproto\Collections\Types\NonPrimitive\ProfileAssetType; use Atproto\Contracts\Resources\ObjectContract; +use Closure; use GenericCollection\Exceptions\InvalidArgumentException; use GenericCollection\GenericCollection; -use GenericCollection\Interfaces\TypeInterface; class ProfilesObject extends GenericCollection implements ObjectContract { @@ -20,8 +19,8 @@ protected function item($data): ObjectContract return new ProfileObject($data); } - protected function type(): TypeInterface + protected function type(): Closure { - return new ProfileAssetType(); + return fn ($value): bool => $value instanceof ProfileObject; } } diff --git a/tests/Unit/Responses/Assets/CollectionObjectTest.php b/tests/Unit/Responses/Assets/CollectionObjectTest.php index 71bced5..1d9ec91 100644 --- a/tests/Unit/Responses/Assets/CollectionObjectTest.php +++ b/tests/Unit/Responses/Assets/CollectionObjectTest.php @@ -5,6 +5,7 @@ use Atproto\Contracts\Resources\ObjectContract; use Atproto\Responses\Objects\BaseObject; use Atproto\Responses\Objects\CollectionObject; +use Closure; use GenericCollection\Exceptions\InvalidArgumentException; use GenericCollection\GenericCollection; use GenericCollection\Interfaces\TypeInterface; @@ -61,14 +62,6 @@ public function testGetMethod() } } - - public function testTypeMethod() - { - $type = $this->collectionAsset->type(); - - $this->assertInstanceOf(ExampleAssetType::class, $type); - } - /** * @throws InvalidArgumentException */ @@ -92,9 +85,9 @@ public function item($data): ObjectContract return new ExampleObject($data); } - public function type(): TypeInterface + public function type(): Closure { - return new ExampleAssetType(); + return fn ($value): bool => $value instanceof ExampleObject; } } From 5dcaa1d3a8bf73d269be62726f294e9b6b6ea510 Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sat, 9 Nov 2024 02:58:08 +0400 Subject: [PATCH 56/58] refactor: switch test asset from PNG to WebP format - Remove unused file.png from art directory --- art/file.png | Bin 119922 -> 0 bytes .../Com/Atproto/Repo/CreateRecordTest.php | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 art/file.png diff --git a/art/file.png b/art/file.png deleted file mode 100644 index 80c12813d1b687f2b6ab0f286d4c2c32e8d59456..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 119922 zcmZU)1zeNu+de)@q*XwXR1r~-kZzO|DG^3DBHb|>1qn%&k}d@qU85Nd(uy!(jL|i^ zHW=~0_4$6^|NA~aKA(+yaOZWM*Kr)@ai06|QbU=FoRJ&^0#T_vS9k>ik-i0ih#9V4 z0sgWR+~o!QBKD9|(YXrz1YCU`34Ffosi^O%?efMGV&QHLvT=5CvgYxya<{g2_ONyF z+#!O?06X#g*-75r+QQS$#rckoos%_49oP^MzN2p8en)^`Ko?Ml2mqhFN%t30qS7H?R{=x zu@&OA)sj-10{--Xg(Aw6Zk_yY&C}=E-UB=F>8Y>P(uHo!`R+KFeoplmk*<3!_ydyV zk*MoLU01|eU}u^3Os%s`h{_S!!CNb;sMRm^w5WW3^H%uvJ0iT-O(4RDFW+C2yL$J3 zzeO;#lu1-MF^viF$C|tCI)J`aTazeiX@OVa8k0ts9qm7~%@&KyN zqTSlZ37^|U=|rF$7A`ESak)XNto91@Zh;Y*X=Qmvyp)0rd(BY$?$!H|x&znhzuueX zrOsCkLI1j}d2{6wwf6#;h?Eg}BgbYa7m zaqaUW*xu7#{%(b}fqwD_C-F;|6NR8{V$lO#9TM>POK`0i-Gmmnw0)%M--DXxo^++{ z6Md_a&$+3h)(eu>T8h{5^JRv{u^Vc%r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7O&-}BAM}veg?ytVU;p z$L=-Uy5DpjmE|&~l)7qt^sM7OtfL{u4yw=*Gubdlxfx~hBN)iY1vEQo9^vh~xw5|q z$A5}UGthf6M1PKDWK{IO`I3?WK;OBjeBmAg$S&`@FHB_sWoX(1K|)`fX{OBQBiWOL z%FBKsI0N|QH*(j$PL#QGME=F!=>H4;t&9KZBfTTt_b@`lvQu-~(=*K3)2ZI!TIPQN Df@SV= diff --git a/tests/Feature/Lexicons/Com/Atproto/Repo/CreateRecordTest.php b/tests/Feature/Lexicons/Com/Atproto/Repo/CreateRecordTest.php index 3b16764..786eb37 100644 --- a/tests/Feature/Lexicons/Com/Atproto/Repo/CreateRecordTest.php +++ b/tests/Feature/Lexicons/Com/Atproto/Repo/CreateRecordTest.php @@ -111,7 +111,7 @@ public function testPostCreationWithoutBlobUploading(): void ->text("Testing post creation without a blob uploading") ->embed(new ImageCollection([ new Image( - Blob::viaFile(new FileSupport(__DIR__.'/../../../../../../art/file.png')), + Blob::viaFile(new FileSupport(__DIR__.'/../../../../../../art/logo-small.webp')), 'This blob not uploaded during this post creation' ), ])); From 17e985f9836b150e6a79fd2a60db7f3a109c5c68 Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sat, 9 Nov 2024 03:27:08 +0400 Subject: [PATCH 57/58] docs: enhance README with detailed examples and structure --- LICENSE | 21 +++ README.md | 517 +++++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 452 insertions(+), 86 deletions(-) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..895d76d --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Eldar Shahmaliyev + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index 5167fff..2ef5cb1 100644 --- a/README.md +++ b/README.md @@ -2,158 +2,503 @@ Logo

-# BlueSky SDK +# BlueSky SDK for PHP ![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/shahmal1yev/blueskysdk?label=latest&style=flat) ![Packagist Downloads](https://img.shields.io/packagist/dt/shahmal1yev/blueskysdk) -[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT) +[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE) ![GitHub last commit](https://img.shields.io/github/last-commit/shahmal1yev/blueskysdk) ![GitHub issues](https://img.shields.io/github/issues/shahmal1yev/blueskysdk) ![GitHub stars](https://img.shields.io/github/stars/shahmal1yev/blueskysdk) ![GitHub forks](https://img.shields.io/github/forks/shahmal1yev/blueskysdk) ![GitHub contributors](https://img.shields.io/github/contributors/shahmal1yev/blueskysdk) -## Project Description +## ๐ŸŒŸ Overview -BlueSky SDK is a PHP library used for interacting with the [BlueSky API](https://docs.bsky.app/docs/get-started). This library allows you to perform various -operations using the BlueSky API. +BlueSky SDK is a comprehensive PHP library designed to seamlessly integrate with the BlueSky social network. Built with developers in mind, it provides an intuitive and powerful interface for interacting with BlueSky's features. Whether you're building a social media management tool, content automation system, or just want to integrate BlueSky features into your existing application, this SDK offers all the tools you need. -## Requirements +### Key Features +- Rich text post creation with links, mentions, and hashtags +- Media management (image uploads and attachments) +- Profile and follower management +- Robust error handling +- Type-safe collections and responses +- Comprehensive testing suite +- Modern PHP practices and standards -- **PHP**: 7.4 or newer -- **Composer**: [Dependency management tool](https://getcomposer.org/) for PHP +## ๐Ÿ“ฆ Installation & Requirements -## Installation +### System Requirements +- PHP 7.4 or newer +- Composer package manager +- Required PHP extensions: json, curl, fileinfo -To install BlueSky SDK via Composer, use the following command: +### Installation Steps ```bash composer require shahmal1yev/blueskysdk ``` -## Usage +After installation, make sure to configure your environment variables for authentication: +```env +BLUESKY_IDENTIFIER=your.identifier +BLUESKY_PASSWORD=your-secure-password +``` -Once installed, you can start using the SDK to interact with the BlueSky API. Below are examples of how to -authenticate and perform various operations using the library. +## ๐Ÿš€ Getting Started -### Authentication and Basic Usage +## ๐Ÿ—๏ธ Architecture Overview -First, instantiate the `Client` class and authenticate using your BlueSky credentials: +### Lexicon Structure +The SDK uses a well-organized namespace structure that mirrors the AT Protocol's lexicon hierarchy: ```php -use Atproto\Client; -use Atproto\Responses\Com\Atproto\Server\CreateSessionResponse; +use Atproto\Lexicons\{ + App\Bsky\Feed\Post, // app.bsky.feed.post + App\Bsky\Actor\Profile, // app.bsky.actor.profile + Com\Atproto\Repo\CreateRecord // com.atproto.repo.createRecord +}; +``` -$client = new Client(); +### NSID (Namespaced Identifier) -// Authenticate using your identifier (e.g., email) and password -$client->authenticate($identifier, $password); +Each operation in the SDK corresponds to a specific NSID (Namespaced Identifier) in the AT Protocol. For example: -// Once authenticated, you can retrieve the user's session resource -/** @var CreateSessionResponse $session */ -$session = $client->authenticated(); +```text +- app.bsky.feed.post -> Atproto\Lexicons\App\Bsky\Feed\Post +- app.bsky.actor.getProfile -> Atproto\Lexicons\App\Bsky\Actor\GetProfile ``` -### Making Requests +### Smart Builder Pattern -BlueSky SDK provides a fluent interface to construct API requests. Use chained method calls to navigate through the -API lexicons and forge the request: +The SDK implements a smart builder pattern using method chaining. This provides an intuitive way to construct API +requests: ```php -use Atproto\Contracts\ResourceContract; +$response = $client->app() // Navigate to 'app' namespace + ->bsky() // Navigate to 'bsky' subspace + ->feed() // Navigate to 'feed' operations + ->post() // Select 'post' operation + ->forge() // Initialize the request builder + ->text("Hello!") // Add content + ->send(); // Execute the request +``` + +### Response Handling + +The SDK uses type-safe response objects that automatically cast API responses into convenient PHP objects: -// Example: Fetching a profile +```php +// Getting a profile $profile = $client->app() - ->bsky() - ->actor() - ->getProfile() - ->forge() - ->actor('some-actor-handle') // Specify the actor handle - ->send(); + ->bsky() + ->actor() + ->getProfile() + ->forge() + ->actor('user.bsky.social') + ->send(); + +// Access data through typed methods +echo $profile->displayName(); // Returns string +echo $profile->followersCount(); // Returns int + +/** @var \Carbon\Carbon $createdAt */ +$createdAt $profile->createdAt(); // Returns Carbon instance + +// Response objects are iterable when representing collections +/** @var \Atproto\Responses\Objects\FollowersObject $followers */ +$followers = $client->app() + ->bsky() + ->graph() + ->getFollowers() + ->forge() + ->actor('user.bsky.social') + ->send(); + +foreach ($followers as $follower) { + // Each $follower is a typed object with guaranteed methods + /** @var \Atproto\Responses\Objects\FollowerObject $follower */ + + echo sprintf( + "%s joined on %s\n", + $follower->handle(), + $follower->createdAt()->format('Y-m-d') + ); +} ``` -### Handling Responses +### Authentication +The first step to using the SDK is establishing a connection with BlueSky's servers. The SDK provides a straightforward authentication process: -BlueSky SDK supports both Resource and Castable interfaces, providing flexibility in handling API responses and -enabling smooth data manipulation and casting for a more streamlined development experience. +```php +use Atproto\Client; -Responses are returned as resource instances that implement the `ResourceContract`. These resources provide methods -for accessing data returned by the API. +$client = new Client(); + +// Basic authentication +$client->authenticate('your.identifier', 'your-password'); + +// Or using environment variables (recommended) +$client->authenticate( + getenv('BLUESKY_IDENTIFIER'), + getenv('BLUESKY_PASSWORD') +); +``` + +## ๐Ÿ“ Content Creation + +### Rich Text Posts +The SDK excels at creating engaging social media content with rich text features. Here's a comprehensive guide to creating various types of posts: + +### Marketing Campaign Example +Perfect for social media managers running promotional campaigns: ```php -// Retrieve properties from the profile -/** @var string $displayName */ -$displayName = $profile->displayName(); +// Announcing a special promotion +$client->app() + ->bsky() + ->feed() + ->post() + ->forge() + ->text( + "๐ŸŽ‰ Summer Sale Spectacular! ๐ŸŒž\n\n", + "Get ready for amazing deals on all our premium products! ", + RichText::link('https://yourstore.com/summer-sale', 'Shop Now'), + "\n\nโœจ Highlights:\n", + "โ€ข Up to 50% off on selected items\n", + "โ€ข Free shipping worldwide\n", + "โ€ข Limited time offers\n\n", + "Questions? Ask ", + RichText::mention('did:plc:support', 'our support team'), + "!\n\n", + RichText::tag('SummerSale', 'SummerSale'), + " ", + RichText::tag('ShopNow', 'ShopNow') + ) + ->send(); +``` -/** @var Carbon\Carbon $createdAt */ -$createdAt = $profile->createdAt(); +### Tech Tutorial Series +Ideal for educational content and technical blogs: + +```php +// Upload tutorial screenshot +$tutorialImage = $client->com() + ->atproto() + ->repo() + ->uploadBlob() + ->forge() + ->token($client->authenticated()->accessJwt()) + ->blob('path/to/tutorial-screenshot.jpg') + ->send() + ->blob(); + +// Create in-depth tutorial post +$client->app() + ->bsky() + ->feed() + ->post() + ->forge() + ->text( + "๐Ÿ“˜ PHP Best Practices Guide: Part 1\n\n", + "Today we're diving into modern PHP development. ", + "First in our series about building robust applications.\n\n", + "Key topics covered:\n", + "1. Dependency Injection\n", + "2. Service Containers\n", + "3. Repository Pattern\n\n", + "Full tutorial: ", + RichText::link('https://blog.dev/php-best-practices', 'Read More'), + "\n\nSpecial thanks to ", + RichText::mention('did:plc:reviewer', 'our technical reviewer'), + " for the insights!\n\n", + RichText::tag('PHP', 'PHP'), + " ", + RichText::tag('WebDev', 'WebDev'), + " ", + RichText::tag('Coding', 'Coding') + ) + ->embed(new ImageCollection([ + new Image($tutorialImage, "Code example showing dependency injection in PHP") + ])) + ->send(); ``` -### Working with Assets and Relationships +## ๐Ÿ‘ฅ Community Management -BlueSky SDK allows you to access complex assets like followers and labels directly through the resource instances. +### Profile Analytics +The SDK provides powerful tools for managing and analyzing user profiles. Here's how to build a simple analytics system: ```php -use Atproto\Responses\Objects\FollowersObject; -use Atproto\Responses\Objects\FollowerObject; +use GenericCollection\Collection; +use GenericCollection\Types\Primitive\StringType; + +class CommunityAnalytics { + private $client; + + public function __construct(Client $client) { + $this->client = $client; + } + + public function analyzeTeamProfiles() { + // Get team members' profiles + $teamHandles = new Collection(StringType::class, [ + 'lead.dev.bsky.social', + 'frontend.dev.bsky.social', + 'backend.dev.bsky.social', + 'design.bsky.social' + ]); + + $profiles = $this->client->app() + ->bsky() + ->actor() + ->getProfiles() + ->forge() + ->actors($teamHandles) + ->send(); + + // Analyze profile data + $analytics = []; + foreach ($profiles as $profile) { + $analytics[] = [ + 'name' => $profile->displayName(), + 'followers' => $profile->followersCount(), + 'posts' => $profile->postsCount(), + 'engagement_rate' => $this->calculateEngagement($profile) + ]; + } + + return $analytics; + } + + private function calculateEngagement($profile) { + // Custom engagement calculation logic + return ($profile->followersCount() * $profile->postsCount()) / 100; + } +} +``` -// Fetch the user's followers -/** @var FollowersObject $followers */ -$followers = $profile->viewer() - ->knownFollowers() - ->followers(); +### Follower Engagement System +Create meaningful interactions with your community: -foreach ($followers as $follower) { - /** @var FollowerObject $follower */ - echo $follower->displayName() . " - Created at: " . $follower->createdAt()->format(DATE_ATOM) . "\n"; +```php +class FollowerEngagement { + private $client; + + public function __construct(Client $client) { + $this->client = $client; + } + + public function welcomeNewFollowers() { + $followers = $this->client->app() + ->bsky() + ->graph() + ->getFollowers() + ->forge() + ->actor($this->client->authenticated()->did()) + ->send(); + + $newFollowers = $this->filterTodaysFollowers($followers); + + foreach ($newFollowers as $follower) { + $this->sendWelcomeMessage($follower); + } + } + + private function sendWelcomeMessage($follower) { + $this->client->app() + ->bsky() + ->feed() + ->post() + ->forge() + ->text( + "๐Ÿ‘‹ Welcome to our community ", + RichText::mention($follower->did(), $follower->handle()), + "!\n\n", + "We're excited to have you here. ", + "Check out our pinned posts for community guidelines ", + "and ongoing discussions.\n\n", + "Feel free to introduce yourself in the comments! ๐ŸŒŸ" + ) + ->send(); + } } ``` -### Example: Fetching Profile Information +## ๐ŸŽจ Advanced Content Strategies -Here is a more complete example of fetching and displaying profile information, including created dates and labels: +### Content Calendar Integration +Example of how to integrate the SDK with a content calendar system: ```php -use Atproto\Client; -use Atproto\API\App\Bsky\Actor\GetProfile; -use Atproto\Responses\App\Bsky\Actor\GetProfileResponse; +class ContentScheduler { + private $client; + + public function __construct(Client $client) { + $this->client = $client; + } + + public function schedulePost($content, $images = [], $scheduledTime) { + // Prepare image uploads if any + $uploadedImages = []; + foreach ($images as $image) { + $uploadedBlob = $this->client->com() + ->atproto() + ->repo() + ->uploadBlob() + ->forge() + ->token($this->client->authenticated()->accessJwt()) + ->blob($image['path']) + ->send() + ->blob(); + + $uploadedImages[] = new Image($uploadedBlob, $image['description']); + } + + // Create the post + $post = $this->client->app() + ->bsky() + ->feed() + ->post() + ->forge() + ->text(...$this->formatContent($content)); + + // Add images if any + if (!empty($uploadedImages)) { + $post->embed(new ImageCollection($uploadedImages)); + } + + return $post->send(); + } + + private function formatContent($content) { + // Transform content into rich text components + // Implementation depends on your content structure + } +} +``` -$client->authenticate('user@example.com', 'password'); +## ๐Ÿ› ๏ธ Error Handling & Best Practices -$client->app() - ->bsky() - ->actor() - ->getProfile() - ->forge(); - // ->actor($client->authenticated()->did()); +The SDK provides comprehensive error handling to ensure your application gracefully handles any issues: -/** @var GetProfileResponse $user */ -$user = $client->send(); +```php +use Atproto\Exceptions\{ + InvalidArgumentException, + Auth\AuthRequired, + Http\MissingFieldProvidedException +}; + +class PostManager { + private $client; + + public function __construct(Client $client) { + $this->client = $client; + } + + public function createSafePost($content) { + try { + return $this->client->app() + ->bsky() + ->feed() + ->post() + ->forge() + ->text($content) + ->send(); + + } catch (AuthRequired $e) { + // Handle authentication issues + $this->logError('Authentication failed', $e); + $this->refreshAuthentication(); + + } catch (MissingFieldProvidedException $e) { + // Handle missing required fields + $this->logError('Missing required field', $e); + throw new ValidationException("Post creation failed: {$e->getMessage()}"); + + } catch (InvalidArgumentException $e) { + // Handle invalid input + $this->logError('Invalid input provided', $e); + throw new ValidationException("Invalid post content: {$e->getMessage()}"); + } + } +} +``` -// Output profile details -echo "Display Name: " . $user->displayName() . "\n"; -echo "Created At: " . $user->createdAt()->toDateTimeString() . "\n"; +## ๐Ÿงช Testing -// Accessing and iterating over followers -$followers = $user->viewer()->knownFollowers()->followers(); +The SDK comes with comprehensive testing tools to ensure your integration works flawlessly: -foreach ($followers as $follower) { - echo $follower->displayName() . " followed on " . $follower->createdAt()->format(DATE_ATOM) . "\n"; +```bash +# Run complete test suite +composer test + +# Run specific test suites +composer test-unit # Unit tests +composer test-feature # Feature tests + +# Run code analysis +composer analyse +``` + +### Writing Tests for Your Integration + +```php +class YourIntegrationTest extends TestCase +{ + private static Client $client; + + public static function setUpBeforeClass(): void + { + static::$client = new Client(); + static::$client->authenticate( + getenv('BLUESKY_TEST_IDENTIFIER'), + getenv('BLUESKY_TEST_PASSWORD') + ); + } + + public function testPostCreation() + { + // Your test implementation + } } ``` -### Extending the SDK +## ๐Ÿ“ˆ Performance Tips + +1. **Batch Operations**: When possible, use bulk endpoints +2. **Image Optimization**: Compress images before upload +3. **Cache Responses**: Implement caching for frequently accessed data +4. **Rate Limiting**: Respect API limits using built-in tools + +## ๐Ÿค Contributing + +We love your input! We want to make contributing to BlueSky SDK as easy and transparent as possible. Here's how you can help: + +1. Fork the repo +2. Clone your fork +3. Create your feature branch +4. Commit your changes +5. Push to your branch +6. Create a pull request + +### Development Guidelines -BlueSky SDK is built with extensibility in mind. You can add custom functionality by extending existing classes and -creating your own request and resource types. Follow the structure used in the SDK to maintain consistency. +- Follow PSR-12 coding standards +- Add tests for new features +- Update documentation +- Use meaningful commit messages -## Contribution +## ๐Ÿ“ License -We welcome contributions from the community! If you find any bugs or would like to add new features, feel free to: +BlueSky SDK is released under the MIT License. See [LICENSE](LICENSE) for more information. -- **Open an issue**: Report bugs, request features, or suggest improvements. -- **Submit a pull request**: Contributions to the codebase are welcome. Please follow best practices and ensure that your code adheres to the existing architecture and coding standards. +## ๐Ÿ™‹โ€โ™‚๏ธ Support -## License +- **Official Documentation**: [Official Docs](https://docs.bsky.app) +- **SDK Documentation**: [SDK Docs](https://blueskysdk.shahmal1yev.dev) +- **Issues**: [GitHub Issues](https://github.com/shahmal1yev/blueskysdk/issues) +- **Discussions**: Start a discussion in [GitHub Discussions](https://github.com/shahmal1yev/blueskysdk/discussions) -BlueSky SDK is licensed under the MIT License. See the LICENSE file for full details. +--- +Built with โค๏ธ by [Eldar Shahmaliyev](https://shahmal1yev.dev/about) for the PHP community. From e3470c9120a0c452d63f36f788c9b32b8a939214 Mon Sep 17 00:00:00 2001 From: Eldar Shahmaliyev Date: Sat, 9 Nov 2024 03:40:19 +0400 Subject: [PATCH 58/58] apply php-cs-fixer and import optimizing --- src/Collections/ActorCollection.php | 4 ++-- src/Lexicons/App/Bsky/Graph/GetFollowers.php | 1 - src/Lexicons/App/Bsky/RichText/FeatureAbstract.php | 1 - src/Responses/App/Bsky/Actor/GetProfilesResponse.php | 2 +- src/Responses/App/Bsky/Graph/GetFollowersResponse.php | 2 +- tests/Feature/Lexicons/App/Bsky/Actor/GetProfilesTest.php | 1 - tests/Feature/Lexicons/Com/Atproto/Repo/CreateRecordTest.php | 4 ---- tests/Unit/Lexicons/App/Bsky/RichText/FeatureTests.php | 1 - tests/Unit/Responses/BaseResponseTest.php | 2 +- 9 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/Collections/ActorCollection.php b/src/Collections/ActorCollection.php index 8122595..a4cf374 100644 --- a/src/Collections/ActorCollection.php +++ b/src/Collections/ActorCollection.php @@ -9,6 +9,6 @@ class ActorCollection extends GenericCollection { public function __construct(iterable $collection = []) { - parent::__construct(new StringType, $collection); + parent::__construct(new StringType(), $collection); } -} \ No newline at end of file +} diff --git a/src/Lexicons/App/Bsky/Graph/GetFollowers.php b/src/Lexicons/App/Bsky/Graph/GetFollowers.php index ffb0aa7..2c62509 100644 --- a/src/Lexicons/App/Bsky/Graph/GetFollowers.php +++ b/src/Lexicons/App/Bsky/Graph/GetFollowers.php @@ -9,7 +9,6 @@ use Atproto\Exceptions\InvalidArgumentException; use Atproto\Lexicons\APIRequest; use Atproto\Lexicons\Traits\AuthenticatedEndpoint; -use Atproto\Lexicons\Traits\Endpoint; use Atproto\Responses\App\Bsky\Graph\GetFollowersResponse; class GetFollowers extends APIRequest implements LexiconContract diff --git a/src/Lexicons/App/Bsky/RichText/FeatureAbstract.php b/src/Lexicons/App/Bsky/RichText/FeatureAbstract.php index ab71af2..72e83a6 100644 --- a/src/Lexicons/App/Bsky/RichText/FeatureAbstract.php +++ b/src/Lexicons/App/Bsky/RichText/FeatureAbstract.php @@ -4,7 +4,6 @@ use Atproto\Contracts\LexiconContract; use Atproto\Lexicons\Traits\Lexicon; -use Atproto\Lexicons\Traits\Serializable; abstract class FeatureAbstract implements LexiconContract { diff --git a/src/Responses/App/Bsky/Actor/GetProfilesResponse.php b/src/Responses/App/Bsky/Actor/GetProfilesResponse.php index 05a55b2..617d0e4 100644 --- a/src/Responses/App/Bsky/Actor/GetProfilesResponse.php +++ b/src/Responses/App/Bsky/Actor/GetProfilesResponse.php @@ -3,8 +3,8 @@ namespace Atproto\Responses\App\Bsky\Actor; use Atproto\Contracts\Resources\ResponseContract; -use Atproto\Responses\Objects\ProfilesObject; use Atproto\Responses\BaseResponse; +use Atproto\Responses\Objects\ProfilesObject; use Atproto\Traits\Castable; class GetProfilesResponse implements ResponseContract diff --git a/src/Responses/App/Bsky/Graph/GetFollowersResponse.php b/src/Responses/App/Bsky/Graph/GetFollowersResponse.php index 197ed3f..7949368 100644 --- a/src/Responses/App/Bsky/Graph/GetFollowersResponse.php +++ b/src/Responses/App/Bsky/Graph/GetFollowersResponse.php @@ -3,10 +3,10 @@ namespace Atproto\Responses\App\Bsky\Graph; use Atproto\Contracts\Resources\ResponseContract; +use Atproto\Responses\BaseResponse; use Atproto\Responses\Objects\BaseObject; use Atproto\Responses\Objects\FollowersObject; use Atproto\Responses\Objects\SubjectObject; -use Atproto\Responses\BaseResponse; use Atproto\Traits\Castable; class GetFollowersResponse implements ResponseContract diff --git a/tests/Feature/Lexicons/App/Bsky/Actor/GetProfilesTest.php b/tests/Feature/Lexicons/App/Bsky/Actor/GetProfilesTest.php index 4b55db2..767d70c 100644 --- a/tests/Feature/Lexicons/App/Bsky/Actor/GetProfilesTest.php +++ b/tests/Feature/Lexicons/App/Bsky/Actor/GetProfilesTest.php @@ -4,7 +4,6 @@ use Atproto\Client; use Atproto\Collections\ActorCollection; -use Atproto\Lexicons\App\Bsky\Actor\GetProfiles; use Atproto\Responses\App\Bsky\Actor\GetProfilesResponse; use Atproto\Responses\Objects\ProfileObject; use Atproto\Responses\Objects\ProfilesObject; diff --git a/tests/Feature/Lexicons/Com/Atproto/Repo/CreateRecordTest.php b/tests/Feature/Lexicons/Com/Atproto/Repo/CreateRecordTest.php index 786eb37..64a9c42 100644 --- a/tests/Feature/Lexicons/Com/Atproto/Repo/CreateRecordTest.php +++ b/tests/Feature/Lexicons/Com/Atproto/Repo/CreateRecordTest.php @@ -5,14 +5,10 @@ use Atproto\Client; use Atproto\Contracts\Lexicons\App\Bsky\Feed\PostBuilderContract; use Atproto\DataModel\Blob\Blob; -use Atproto\Exceptions\BlueskyException; use Atproto\Exceptions\InvalidArgumentException; use Atproto\Lexicons\App\Bsky\Embed\Collections\ImageCollection; use Atproto\Lexicons\App\Bsky\Embed\Image; use Atproto\Lexicons\App\Bsky\RichText\RichText; -use Atproto\Lexicons\App\Bsky\RichText\Link; -use Atproto\Lexicons\App\Bsky\RichText\Mention; -use Atproto\Lexicons\App\Bsky\RichText\Tag; use Atproto\Lexicons\Com\Atproto\Repo\CreateRecord; use Atproto\Support\Arr; use Atproto\Support\FileSupport; diff --git a/tests/Unit/Lexicons/App/Bsky/RichText/FeatureTests.php b/tests/Unit/Lexicons/App/Bsky/RichText/FeatureTests.php index cf07f59..f041b18 100644 --- a/tests/Unit/Lexicons/App/Bsky/RichText/FeatureTests.php +++ b/tests/Unit/Lexicons/App/Bsky/RichText/FeatureTests.php @@ -3,7 +3,6 @@ namespace Tests\Unit\Lexicons\App\Bsky\RichText; use Atproto\Lexicons\App\Bsky\RichText\FeatureAbstract; -use ReflectionException; use Tests\Supports\Reflection; trait FeatureTests diff --git a/tests/Unit/Responses/BaseResponseTest.php b/tests/Unit/Responses/BaseResponseTest.php index bf0d116..f6bb926 100644 --- a/tests/Unit/Responses/BaseResponseTest.php +++ b/tests/Unit/Responses/BaseResponseTest.php @@ -5,8 +5,8 @@ use Atproto\Contracts\Resources\ObjectContract; use Atproto\Contracts\Resources\ResponseContract; use Atproto\Exceptions\Resource\BadAssetCallException; -use Atproto\Responses\Objects\BaseObject; use Atproto\Responses\BaseResponse; +use Atproto\Responses\Objects\BaseObject; use Atproto\Traits\Castable; use PHPUnit\Framework\TestCase;