Parse and validate AT Protocol Lexicons with DTO generation for Laravel
1<?php
2
3namespace SocialDept\AtpSchema\Tests\Unit\Console;
4
5use Orchestra\Testbench\TestCase;
6use SocialDept\AtpSchema\Console\GenerateCommand;
7use SocialDept\AtpSchema\SchemaServiceProvider;
8
9class GenerateCommandTest 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 'schema.lexicons.output_path' => sys_get_temp_dir().'/schema-test',
23 'schema.lexicons.base_namespace' => 'Test\\Generated',
24 ]);
25 }
26
27 public function test_it_generates_code_in_dry_run_mode(): void
28 {
29 $this->artisan(GenerateCommand::class, [
30 'nsid' => 'app.bsky.feed.post',
31 '--dry-run' => true,
32 ])
33 ->expectsOutput('Generating DTO classes for schema: app.bsky.feed.post')
34 ->expectsOutput('Dry run mode - no files will be written')
35 ->assertSuccessful();
36 }
37
38 public function test_it_handles_invalid_nsid(): void
39 {
40 $this->artisan(GenerateCommand::class, [
41 'nsid' => 'nonexistent.schema',
42 ])
43 ->expectsOutput('Generating DTO classes for schema: nonexistent.schema')
44 ->assertFailed();
45 }
46
47 public function test_it_accepts_custom_output_directory(): void
48 {
49 $this->artisan(GenerateCommand::class, [
50 'nsid' => 'app.bsky.feed.post',
51 '--output' => '/custom/path',
52 '--dry-run' => true,
53 ])
54 ->assertSuccessful();
55 }
56
57 public function test_it_accepts_custom_namespace(): void
58 {
59 $this->artisan(GenerateCommand::class, [
60 'nsid' => 'app.bsky.feed.post',
61 '--namespace' => 'Custom\\Namespace',
62 '--dry-run' => true,
63 ])
64 ->assertSuccessful();
65 }
66}