Parse and validate AT Protocol Lexicons with DTO generation for Laravel
1<?php
2
3namespace SocialDept\AtpSchema\Tests\Unit\Validation\Rules;
4
5use Orchestra\Testbench\TestCase;
6use SocialDept\AtpSchema\Validation\Rules\AtUri;
7
8class AtUriTest extends TestCase
9{
10 protected AtUri $rule;
11
12 protected function setUp(): void
13 {
14 parent::setUp();
15
16 $this->rule = new AtUri();
17 }
18
19 public function test_it_validates_valid_at_uri_with_did(): void
20 {
21 $valid = 'at://did:plc:z72i7hdynmk6r22z27h6tvur/app.bsky.feed.post/3jwlwj2ctlk26';
22
23 $failed = false;
24 $this->rule->validate('uri', $valid, function () use (&$failed) {
25 $failed = true;
26 });
27
28 $this->assertFalse($failed);
29 }
30
31 public function test_it_validates_valid_at_uri_with_handle(): void
32 {
33 $valid = 'at://user.bsky.social/app.bsky.feed.post/3jwlwj2ctlk26';
34
35 $failed = false;
36 $this->rule->validate('uri', $valid, function () use (&$failed) {
37 $failed = true;
38 });
39
40 $this->assertFalse($failed);
41 }
42
43 public function test_it_validates_at_uri_without_path(): void
44 {
45 $valid = 'at://did:plc:z72i7hdynmk6r22z27h6tvur';
46
47 $failed = false;
48 $this->rule->validate('uri', $valid, function () use (&$failed) {
49 $failed = true;
50 });
51
52 $this->assertFalse($failed);
53 }
54
55 public function test_it_rejects_uri_without_at_protocol(): void
56 {
57 $invalid = 'https://example.com/path';
58
59 $failed = false;
60 $this->rule->validate('uri', $invalid, function () use (&$failed) {
61 $failed = true;
62 });
63
64 $this->assertTrue($failed);
65 }
66
67 public function test_it_rejects_invalid_authority(): void
68 {
69 $invalid = 'at://not a valid authority/path';
70
71 $failed = false;
72 $this->rule->validate('uri', $invalid, function () use (&$failed) {
73 $failed = true;
74 });
75
76 $this->assertTrue($failed);
77 }
78
79 public function test_it_rejects_empty_uri(): void
80 {
81 $invalid = 'at://';
82
83 $failed = false;
84 $this->rule->validate('uri', $invalid, function () use (&$failed) {
85 $failed = true;
86 });
87
88 $this->assertTrue($failed);
89 }
90
91 public function test_it_rejects_non_string(): void
92 {
93 $failed = false;
94 $this->rule->validate('uri', 123, function () use (&$failed) {
95 $failed = true;
96 });
97
98 $this->assertTrue($failed);
99 }
100}