@@ -30,7 +30,7 @@ protected function setUp(): void
3030 /**
3131 * @test
3232 */
33- public function output_writes_nothing_for_empty_tree ()
33+ public function output_generates_nothing_for_empty_tree ()
3434 {
3535 $ this ->files ->expects ('stub ' )
3636 ->with ('model/class.stub ' )
@@ -45,7 +45,7 @@ public function output_writes_nothing_for_empty_tree()
4545 * @test
4646 * @dataProvider modelTreeDataProvider
4747 */
48- public function output_writes_migration_for_model_tree ($ definition , $ path , $ model )
48+ public function output_generates_models ($ definition , $ path , $ model )
4949 {
5050 $ this ->files ->expects ('stub ' )
5151 ->with ('model/class.stub ' )
@@ -112,6 +112,45 @@ public function output_respects_configuration()
112112 $ this ->assertEquals (['created ' => ['src/path/Models/Comment.php ' ]], $ this ->subject ->output ($ tree ));
113113 }
114114
115+ /**
116+ * @test
117+ * @dataProvider docBlockModelsDataProvider
118+ */
119+ public function output_generates_phpdoc_for_model ($ definition , $ path , $ model )
120+ {
121+ $ this ->app ['config ' ]->set ('blueprint.generate_phpdocs ' , true );
122+
123+ $ this ->files ->expects ('stub ' )
124+ ->with ('model/class.stub ' )
125+ ->andReturn (file_get_contents ('stubs/model/class.stub ' ));
126+
127+ $ this ->files ->expects ('stub ' )
128+ ->with ('model/fillable.stub ' )
129+ ->andReturn (file_get_contents ('stubs/model/fillable.stub ' ));
130+
131+ $ this ->files ->expects ('stub ' )
132+ ->with ('model/casts.stub ' )
133+ ->andReturn (file_get_contents ('stubs/model/casts.stub ' ));
134+
135+ if ($ definition === 'definitions/readme-example.bp ' ) {
136+ $ this ->files ->expects ('stub ' )
137+ ->with ('model/dates.stub ' )
138+ ->andReturn (file_get_contents ('stubs/model/dates.stub ' ));
139+ }
140+
141+ $ this ->files ->shouldReceive ('stub ' )
142+ ->with ('model/method.stub ' )
143+ ->andReturn (file_get_contents ('stubs/model/method.stub ' ));
144+
145+ $ this ->files ->expects ('put ' )
146+ ->with ($ path , $ this ->fixture ($ model ));
147+
148+ $ tokens = $ this ->blueprint ->parse ($ this ->fixture ($ definition ));
149+ $ tree = $ this ->blueprint ->analyze ($ tokens );
150+
151+ $ this ->assertEquals (['created ' => [$ path ]], $ this ->subject ->output ($ tree ));
152+ }
153+
115154 public function modelTreeDataProvider ()
116155 {
117156 return [
@@ -123,4 +162,13 @@ public function modelTreeDataProvider()
123162 ['definitions/nested-components.bp ' , 'app/Admin/User.php ' , 'models/nested-components.php ' ],
124163 ];
125164 }
165+
166+ public function docBlockModelsDataProvider ()
167+ {
168+ return [
169+ ['definitions/readme-example.bp ' , 'app/Post.php ' , 'models/readme-example-phpdoc.php ' ],
170+ ['definitions/soft-deletes.bp ' , 'app/Comment.php ' , 'models/soft-deletes-phpdoc.php ' ],
171+ ['definitions/disable-auto-columns.bp ' , 'app/State.php ' , 'models/disable-auto-columns-phpdoc.php ' ],
172+ ];
173+ }
126174}
0 commit comments