Parse and validate AT Protocol Lexicons with DTO generation for Laravel
at main 83 lines 2.0 kB view raw
1<?php 2 3namespace SocialDept\AtpSchema\Tests\Unit\Validation\Rules; 4 5use Orchestra\Testbench\TestCase; 6use SocialDept\AtpSchema\Validation\Rules\Handle; 7 8class HandleTest extends TestCase 9{ 10 protected Handle $rule; 11 12 protected function setUp(): void 13 { 14 parent::setUp(); 15 16 $this->rule = new Handle(); 17 } 18 19 public function test_it_validates_valid_handle(): void 20 { 21 $valid = 'user.bsky.social'; 22 23 $failed = false; 24 $this->rule->validate('handle', $valid, function () use (&$failed) { 25 $failed = true; 26 }); 27 28 $this->assertFalse($failed); 29 } 30 31 public function test_it_validates_various_handles(): void 32 { 33 $validHandles = [ 34 'example.com', 35 'user.bsky.social', 36 'my-handle.example.io', 37 'test123.domain.org', 38 ]; 39 40 foreach ($validHandles as $handle) { 41 $failed = false; 42 $this->rule->validate('handle', $handle, function () use (&$failed) { 43 $failed = true; 44 }); 45 46 $this->assertFalse($failed, "Expected {$handle} to be valid"); 47 } 48 } 49 50 public function test_it_rejects_invalid_handle(): void 51 { 52 $invalid = 'invalid handle'; 53 54 $failed = false; 55 $this->rule->validate('handle', $invalid, function () use (&$failed) { 56 $failed = true; 57 }); 58 59 $this->assertTrue($failed); 60 } 61 62 public function test_it_rejects_too_short_handle(): void 63 { 64 $invalid = 'ab'; 65 66 $failed = false; 67 $this->rule->validate('handle', $invalid, function () use (&$failed) { 68 $failed = true; 69 }); 70 71 $this->assertTrue($failed); 72 } 73 74 public function test_it_rejects_non_string(): void 75 { 76 $failed = false; 77 $this->rule->validate('handle', 123, function () use (&$failed) { 78 $failed = true; 79 }); 80 81 $this->assertTrue($failed); 82 } 83}