Parse and validate AT Protocol Lexicons with DTO generation for Laravel
at main 78 lines 1.8 kB view raw
1<?php 2 3namespace SocialDept\AtpSchema\Tests\Unit\Validation\Rules; 4 5use Orchestra\Testbench\TestCase; 6use SocialDept\AtpSchema\Validation\Rules\MaxGraphemes; 7 8class MaxGraphemesTest extends TestCase 9{ 10 public function test_it_validates_string_within_limit(): void 11 { 12 $rule = new MaxGraphemes(10); 13 14 $valid = 'Hello'; 15 16 $failed = false; 17 $rule->validate('text', $valid, function () use (&$failed) { 18 $failed = true; 19 }); 20 21 $this->assertFalse($failed); 22 } 23 24 public function test_it_rejects_string_exceeding_limit(): void 25 { 26 $rule = new MaxGraphemes(5); 27 28 $invalid = 'This is too long'; 29 30 $failed = false; 31 $rule->validate('text', $invalid, function () use (&$failed) { 32 $failed = true; 33 }); 34 35 $this->assertTrue($failed); 36 } 37 38 public function test_it_counts_graphemes_correctly(): void 39 { 40 $rule = new MaxGraphemes(5); 41 42 // 6 emoji graphemes 43 $invalid = '😀😁😂😃😄😅'; 44 45 $failed = false; 46 $rule->validate('text', $invalid, function () use (&$failed) { 47 $failed = true; 48 }); 49 50 $this->assertTrue($failed); 51 } 52 53 public function test_it_allows_exact_limit(): void 54 { 55 $rule = new MaxGraphemes(5); 56 57 $valid = '😀😁😂😃😄'; 58 59 $failed = false; 60 $rule->validate('text', $valid, function () use (&$failed) { 61 $failed = true; 62 }); 63 64 $this->assertFalse($failed); 65 } 66 67 public function test_it_rejects_non_string(): void 68 { 69 $rule = new MaxGraphemes(10); 70 71 $failed = false; 72 $rule->validate('text', 123, function () use (&$failed) { 73 $failed = true; 74 }); 75 76 $this->assertTrue($failed); 77 } 78}