Skip to content

Commit b6ffc81

Browse files
authored
Use modern App/Models namespace as default (#521)
1 parent 7fe3785 commit b6ffc81

File tree

83 files changed

+254
-194
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+254
-194
lines changed

tests/Feature/Commands/EraseCommandTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function it_parses_and_update_the_trace_file()
2626
$this->filesystem->expects('put')
2727
->with('.blueprint', "other: test.php\n");
2828

29-
$this->filesystem->expects('exists')->with('app');
29+
$this->filesystem->expects('exists')->with('app/Models');
3030

3131
$this->artisan('blueprint:erase')
3232
->assertExitCode(0);
@@ -45,7 +45,7 @@ public function it_deletes_the_created_files()
4545
]);
4646

4747
$this->filesystem->expects('put')->with('.blueprint', '{ }');
48-
$this->filesystem->expects('exists')->with('app');
48+
$this->filesystem->expects('exists')->with('app/Models');
4949

5050
$this->artisan('blueprint:erase')
5151
->assertExitCode(0)
@@ -62,7 +62,7 @@ public function it_notify_about_the_updated_files()
6262
->andReturn("updated:\n - updated_file1.php\n - updated_file2.php");
6363

6464
$this->filesystem->expects('put')->with('.blueprint', '{ }');
65-
$this->filesystem->expects('exists')->with('app');
65+
$this->filesystem->expects('exists')->with('app/Models');
6666

6767
$this->artisan('blueprint:erase')
6868
->assertExitCode(0)

tests/Feature/Commands/TraceCommandTest.php

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
use Blueprint\Blueprint;
66
use Blueprint\Builder;
7-
use Blueprint\Commands\TraceCommand;
87
use Blueprint\Tracer;
9-
use Illuminate\Support\Facades\File;
108
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
119
use Symfony\Component\Yaml\Yaml;
1210
use Tests\TestCase;
@@ -40,8 +38,8 @@ public function it_shows_the_number_of_traced_models()
4038
$tracer->shouldReceive('execute')
4139
->with(resolve(Blueprint::class), $this->files, [])
4240
->andReturn([
43-
"Model" => [],
44-
"OtherModel" => [],
41+
'Model' => [],
42+
'OtherModel' => [],
4543
]);
4644

4745
$this->artisan('blueprint:trace')
@@ -53,7 +51,8 @@ public function it_shows_the_number_of_traced_models()
5351
public function relative_class_name_removes_models_namespace()
5452
{
5553
$this->requireFixture('models/comment.php');
56-
$this->requireFixture('models/custom-models-namespace.php');
54+
$this->requireFixture('models/comment-global-namespace.php');
55+
$this->requireFixture('models/tag-custom-models-namespace.php');
5756

5857
$method = new \ReflectionMethod(Tracer::class, 'relativeClassName');
5958
$method->setAccessible(true);
@@ -62,13 +61,13 @@ public function relative_class_name_removes_models_namespace()
6261
config(['blueprint.models_namespace' => '']);
6362

6463
$this->assertEquals($method->invoke(new Tracer(), app('App\Comment')), 'Comment');
65-
$this->assertEquals($method->invoke(new Tracer(), app('App\Models\Tag')), 'Models\Tag');
64+
$this->assertEquals($method->invoke(new Tracer(), app('App\Something\Tag')), 'Something\Tag');
6665

6766
// Models namespace
6867
config(['blueprint.models_namespace' => 'Models']);
6968

70-
$this->assertEquals($method->invoke(new Tracer(), app('App\Comment')), 'Comment');
71-
$this->assertEquals($method->invoke(new Tracer(), app('App\Models\Tag')), 'Tag');
69+
$this->assertEquals($method->invoke(new Tracer(), app('App\Models\Comment')), 'Comment');
70+
$this->assertEquals($method->invoke(new Tracer(), app('App\Something\Tag')), 'Something\Tag');
7271
}
7372

7473
public function it_passes_the_command_path_to_tracer()
@@ -94,18 +93,18 @@ public function it_traces_models_with_differente_namespaces()
9493
$this->requireFixture('models/custom-models-namespace.php');
9594

