Skip to content

Commit be5f383

Browse files
authored
Stubs helper (#333)
1 parent fb5af36 commit be5f383

14 files changed

+144
-137
lines changed

tests/Feature/Generator/ControllerGeneratorTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function output_writes_nothing_for_empty_tree()
4040
{
4141
$this->files->expects('stub')
4242
->with('controller.class.stub')
43-
->andReturn(file_get_contents('stubs/controller.class.stub'));
43+
->andReturn($this->stub('controller.class.stub'));
4444

4545
$this->files->shouldNotHaveReceived('put');
4646

@@ -55,10 +55,10 @@ public function output_writes_migration_for_controller_tree($definition, $path,
5555
{
5656
$this->files->expects('stub')
5757
->with('controller.class.stub')
58-
->andReturn(file_get_contents('stubs/controller.class.stub'));
58+
->andReturn($this->stub('controller.class.stub'));
5959
$this->files->expects('stub')
6060
->with('controller.method.stub')
61-
->andReturn(file_get_contents('stubs/controller.method.stub'));
61+
->andReturn($this->stub('controller.method.stub'));
6262

6363
$this->files->expects('exists')
6464
->with(dirname($path))
@@ -84,10 +84,10 @@ public function output_generates_controllers_with_models_with_custom_namespace_c
8484

8585
$this->files->expects('stub')
8686
->with('controller.class.stub')
87-
->andReturn(file_get_contents('stubs/controller.class.stub'));
87+
->andReturn($this->stub('controller.class.stub'));
8888
$this->files->expects('stub')
8989
->with('controller.method.stub')
90-
->andReturn(file_get_contents('stubs/controller.method.stub'));
90+
->andReturn($this->stub('controller.method.stub'));
9191

9292
$this->files->expects('exists')
9393
->with(dirname($path))
@@ -108,10 +108,10 @@ public function output_works_for_pascal_case_definition()
108108
{
109109
$this->files->expects('stub')
110110
->with('controller.class.stub')
111-
->andReturn(file_get_contents('stubs/controller.class.stub'));
111+
->andReturn($this->stub('controller.class.stub'));
112112
$this->files->expects('stub')
113113
->with('controller.method.stub')
114-
->andReturn(file_get_contents('stubs/controller.method.stub'))
114+
->andReturn($this->stub('controller.method.stub'))
115115
->twice();
116116

117117
$certificateController = 'app/Http/Controllers/CertificateController.php';
@@ -145,10 +145,10 @@ public function output_respects_configuration()
145145

146146
$this->files->expects('stub')
147147
->with('controller.class.stub')
148-
->andReturn(file_get_contents('stubs/controller.class.stub'));
148+
->andReturn($this->stub('controller.class.stub'));
149149
$this->files->expects('stub')
150150
->with('controller.method.stub')
151-
->andReturn(file_get_contents('stubs/controller.method.stub'));
151+
->andReturn($this->stub('controller.method.stub'));
152152

153153
$this->files->expects('exists')
154154
->with('src/path/Other/Http')

tests/Feature/Generator/FactoryGeneratorTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function output_writes_nothing_for_empty_tree()
3838
{
3939
$this->files->expects('stub')
4040
->with('factory.stub')
41-
->andReturn(file_get_contents('stubs/factory.stub'));
41+
->andReturn($this->stub('factory.stub'));
4242

4343
$this->files->shouldNotHaveReceived('put');
4444

@@ -53,7 +53,7 @@ public function output_writes_factory_for_model_tree($definition, $path, $factor
5353
{
5454
$this->files->expects('stub')
5555
->with('factory.stub')
56-
->andReturn(file_get_contents('stubs/factory.stub'));
56+
->andReturn($this->stub('factory.stub'));
5757

5858
$this->files->expects('exists')
5959
->with('database/factories')
@@ -77,7 +77,7 @@ public function output_ignores_nullables_if_fake_nullables_configuration_is_set_
7777

7878
$this->files->expects('stub')
7979
->with('factory.stub')
80-
->andReturn(file_get_contents('stubs/factory.stub'));
80+
->andReturn($this->stub('factory.stub'));
8181

8282
$this->files->expects('exists')
8383
->with('database/factories')
@@ -102,7 +102,7 @@ public function output_respects_configuration()
102102

103103
$this->files->expects('stub')
104104
->with('factory.stub')
105-
->andReturn(file_get_contents('stubs/factory.stub'));
105+
->andReturn($this->stub('factory.stub'));
106106

107107
$this->files->expects('exists')
108108
->with('database/factories')
@@ -124,7 +124,7 @@ public function output_creates_directory_for_nested_components()
124124
{
125125
$this->files->expects('stub')
126126
->with('factory.stub')
127-
->andReturn(file_get_contents('stubs/factory.stub'));
127+
->andReturn($this->stub('factory.stub'));
128128

129129
$this->files->expects('exists')
130130
->with('database/factories/Admin')

tests/Feature/Generator/MigrationGeneratorTest.php

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function output_writes_nothing_for_empty_tree()
4141
{
4242
$this->files->expects('stub')
4343
->with('migration.stub')
44-
->andReturn(file_get_contents('stubs/migration.stub'));
44+
->andReturn($this->stub('migration.stub'));
4545

4646
$this->files->shouldNotHaveReceived('put');
4747

@@ -56,7 +56,7 @@ public function output_writes_migration_for_model_tree($definition, $path, $migr
5656
{
5757
$this->files->expects('stub')
5858
->with('migration.stub')
59-
->andReturn(file_get_contents('stubs/migration.stub'));
59+
->andReturn($this->stub('migration.stub'));
6060

6161
$now = Carbon::now();
6262
Carbon::setTestNow($now);
@@ -84,7 +84,7 @@ public function output_updates_migration_for_model_tree($definition, $path, $mig
8484
{
8585
$this->files->expects('stub')
8686
->with('migration.stub')
87-
->andReturn(file_get_contents('stubs/migration.stub'));
87+
->andReturn($this->stub('migration.stub'));
8888

8989
$yday = Carbon::yesterday();
9090

@@ -116,7 +116,7 @@ public function output_writes_migration_for_foreign_shorthand()
116116
{
117117
$this->files->expects('stub')
118118
->with('migration.stub')
119-
->andReturn(file_get_contents('stubs/migration.stub'));
119+
->andReturn($this->stub('migration.stub'));
120120

121121
$now = Carbon::now();
122122
Carbon::setTestNow($now);
@@ -141,7 +141,7 @@ public function output_uses_past_timestamp_for_multiple_migrations()
141141
{
142142
$this->files->expects('stub')
143143
->with('migration.stub')
144-
->andReturn(file_get_contents('stubs/migration.stub'));
144+
->andReturn($this->stub('migration.stub'));
145145

146146
$now = Carbon::now();
147147
Carbon::setTestNow($now);
@@ -175,7 +175,7 @@ public function output_uses_proper_data_type_for_id_columns_in_laravel6()
175175

176176
$this->files->expects('stub')
177177
->with('migration.stub')
178-
->andReturn(file_get_contents('stubs/migration.stub'));
178+
->andReturn($this->stub('migration.stub'));
179179

180180
$now = Carbon::now();
181181
Carbon::setTestNow($now);
@@ -202,7 +202,7 @@ public function output_creates_constraints_for_unconventional_foreign_reference_
202202

203203
$this->files->expects('stub')
204204
->with('migration.stub')
205-
->andReturn(file_get_contents('stubs/migration.stub'));
205+
->andReturn($this->stub('migration.stub'));
206206

207207
$now = Carbon::now();
208208
Carbon::setTestNow($now);
@@ -235,7 +235,7 @@ public function output_creates_constraints_for_unconventional_foreign_reference_
235235

236236
$this->files->expects('stub')
237237
->with('migration.stub')
238-
->andReturn(file_get_contents('stubs/migration.stub'));
238+
->andReturn($this->stub('migration.stub'));
239239

240240
$now = Carbon::now();
241241
Carbon::setTestNow($now);
@@ -260,7 +260,7 @@ public function output_also_creates_pivot_table_migration()
260260
{
261261
$this->files->expects('stub')
262262
->with('migration.stub')
263-
->andReturn(file_get_contents('stubs/migration.stub'));
263+
->andReturn($this->stub('migration.stub'));
264264

265265
$now = Carbon::now();
266266
Carbon::setTestNow($now);
@@ -288,7 +288,7 @@ public function output_also_updates_pivot_table_migration()
288288
{
289289
$this->files->expects('stub')
290290
->with('migration.stub')
291-
->andReturn(file_get_contents('stubs/migration.stub'));
291+
->andReturn($this->stub('migration.stub'));
292292

293293
$yday = Carbon::yesterday();
294294

@@ -330,7 +330,7 @@ public function output_also_creates_pivot_table_migration_laravel6()
330330

331331
$this->files->expects('stub')
332332
->with('migration.stub')
333-
->andReturn(file_get_contents('stubs/migration.stub'));
333+
->andReturn($this->stub('migration.stub'));
334334

335335
$now = Carbon::now();
336336
Carbon::setTestNow($now);
@@ -361,7 +361,7 @@ public function output_also_creates_constraints_for_pivot_table_migration()
361361

362362
$this->files->expects('stub')
363363
->with('migration.stub')
364-
->andReturn(file_get_contents('stubs/migration.stub'));
364+
->andReturn($this->stub('migration.stub'));
365365

366366
$now = Carbon::now();
367367
Carbon::setTestNow($now);
@@ -398,7 +398,7 @@ public function output_also_creates_constraints_for_pivot_table_migration_larave
398398

399399
$this->files->expects('stub')
400400
->with('migration.stub')
401-
->andReturn(file_get_contents('stubs/migration.stub'));
401+
->andReturn($this->stub('migration.stub'));
402402

403403
$now = Carbon::now();
404404
Carbon::setTestNow($now);
@@ -426,7 +426,7 @@ public function output_does_not_duplicate_pivot_table_migration()
426426
{
427427
$this->files->expects('stub')
428428
->with('migration.stub')
429-
->andReturn(file_get_contents('stubs/migration.stub'));
429+
->andReturn($this->stub('migration.stub'));
430430

431431
$now = Carbon::now();
432432
Carbon::setTestNow($now);
@@ -463,7 +463,7 @@ public function output_does_not_duplicate_pivot_table_migration_laravel6()
463463

464464
$this->files->expects('stub')
465465
->with('migration.stub')
466-
->andReturn(file_get_contents('stubs/migration.stub'));
466+
->andReturn($this->stub('migration.stub'));
467467

468468
$now = Carbon::now();
469469
Carbon::setTestNow($now);
@@ -494,7 +494,7 @@ public function output_also_creates_pivot_table_migration_with_custom_name()
494494
{
495495
$this->files->expects('stub')
496496
->with('migration.stub')
497-
->andReturn(file_get_contents('stubs/migration.stub'));
497+
->andReturn($this->stub('migration.stub'));
498498

499499
$now = Carbon::now();
500500
Carbon::setTestNow($now);
@@ -528,7 +528,7 @@ public function output_also_creates_pivot_table_migration_with_custom_name_larav
528528

529529
$this->files->expects('stub')
530530
->with('migration.stub')
531-
->andReturn(file_get_contents('stubs/migration.stub'));
531+
->andReturn($this->stub('migration.stub'));
532532

533533
$now = Carbon::now();
534534
Carbon::setTestNow($now);
@@ -558,7 +558,7 @@ public function output_creates_foreign_keys_with_nullable_chained_correctly()
558558

559559
$this->files->expects('stub')
560560
->with('migration.stub')
561-
->andReturn(file_get_contents('stubs/migration.stub'));
561+
->andReturn($this->stub('migration.stub'));
562562

563563
$now = Carbon::now();
564564
Carbon::setTestNow($now);
@@ -592,7 +592,7 @@ public function output_creates_foreign_keys_with_nullable_chained_correctly_lara
592592

593593
$this->files->expects('stub')
594594
->with('migration.stub')
595-
->andReturn(file_get_contents('stubs/migration.stub'));
595+
->andReturn($this->stub('migration.stub'));
596596

597597
$now = Carbon::now();
598598
Carbon::setTestNow($now);
@@ -618,7 +618,7 @@ public function output_creates_foreign_keys_with_on_delete()
618618
{
619619
$this->files->expects('stub')
620620
->with('migration.stub')
621-
->andReturn(file_get_contents('stubs/migration.stub'));
621+
->andReturn($this->stub('migration.stub'));
622622

623623
$now = Carbon::now();
624624
Carbon::setTestNow($now);
@@ -650,7 +650,7 @@ public function output_creates_foreign_keys_with_on_delete_laravel6()
650650

651651
$this->files->expects('stub')
652652
->with('migration.stub')
653-
->andReturn(file_get_contents('stubs/migration.stub'));
653+
->andReturn($this->stub('migration.stub'));
654654

655655
$now = Carbon::now();
656656
Carbon::setTestNow($now);
@@ -676,7 +676,7 @@ public function output_works_with_polymorphic_relationships()
676676
{
677677
$this->files->expects('stub')
678678
->with('migration.stub')
679-
->andReturn(file_get_contents('stubs/migration.stub'));
679+
->andReturn($this->stub('migration.stub'));
680680

681681
$now = Carbon::now();
682682
Carbon::setTestNow($now);
@@ -713,7 +713,7 @@ public function output_works_with_polymorphic_relationships_laravel6()
713713

714714
$this->files->expects('stub')
715715
->with('migration.stub')
716-
->andReturn(file_get_contents('stubs/migration.stub'));
716+
->andReturn($this->stub('migration.stub'));
717717

718718
$now = Carbon::now();
719719
Carbon::setTestNow($now);

0 commit comments

Comments
 (0)