Resolve AT Protocol DIDs, handles, and schemas with intelligent caching for Laravel
1<?php
2
3namespace SocialDept\AtpResolver\Tests\Unit;
4
5use PHPUnit\Framework\TestCase;
6use SocialDept\AtpResolver\Data\DidDocument;
7
8class DidDocumentTest extends TestCase
9{
10 public function test_it_can_be_created_from_array(): void
11 {
12 $data = [
13 'id' => 'did:plc:abc123',
14 'alsoKnownAs' => ['at://user.bsky.social'],
15 'verificationMethod' => [],
16 'service' => [
17 [
18 'type' => 'AtprotoPersonalDataServer',
19 'serviceEndpoint' => 'https://bsky.social',
20 ],
21 ],
22 ];
23
24 $document = DidDocument::fromArray($data);
25
26 $this->assertSame('did:plc:abc123', $document->id);
27 $this->assertSame(['at://user.bsky.social'], $document->alsoKnownAs);
28 $this->assertCount(1, $document->service);
29 }
30
31 public function test_it_can_get_pds_endpoint(): void
32 {
33 $document = DidDocument::fromArray([
34 'id' => 'did:plc:abc123',
35 'service' => [
36 [
37 'type' => 'AtprotoPersonalDataServer',
38 'serviceEndpoint' => 'https://bsky.social',
39 ],
40 ],
41 ]);
42
43 $this->assertSame('https://bsky.social', $document->getPdsEndpoint());
44 }
45
46 public function test_it_returns_null_when_no_pds_endpoint(): void
47 {
48 $document = DidDocument::fromArray([
49 'id' => 'did:plc:abc123',
50 'service' => [],
51 ]);
52
53 $this->assertNull($document->getPdsEndpoint());
54 }
55
56 public function test_it_can_get_handle(): void
57 {
58 $document = DidDocument::fromArray([
59 'id' => 'did:plc:abc123',
60 'alsoKnownAs' => ['at://user.bsky.social'],
61 ]);
62
63 $this->assertSame('user.bsky.social', $document->getHandle());
64 }
65
66 public function test_it_returns_null_when_no_handle(): void
67 {
68 $document = DidDocument::fromArray([
69 'id' => 'did:plc:abc123',
70 'alsoKnownAs' => [],
71 ]);
72
73 $this->assertNull($document->getHandle());
74 }
75
76 public function test_it_can_convert_to_array(): void
77 {
78 $data = [
79 'id' => 'did:plc:abc123',
80 'alsoKnownAs' => ['at://user.bsky.social'],
81 ];
82
83 $document = DidDocument::fromArray($data);
84
85 $this->assertSame($data, $document->toArray());
86 }
87}