31
31
use Illuminate \Foundation \Application ;
32
32
use Illuminate \Http \Request ;
33
33
use Illuminate \Routing \Route ;
34
+ use Illuminate \Routing \Router ;
34
35
use Illuminate \Support \Collection ;
35
36
use Illuminate \Support \ViewErrorBag ;
36
37
use ReflectionClass ;
@@ -462,14 +463,16 @@ public function callArtisan(string $command, $parameters = [], OutputInterface $
462
463
* ```
463
464
*
464
465
* @param string $routeName
465
- * @param array $params
466
+ * @param mixed $params
466
467
*/
467
- public function amOnRoute (string $ routeName , array $ params = []): void
468
+ public function amOnRoute (string $ routeName , $ params = []): void
468
469
{
469
470
$ route = $ this ->getRouteByName ($ routeName );
470
471
471
472
$ absolute = !is_null ($ route ->domain ());
472
- $ url = $ this ->app ['url ' ]->route ($ routeName , $ params , $ absolute );
473
+ /** @var UrlGenerator $urlGenerator */
474
+ $ urlGenerator = $ this ->app ['url ' ];
475
+ $ url = $ urlGenerator ->route ($ routeName , $ params , $ absolute );
473
476
$ this ->amOnPage ($ url );
474
477
}
475
478
@@ -562,7 +565,10 @@ public function seeCurrentActionIs(string $action): void
562
565
*/
563
566
protected function getRouteByName (string $ routeName )
564
567
{
565
- if (!$ route = $ this ->app ['routes ' ]->getByName ($ routeName )) {
568
+ /** @var Router $router */
569
+ $ router = $ this ->app ['router ' ];
570
+ $ routes = $ router ->getRoutes ();
571
+ if (!$ route = $ routes ->getByName ($ routeName )) {
566
572
$ this ->fail ("Route with name ' $ routeName' does not exist " );
567
573
}
568
574
@@ -1126,17 +1132,16 @@ protected function getQueryBuilderFromTable(string $table)
1126
1132
}
1127
1133
1128
1134
/**
1129
- * Use Laravel's model factory to create a model.
1130
- * Can only be used with Laravel 5.1 and later.
1135
+ * Use Laravel model factory to create a model.
1131
1136
*
1132
1137
* ``` php
1133
1138
* <?php
1134
- * $I->have('App\User');
1135
- * $I->have('App\User', ['name' => 'John Doe']);
1136
- * $I->have('App\User', [], 'admin');
1139
+ * $I->have('App\Models\ User');
1140
+ * $I->have('App\Models\ User', ['name' => 'John Doe']);
1141
+ * $I->have('App\Models\ User', [], 'admin');
1137
1142
* ```
1138
1143
*
1139
- * @see http ://laravel.com/docs/5.1/ testing#model -factories
1144
+ * @see https ://laravel.com/docs/6.x/database- testing#using -factories
1140
1145
* @param string $model
1141
1146
* @param array $attributes
1142
1147
* @param string $name
@@ -1146,31 +1151,30 @@ protected function getQueryBuilderFromTable(string $table)
1146
1151
public function have (string $ model , array $ attributes = [], string $ name = 'default ' )
1147
1152
{
1148
1153
try {
1149
- $ result = $ this ->modelFactory ($ model , $ name )->create ($ attributes );
1154
+ $ model = $ this ->modelFactory ($ model , $ name )->create ($ attributes );
1150
1155
1151
- // Since Laravel 5.4 the model factory returns a collection instead of a single object
1152
- if ($ result instanceof Collection) {
1153
- $ result = $ result [0 ];
1156
+ // In Laravel 6 the model factory returns a collection instead of a single object
1157
+ if ($ model instanceof Collection) {
1158
+ $ model = $ model [0 ];
1154
1159
}
1155
1160
1156
- return $ result ;
1161
+ return $ model ;
1157
1162
} catch (Exception $ e ) {
1158
- $ this ->fail (" Could not create model: \n\n" . get_class ($ e ) . " \n\n" . $ e ->getMessage ());
1163
+ $ this ->fail (' Could not create model: \n\n ' . get_class ($ e ) . ' \n\n ' . $ e ->getMessage ());
1159
1164
}
1160
1165
}
1161
1166
1162
1167
/**
1163
- * Use Laravel's model factory to create multiple models.
1164
- * Can only be used with Laravel 5.1 and later.
1168
+ * Use Laravel model factory to create multiple models.
1165
1169
*
1166
1170
* ``` php
1167
1171
* <?php
1168
- * $I->haveMultiple('App\User', 10);
1169
- * $I->haveMultiple('App\User', 10, ['name' => 'John Doe']);
1170
- * $I->haveMultiple('App\User', 10, [], 'admin');
1172
+ * $I->haveMultiple('App\Models\ User', 10);
1173
+ * $I->haveMultiple('App\Models\ User', 10, ['name' => 'John Doe']);
1174
+ * $I->haveMultiple('App\Models\ User', 10, [], 'admin');
1171
1175
* ```
1172
1176
*
1173
- * @see http ://laravel.com/docs/5.1/ testing#model -factories
1177
+ * @see https ://laravel.com/docs/6.x/database- testing#using -factories
1174
1178
* @param string $model
1175
1179
* @param int $times
1176
1180
* @param array $attributes
@@ -1188,17 +1192,16 @@ public function haveMultiple(string $model, int $times, array $attributes = [],
1188
1192
}
1189
1193
1190
1194
/**
1191
- * Use Laravel's model factory to make a model instance.
1192
- * Can only be used with Laravel 5.1 and later.
1195
+ * Use Laravel model factory to make a model instance.
1193
1196
*
1194
1197
* ``` php
1195
1198
* <?php
1196
- * $I->make('App\User');
1197
- * $I->make('App\User', ['name' => 'John Doe']);
1198
- * $I->make('App\User', [], 'admin');
1199
+ * $I->make('App\Models\ User');
1200
+ * $I->make('App\Models\ User', ['name' => 'John Doe']);
1201
+ * $I->make('App\Models\ User', [], 'admin');
1199
1202
* ```
1200
1203
*
1201
- * @see http ://laravel.com/docs/5.1/ testing#model -factories
1204
+ * @see https ://laravel.com/docs/6.x/database- testing#using -factories
1202
1205
* @param string $model
1203
1206
* @param array $attributes
1204
1207
* @param string $name
@@ -1215,17 +1218,16 @@ public function make(string $model, array $attributes = [], string $name = 'defa
1215
1218
}
1216
1219
1217
1220
/**
1218
- * Use Laravel's model factory to make multiple model instances.
1219
- * Can only be used with Laravel 5.1 and later.
1221
+ * Use Laravel model factory to make multiple model instances.
1220
1222
*
1221
1223
* ``` php
1222
1224
* <?php
1223
- * $I->makeMultiple('App\User', 10);
1224
- * $I->makeMultiple('App\User', 10, ['name' => 'John Doe']);
1225
- * $I->makeMultiple('App\User', 10, [], 'admin');
1225
+ * $I->makeMultiple('App\Models\ User', 10);
1226
+ * $I->makeMultiple('App\Models\ User', 10, ['name' => 'John Doe']);
1227
+ * $I->makeMultiple('App\Models\ User', 10, [], 'admin');
1226
1228
* ```
1227
1229
*
1228
- * @see http ://laravel.com/docs/5.1/ testing#model -factories
1230
+ * @see https ://laravel.com/docs/6.x/database- testing#using -factories
1229
1231
* @param string $model
1230
1232
* @param int $times
1231
1233
* @param array $attributes
@@ -1246,23 +1248,15 @@ public function makeMultiple(string $model, int $times, array $attributes = [],
1246
1248
* @param string $model
1247
1249
* @param string $name
1248
1250
* @param int $times
1249
- * @return FactoryBuilder
1250
- * @throws ModuleException
1251
+ * @return FactoryBuilder|\Illuminate\Database\Eloquent\Factories\Factory
1251
1252
*/
1252
- protected function modelFactory (string $ model , string $ name , $ times = 1 ): FactoryBuilder
1253
+ protected function modelFactory (string $ model , string $ name , $ times = 1 )
1253
1254
{
1254
- if (! function_exists ('factory ' )) {
1255
- throw new ModuleException ($ this , 'The factory() method does not exist. ' .
1256
- 'This functionality relies on Laravel model factories, which were introduced in Laravel 5.1. ' );
1257
- }
1258
-
1259
1255
if (version_compare (Application::VERSION , '7.0.0 ' , '< ' )) {
1260
- $ factory = factory ($ model , $ name , $ times );
1261
- } else {
1262
- $ factory = factory ($ model , $ times );
1256
+ return factory ($ model , $ name , $ times );
1263
1257
}
1264
1258
1265
- return $ factory ;
1259
+ return $ model :: factory ()-> count ( $ times ) ;
1266
1260
}
1267
1261
1268
1262
/**
0 commit comments