我正在爲我們的應用程序編寫phpUnit測試,所以爲此我編寫了一個模型工廠,之後當我嘗試運行單元測試時,出現如下錯誤:「InvalidArgumentException:未知格式化程序'publicId'「。我在Model工廠中聲明瞭表格的所有列名稱。是否需要提及工廠中的所有列?InvalidArgumentException:編寫單元測試時未知的格式化程序
ModelFactory.php
$factory->define(App\Campaign::class, function (Faker\Generator $faker) {
return [
'public_id' => $faker->publicId,
'client_id' => $faker->clientID,
'name' => $faker->name,
'criteria_age' => $faker->criteriaAge,
'criteria_state' => $faker->criteriaState,
'criteria_postcode' => $faker->criteriaPostcode,
'dncr_required' => $faker->dncrRequired,
'criteria_state' => $faker->criteriaState,
'active' => $faker->active,
'method' => $faker->method,
'server_parameters' => $faker->serverParameters,
'parameter_mapping' => $faker->parameterMapping,
];
});
\測試\單位\運動\ CampaignTest.php
namespace Tests\Unit\Campaign;
use App\Campaign;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class CampaignTest extends TestCase
{
use DatabaseTransactions;
public function testCampaignCreation()
{
factory(\App\Campaign::class)->create(['name' => 'tinku']);
$this->seeInDatabase('campaigns', ['name' => 'tinku']);
}
}
運行後 「PHPUnit測試/單位/運動/ CampaignTest.php」 我得到這個錯誤「 InvalidArgumentException:未知格式化程序'publicId'「。我是Laravel的新手我知道有一個創建工廠的程序,但我無法弄清楚。希望有人幫助。謝謝。