@@ -58,4 +58,89 @@ public function it_generated_graphviz_in_jpeg_format()
58
58
59
59
$ this ->assertStringContainsString ('Wrote diagram to graph.jpeg ' , Artisan::output ());
60
60
}
61
+
62
+ /** @test */
63
+ public function it_generates_text_output_file ()
64
+ {
65
+ $ this ->app ['config ' ]->set ('erd-generator.directories ' , [__DIR__ . '/Models ' ]);
66
+
67
+ $ outputFile = __DIR__ . '/output_test.txt ' ;
68
+
69
+ // Make sure the file doesn't exist before the test
70
+ if (file_exists ($ outputFile )) {
71
+ unlink ($ outputFile );
72
+ }
73
+
74
+ Artisan::call ('generate:erd ' , [
75
+ 'filename ' => $ outputFile ,
76
+ '--text-output ' => true
77
+ ]);
78
+
79
+ $ this ->assertFileExists ($ outputFile );
80
+ $ this ->assertStringContainsString ('Wrote text diagram to ' . $ outputFile , Artisan::output ());
81
+
82
+ // Check if the file contains GraphViz DOT content
83
+ $ fileContent = file_get_contents ($ outputFile );
84
+ $ this ->assertStringContainsString ('digraph ' , $ fileContent );
85
+
86
+ // Clean up
87
+ if (file_exists ($ outputFile )) {
88
+ unlink ($ outputFile );
89
+ }
90
+ }
91
+
92
+ /** @test */
93
+ public function it_generates_structured_text_output_file ()
94
+ {
95
+ $ this ->app ['config ' ]->set ('erd-generator.directories ' , [__DIR__ . '/Models ' ]);
96
+
97
+ $ outputFile = __DIR__ . '/structured_test.txt ' ;
98
+
99
+ // Make sure the file doesn't exist before the test
100
+ if (file_exists ($ outputFile )) {
101
+ unlink ($ outputFile );
102
+ }
103
+
104
+ Artisan::call ('generate:erd ' , [
105
+ 'filename ' => $ outputFile ,
106
+ '--structured ' => true
107
+ ]);
108
+
109
+ $ this ->assertFileExists ($ outputFile );
110
+ $ this ->assertStringContainsString ('Wrote structured text diagram to ' . $ outputFile , Artisan::output ());
111
+
112
+ // Check if the file contains structured Markdown content
113
+ $ fileContent = file_get_contents ($ outputFile );
114
+ $ this ->assertStringContainsString ('# Entity Relationship Diagram ' , $ fileContent );
115
+ $ this ->assertStringContainsString ('## Entities ' , $ fileContent );
116
+ $ this ->assertStringContainsString ('## Relationships ' , $ fileContent );
117
+
118
+ // Clean up
119
+ if (file_exists ($ outputFile )) {
120
+ unlink ($ outputFile );
121
+ }
122
+ }
123
+
124
+ /** @test */
125
+ public function it_generates_structured_text_output_with_correct_content ()
126
+ {
127
+ $ this ->app ['config ' ]->set ('erd-generator.directories ' , [__DIR__ . '/Models ' ]);
128
+
129
+ // Get the structured text output directly from the GraphBuilder
130
+ $ models = $ this ->app ->make ('BeyondCode\ErdGenerator\ModelFinder ' )
131
+ ->getModelsInDirectory (__DIR__ . '/Models ' )
132
+ ->transform (function ($ model ) {
133
+ return new \BeyondCode \ErdGenerator \Model (
134
+ $ model ,
135
+ (new \ReflectionClass ($ model ))->getShortName (),
136
+ $ this ->app ->make ('BeyondCode\ErdGenerator\RelationFinder ' )->getModelRelations ($ model )
137
+ );
138
+ });
139
+
140
+ $ structuredOutput = $ this ->app ->make ('BeyondCode\ErdGenerator\GraphBuilder ' )
141
+ ->generateStructuredTextRepresentation ($ models );
142
+
143
+ // Assert the structured output matches the snapshot
144
+ $ this ->assertMatchesSnapshot ($ structuredOutput );
145
+ }
61
146
}
0 commit comments