9695
$expectedBlueprint = Yaml::dump([
97-
'models' => [
98-
'Comment' => [],
99-
'Models\Tag' => [],
100-
],
101-
]);
96+
'models' => [
97+
'Comment' => [],
98+
'Models\Tag' => [],
99+
],
100+
]);
102101

103102
$this->filesystem->shouldReceive('exists')
104-
->with('app')
103+
->with('app/Models')
105104
->andReturnTrue();
106105

107106
$this->filesystem->shouldReceive('allFiles')
108-
->with('app')
107+
->with('app/Models')
109108
->andReturn([
110109
new \SplFileInfo('Comment.php'),
111110
new \SplFileInfo('Models\Tag.php'),

tests/Feature/Generators/ModelGeneratorTest.php

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ public function output_works_for_pascal_case_definition()
111111
->andReturn($this->stub('model.method.stub'))
112112
->twice();
113113

114-
$certificateModel = 'app/Certificate.php';
115-
$certificateTypeModel = 'app/CertificateType.php';
114+
$certificateModel = 'app/Models/Certificate.php';
115+
$certificateTypeModel = 'app/Models/CertificateType.php';
116116

117117
$this->filesystem->expects('exists')
118118
->with(dirname($certificateModel))
@@ -151,15 +151,15 @@ public function output_generates_relationships()
151151
->andReturn($this->stub('model.method.stub'));
152152

153153
$this->filesystem->expects('exists')
154-
->with('app')
154+
->with('app/Models')
155155
->andReturnTrue();
156156
$this->filesystem->expects('put')
157-
->with('app/Subscription.php', $this->fixture('models/model-relationships.php'));
157+
->with('app/Models/Subscription.php', $this->fixture('models/model-relationships.php'));
158158

159159
$tokens = $this->blueprint->parse($this->fixture('drafts/model-relationships.yaml'));
160160
$tree = $this->blueprint->analyze($tokens);
161161

162-
$this->assertEquals(['created' => ['app/Subscription.php']], $this->subject->output($tree));
162+
$this->assertEquals(['created' => ['app/Models/Subscription.php']], $this->subject->output($tree));
163163
}
164164

165165
/**
@@ -181,16 +181,16 @@ public function output_generates_relationships_added_with_full_model_namespace()
181181
->andReturn($this->stub('model.method.stub'));
182182

183183
$this->files->expects('exists')
184-
->with('app')
184+
->with('app/Models')
185185
->andReturnTrue();
186186

187187
$this->files->expects('put')
188-
->with('app/Recurrency.php', $this->fixture('models/model-relationships-with-full-namespace.php'));
188+
->with('app/Models/Recurrency.php', $this->fixture('models/model-relationships-with-full-namespace.php'));
189189

190190
$tokens = $this->blueprint->parse($this->fixture('drafts/model-relationships-with-full-model-namespaces.yaml'));
191191
$tree = $this->blueprint->analyze($tokens);
192192

193-
$this->assertEquals(['created' => ['app/Recurrency.php']], $this->subject->output($tree));
193+
$this->assertEquals(['created' => ['app/Models/Recurrency.php']], $this->subject->output($tree));
194194
}
195195

196196
/**
@@ -212,16 +212,16 @@ public function output_generates_morphone_morphmany_relation_string_when_using_f
212212
->andReturn($this->stub('model.method.stub'));
213213

214214
$this->files->expects('exists')
215-
->with('app')
215+
->with('app/Models')
216216
->andReturnTrue();
217217

218218
$this->files->expects('put')
219-
->with('app/Flag.php', $this->fixture('models/model-relationships-morphone-morphmany-with-fqn.php'));
219+
->with('app/Models/Flag.php', $this->fixture('models/model-relationships-morphone-morphmany-with-fqn.php'));
220220

221221
$tokens = $this->blueprint->parse($this->fixture('drafts/model-relationships-morphone-morphmany-with-fqn.yaml'));
222222
$tree = $this->blueprint->analyze($tokens);
223223

224-
$this->assertEquals(['created' => ['app/Flag.php']], $this->subject->output($tree));
224+
$this->assertEquals(['created' => ['app/Models/Flag.php']], $this->subject->output($tree));
225225
}
226226

227227
/**
@@ -246,27 +246,27 @@ public function output_generates_polymorphic_relationships()
246246
->andReturn($this->stub('model.method.stub'));
247247

248248
$this->filesystem->expects('exists')
249-
->with('app')
249+
->with('app/Models')
250250
->andReturnTrue();
251251
$this->filesystem->expects('put')
252-
->with('app/Post.php', $this->fixture('models/post-polymorphic-relationship.php'));
252+
->with('app/Models/Post.php', $this->fixture('models/post-polymorphic-relationship.php'));
253253

254254
$this->filesystem->expects('exists')
255-
->with('app')
255+
->with('app/Models')
256256
->andReturnTrue();
257257
$this->filesystem->expects('put')
258-
->with('app/User.php', $this->fixture('models/user-polymorphic-relationship.php'));
258+
->with('app/Models/User.php', $this->fixture('models/user-polymorphic-relationship.php'));
259259

260260
$this->filesystem->expects('exists')
261-
->with('app')
261+
->with('app/Models')
262262
->andReturnTrue();
263263
$this->filesystem->expects('put')
264-
->with('app/Image.php', $this->fixture('models/image-polymorphic-relationship.php'));
264+
->with('app/Models/Image.php', $this->fixture('models/image-polymorphic-relationship.php'));
265265

266266
$tokens = $this->blueprint->parse($this->fixture('drafts/polymorphic-relationships.yaml'));
267267
$tree = $this->blueprint->analyze($tokens);
268268

269-
$this->assertEquals(['created' => ['app/Post.php', 'app/User.php', 'app/Image.php']], $this->subject->output($tree));
269+
$this->assertEquals(['created' => ['app/Models/Post.php', 'app/Models/User.php', 'app/Models/Image.php']], $this->subject->output($tree));
270270
}
271271

272272
/**
@@ -292,27 +292,27 @@ public function output_generates_morphtomany_relationship_with_intermediate_mode
292292
->andReturn($this->stub('model.method.stub'));
293293

294294
$this->filesystem->expects('exists')
295-
->with('app')
295+
->with('app/Models')
296296
->andReturnTrue();
297297
$this->filesystem->expects('put')
298-
->with('app/Post.php', $this->fixture('models/post-many-to-many-polymorphic-relationship.php'));
298+
->with('app/Models/Post.php', $this->fixture('models/post-many-to-many-polymorphic-relationship.php'));
299299

300300
$this->filesystem->expects('exists')
301-
->with('app')
301+
->with('app/Models')
302302
->andReturnTrue();
303303
$this->filesystem->expects('put')
304-
->with('app/Video.php', $this->fixture('models/video-many-to-many-polymorphic-relationship.php'));
304+
->with('app/Models/Video.php', $this->fixture('models/video-many-to-many-polymorphic-relationship.php'));
305305

306306
$this->filesystem->expects('exists')
307-
->with('app')
307+
->with('app/Models')
308308
->andReturnTrue();
309309
$this->filesystem->expects('put')
310-
->with('app/Tag.php', $this->fixture('models/tag-many-to-many-polymorphic-relationship.php'));
310+
->with('app/Models/Tag.php', $this->fixture('models/tag-many-to-many-polymorphic-relationship.php'));
311311

312312
$tokens = $this->blueprint->parse($this->fixture('drafts/many-to-many-polymorphic-relationships.yaml'));
313313
$tree = $this->blueprint->analyze($tokens);
314314

315-
$this->assertEquals(['created' => ['app/Post.php', 'app/Video.php', 'app/Tag.php']], $this->subject->output($tree));
315+
$this->assertEquals(['created' => ['app/Models/Post.php', 'app/Models/Video.php', 'app/Models/Tag.php']], $this->subject->output($tree));
316316
}
317317

318318
/**
@@ -337,15 +337,15 @@ public function output_generates_disabled_auto_columns()
337337
->andReturn($this->stub('model.method.stub'));
338338

339339
$this->filesystem->expects('exists')
340-
->with('app')
340+
->with('app/Models')
341341
->andReturnTrue();
342342
$this->filesystem->expects('put')
343-
->with('app/State.php', $this->fixture('models/disable-auto-columns.php'));
343+
->with('app/Models/State.php', $this->fixture('models/disable-auto-columns.php'));
344344

345345
$tokens = $this->blueprint->parse($this->fixture('drafts/disable-auto-columns.yaml'));
346346
$tree = $this->blueprint->analyze($tokens);
347347

348-
$this->assertEquals(['created' => ['app/State.php']], $this->subject->output($tree));
348+
$this->assertEquals(['created' => ['app/Models/State.php']], $this->subject->output($tree));
349349
}
350350

351351
/**
@@ -458,16 +458,16 @@ public function output_generates_models_with_guarded_property_when_config_option
458458
->andReturn($this->stub('model.method.stub'));
459459

460460
$this->filesystem->expects('exists')
461-
->with(dirname('app/Comment.php'))
461+
->with(dirname('app/Models/Comment.php'))
462462
->andReturnTrue();
463463

464464
$this->filesystem->expects('put')
465-
->with('app/Comment.php', $this->fixture('models/model-guarded.php'));
465+
->with('app/Models/Comment.php', $this->fixture('models/model-guarded.php'));
466466

467467
$tokens = $this->blueprint->parse($this->fixture('drafts/model-guarded.yaml'));
468468
$tree = $this->blueprint->analyze($tokens);
469469

470-
$this->assertEquals(['created' => ['app/Comment.php']], $this->subject->output($tree));
470+
$this->assertEquals(['created' => ['app/Models/Comment.php']], $this->subject->output($tree));
471471
}
472472

473473
/**
@@ -523,12 +523,12 @@ public function output_generates_models_with_namespaces_correctly()
523523
*/
524524
public function output_generates_models_with_custom_namespace_correctly()
525525
{
526+
$this->app['config']->set('blueprint.models_namespace', 'MyCustom');
527+
526528
$definition = 'drafts/custom-models-namespace.yaml';
527-
$path = 'app/Models/Tag.php';
529+
$path = 'app/MyCustom/Tag.php';
528530
$model = 'models/custom-models-namespace.php';
529531

530-
$this->app['config']->set('blueprint.models_namespace', 'Models');
531-
532532
$this->filesystem->expects('stub')
533533
->with($this->modelStub)
534534
->andReturn($this->stub($this->modelStub));
@@ -543,7 +543,7 @@ public function output_generates_models_with_custom_namespace_correctly()
543543
->andReturn($this->stub('model.method.stub'));
544544

545545
$this->filesystem->expects('exists')
546-
->with('app/Models')
546+
->with('app/MyCustom')
547547
->andReturnTrue();
548548
$this->filesystem->expects('put')
549549
->with($path, $this->fixture($model));
@@ -576,42 +576,42 @@ public function output_generates_models_with_custom_pivot_columns()
576576
->andReturn($this->stub('model.hidden.stub'));
577577

578578
$this->filesystem->expects('exists')
579-
->with('app')
579+
->with('app/Models')
580580
->andReturnTrue();
581581
$this->filesystem->expects('put')
582-
->with('app/User.php', $this->fixture('models/custom-pivot-table-name.php'));
582+
->with('app/Models/User.php', $this->fixture('models/custom-pivot-table-name.php'));
583583

584584
$tokens = $this->blueprint->parse($this->fixture('drafts/custom-pivot-table-name.yaml'));
585585
$tree = $this->blueprint->analyze($tokens);
586586

587-
$this->assertEquals(['created' => ['app/User.php']], $this->subject->output($tree));
587+
$this->assertEquals(['created' => ['app/Models/User.php']], $this->subject->output($tree));
588588
}
589589

590590
public function modelTreeDataProvider()
591591
{
592592
return [
593-
['drafts/readme-example.yaml', 'app/Post.php', 'models/readme-example.php'],
594-
['drafts/with-timezones.yaml', 'app/Comment.php', 'models/comment.php'],
595-
['drafts/soft-deletes.yaml', 'app/Comment.php', 'models/soft-deletes.php'],
596-
['drafts/relationships.yaml', 'app/Comment.php', 'models/relationships.php'],
597-
['drafts/unconventional.yaml', 'app/Team.php', 'models/unconventional.php'],
598-
['drafts/nested-components.yaml', 'app/Admin/User.php', 'models/nested-components.php'],
599-
['drafts/resource-statements.yaml', 'app/User.php', 'models/resource-statements.php'],
600-
['drafts/all-column-types.yaml', 'app/AllType.php', 'models/all-column-types.php'],
601-
['drafts/alias-relationships.yaml', 'app/Salesman.php', 'models/alias-relationships.php'],
602-
['drafts/return-type-declarations.yaml', 'app/Term.php', 'models/return-type-declarations.php'],
603-
['drafts/uuid-shorthand-invalid-relationship.yaml', 'app/AgeCohort.php', 'models/uuid-shorthand-invalid-relationship.php'],
593+
['drafts/readme-example.yaml', 'app/Models/Post.php', 'models/readme-example.php'],
594+
['drafts/with-timezones.yaml', 'app/Models/Comment.php', 'models/comment.php'],
595+
['drafts/soft-deletes.yaml', 'app/Models/Comment.php', 'models/soft-deletes.php'],
596+
['drafts/relationships.yaml', 'app/Models/Comment.php', 'models/relationships.php'],
597+
['drafts/unconventional.yaml', 'app/Models/Team.php', 'models/unconventional.php'],
598+
['drafts/nested-components.yaml', 'app/Models/Admin/User.php', 'models/nested-components.php'],
599+
['drafts/resource-statements.yaml', 'app/Models/User.php', 'models/resource-statements.php'],
600+
['drafts/all-column-types.yaml', 'app/Models/AllType.php', 'models/all-column-types.php'],
601+
['drafts/alias-relationships.yaml', 'app/Models/Salesman.php', 'models/alias-relationships.php'],
602+
['drafts/return-type-declarations.yaml', 'app/Models/Term.php', 'models/return-type-declarations.php'],
603+
['drafts/uuid-shorthand-invalid-relationship.yaml', 'app/Models/AgeCohort.php', 'models/uuid-shorthand-invalid-relationship.php'],
604604
];
605605
}
606606

607607
public function docBlockModelsDataProvider()
608608
{
609609
return [
610-
['drafts/readme-example.yaml', 'app/Post.php', 'models/readme-example-phpdoc.php'],
611-
['drafts/soft-deletes.yaml', 'app/Comment.php', 'models/soft-deletes-phpdoc.php'],
612-
['drafts/relationships.yaml', 'app/Comment.php', 'models/relationships-phpdoc.php'],
613-
['drafts/disable-auto-columns.yaml', 'app/State.php', 'models/disable-auto-columns-phpdoc.php'],
614-
['drafts/foreign-key-shorthand.yaml', 'app/Comment.php', 'models/foreign-key-shorthand-phpdoc.php'],
610+
['drafts/readme-example.yaml', 'app/Models/Post.php', 'models/readme-example-phpdoc.php'],
611+
['drafts/soft-deletes.yaml', 'app/Models/Comment.php', 'models/soft-deletes-phpdoc.php'],
612+
['drafts/relationships.yaml', 'app/Models/Comment.php', 'models/relationships-phpdoc.php'],
613+
['drafts/disable-auto-columns.yaml', 'app/Models/State.php', 'models/disable-auto-columns-phpdoc.php'],
614+
['drafts/foreign-key-shorthand.yaml', 'app/Models/Comment.php', 'models/foreign-key-shorthand-phpdoc.php'],
615615
];
616616
}
617617
}

tests/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ protected function getEnvironmentSetUp($app)
2525
{
2626
$app['config']->set('blueprint.namespace', 'App');
2727
$app['config']->set('blueprint.controllers_namespace', 'Http\\Controllers');
28-
$app['config']->set('blueprint.models_namespace', '');
28+
$app['config']->set('blueprint.models_namespace', 'Models');
2929
$app['config']->set('blueprint.app_path', 'app');
3030
$app['config']->set('blueprint.generate_phpdocs', false);
3131
$app['config']->set('blueprint.use_constraints', false);

0 commit comments

Comments
 (0)