我正在開發一個Laravel 5.3版本並使用Laravel Infyom Generator的項目,它以某種方式生成了所有這些特徵和其他測試文件,如(ApiTest,RepositoryTest等等)。當我嘗試運行PHPUNIT我得到這個錯誤有人可以幫我找出爲什麼我得到這個錯誤?找不到Laravel Trait PHP致命錯誤
PHP Fatal error: Trait 'MakeCustomerTrait' not found in C:\Users\ahmed\dev\gamla\tests\CustomerApiTest.php on line 8
Fatal error: Trait 'MakeCustomerTrait' not found in C:\Users\ahmed\dev\gamla\tests\CustomerApiTest.php on line 8
我想開始爲我的項目進行新測試嗎?我需要刪除這些文件嗎?因爲它一直給我那個錯誤?
MakeCustomerTrait
<?php
use Faker\Factory as Faker;
use App\Models\Customer;
use App\Repositories\CustomerRepository;
trait MakeCustomerTrait
{
/**
* Create fake instance of Customer and save it in database
*
* @param array $customerFields
* @return Customer
*/
public function makeCustomer($customerFields = [])
{
/** @var CustomerRepository $customerRepo */
$customerRepo = App::make(CustomerRepository::class);
$theme = $this->fakeCustomerData($customerFields);
return $customerRepo->create($theme);
}
/**
* Get fake instance of Customer
*
* @param array $customerFields
* @return Customer
*/
public function fakeCustomer($customerFields = [])
{
return new Customer($this->fakeCustomerData($customerFields));
}
/**
* Get fake data of Customer
*
* @param array $postFields
* @return array
*/
public function fakeCustomerData($customerFields = [])
{
$fake = Faker::create();
return array_merge([
'name' => $fake->word,
'address_street' => $fake->word,
'address_zip' => $fake->word,
'address_city' => $fake->word,
'address_country' => $fake->word,
'shipping_address_street' => $fake->word,
'shipping_address_zip' => $fake->word,
'shipping_address_city' => $fake->word,
'shipping_address_country' => $fake->word,
'contact_person_id' => $fake->randomDigitNotNull,
'created_at' => $fake->word,
'updated_at' => $fake->word
], $customerFields);
}
}
使用特徵的完整名稱空間或在文件中的use語句中定義它。對於全局名稱空間,使用它就像'\ MakeCustomerTrait'。 –
你能在這裏寫下來理解你的意思嗎? –
我已更新評論。請看看它是否有效。 –