我在Laravel 5.1工作,我不斷收到嘗試運行測試時此錯誤:收到錯誤:InvalidArgumentException:無法與名稱查找廠[默認] [應用用戶]
invalidArgumentException:無法與名廠找到[默認] [應用\用戶]
這裏是我的測試代碼:
namespace tests\unit;
class UserTest extends \TestCase
{
public function testTheUser() {
$user = factory(\App\User::class)->make();
$this->assertTrue(true,'Test Something');
}
}
這裏是我的ModelFactory.php
它位於數據庫/事實法制前提/ ModelFactory.php
$factory->define(\App\User::class, function (Faker\Generator $faker) {
static $password;
return [
'name' => $faker->name,
'email' => $faker->unique()->safeEmail,
'password' => $password ?: $password = bcrypt('secret'),
'remember_token' => str_random(10),
];
});
只是要徹底,這是什麼樣的TestCase的樣子:
class TestCase extends Illuminate\Foundation\Testing\TestCase {
protected $baseUrl = 'http://localhost';
/**
* Creates the application.
*
* @return \Illuminate\Foundation\Application
*/
public function createApplication()
{
$app = require __DIR__.'/../bootstrap/app.php';
$app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();
return $app;
}
}
它似乎並沒有被加載ModelFactory.php代碼。我在文件中添加了一個dd()語句來查看它是否會停止,並且我得到相同的錯誤。我也在Eloquent \ Factory文件中加入了一個,它甚至沒有調用load函數將這些文件包含在工廠文件夾中。
我甚至用下面的命令來運行PHP的工匠修補匠:
>>> factory('\App\User')->make();
InvalidArgumentException與消息「無法找到工廠的名字[默認] [\軟件\用戶。」
和我得到相同的錯誤。不知道在哪裏看這一點。任何幫助,將不勝感激。謝謝!
看看這個https://laracasts.com/discuss/channels/testing/invalidargumentexception-unable-to-locate-factory-with-name-default-appmodelsdomain – usrNotFound
謝謝,我看了很多。我有我的ModelFactory.php在數據庫/工廠/文件夾。它似乎沒有試圖從那裏加載文件。我還在一個不同的項目上安裝了Laravel 5.3,它在那裏工作的很好。 – Joe