Parse and validate AT Protocol Lexicons with DTO generation for Laravel
at dev 2.0 kB view raw
1<?php 2 3namespace SocialDept\AtpSchema\Tests\Unit\Console; 4 5use Orchestra\Testbench\TestCase; 6use SocialDept\AtpSchema\Console\ValidateCommand; 7use SocialDept\AtpSchema\SchemaServiceProvider; 8 9class ValidateCommandTest extends TestCase 10{ 11 protected function getPackageProviders($app): array 12 { 13 return [SchemaServiceProvider::class]; 14 } 15 16 protected function setUp(): void 17 { 18 parent::setUp(); 19 20 config([ 21 'schema.sources' => [__DIR__.'/../../fixtures'], 22 ]); 23 } 24 25 public function test_it_validates_valid_data(): void 26 { 27 $data = json_encode([ 28 'text' => 'Hello, World!', 29 'createdAt' => '2024-01-01T00:00:00Z', 30 ]); 31 32 $this->artisan(ValidateCommand::class, [ 33 'nsid' => 'app.bsky.feed.post', 34 '--data' => $data, 35 ]) 36 ->expectsOutput('Validating data against schema: app.bsky.feed.post') 37 ->expectsOutput('✓ Validation passed') 38 ->assertSuccessful(); 39 } 40 41 public function test_it_fails_on_invalid_data(): void 42 { 43 $data = json_encode([ 44 'text' => 'Hello, World!', 45 // Missing required createdAt 46 ]); 47 48 $this->artisan(ValidateCommand::class, [ 49 'nsid' => 'app.bsky.feed.post', 50 '--data' => $data, 51 ]) 52 ->expectsOutput('✗ Validation failed:') 53 ->assertFailed(); 54 } 55 56 public function test_it_requires_data_or_file_option(): void 57 { 58 $this->artisan(ValidateCommand::class, [ 59 'nsid' => 'app.bsky.feed.post', 60 ]) 61 ->expectsOutput('Either --data or --file option must be provided') 62 ->assertFailed(); 63 } 64 65 public function test_it_handles_invalid_json(): void 66 { 67 $this->artisan(ValidateCommand::class, [ 68 'nsid' => 'app.bsky.feed.post', 69 '--data' => '{invalid json}', 70 ]) 71 ->assertFailed(); 72 } 73}