Parse and validate AT Protocol Lexicons with DTO generation for Laravel
1<?php
2
3namespace SocialDept\AtpSchema\Tests\Unit\Generator;
4
5use Orchestra\Testbench\TestCase;
6use SocialDept\AtpSchema\Generator\NamespaceResolver;
7
8class NamespaceResolverTest extends TestCase
9{
10 protected NamespaceResolver $resolver;
11
12 protected function setUp(): void
13 {
14 parent::setUp();
15
16 $this->resolver = new NamespaceResolver('App\\Lexicon');
17 }
18
19 public function test_it_resolves_namespace_from_nsid(): void
20 {
21 $namespace = $this->resolver->resolveNamespace('app.bsky.feed.post');
22
23 $this->assertSame('App\\Lexicon\\App\\Bsky\\Feed', $namespace);
24 }
25
26 public function test_it_resolves_class_name_from_nsid(): void
27 {
28 $className = $this->resolver->resolveClassName('app.bsky.feed.post');
29
30 $this->assertSame('Post', $className);
31 }
32
33 public function test_it_resolves_class_name_with_definition(): void
34 {
35 $className = $this->resolver->resolveClassName('app.bsky.feed.post', 'replyRef');
36
37 $this->assertSame('ReplyRef', $className);
38 }
39
40 public function test_it_resolves_fully_qualified_name(): void
41 {
42 $fqn = $this->resolver->resolveFullyQualifiedName('app.bsky.feed.post');
43
44 $this->assertSame('App\\Lexicon\\App\\Bsky\\Feed\\Post', $fqn);
45 }
46
47 public function test_it_resolves_fully_qualified_name_with_definition(): void
48 {
49 $fqn = $this->resolver->resolveFullyQualifiedName('app.bsky.feed.post', 'replyRef');
50
51 $this->assertSame('App\\Lexicon\\App\\Bsky\\Feed\\ReplyRef', $fqn);
52 }
53
54 public function test_it_resolves_file_path(): void
55 {
56 $path = $this->resolver->resolveFilePath('app.bsky.feed.post', '/var/www/app');
57
58 $this->assertSame('/var/www/app/App/Bsky/Feed/Post.php', $path);
59 }
60
61 public function test_it_handles_hyphens_in_nsid(): void
62 {
63 $className = $this->resolver->resolveClassName('app.bsky.feed.feed-view');
64
65 $this->assertSame('FeedView', $className);
66 }
67
68 public function test_it_gets_base_namespace(): void
69 {
70 $this->assertSame('App\\Lexicon', $this->resolver->getBaseNamespace());
71 }
72
73 public function test_it_handles_custom_base_namespace(): void
74 {
75 $resolver = new NamespaceResolver('Custom\\Namespace');
76
77 $namespace = $resolver->resolveNamespace('app.bsky.feed.post');
78
79 $this->assertSame('Custom\\Namespace\\App\\Bsky\\Feed', $namespace);
80 }
81}