Bonjour à tous,
J'ai encore un problème avec laravel.
J'utilise des factory pour mes tests
VendorFactory.php
Et le modèle
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 <?php use Faker\Generator as Faker; use App\Models\Vendor; $factory->define(Vendor::class, function (Faker $faker) { return [ 'id_lang' => 'fr', 'id_currency' => 'EUR', 'name' => 'phpunit test name vendor', 'id_site' => '1', 'ref' => '1234', 'file_logo' => '', 'description' => 'description phpunit vendor' ]; });
Dans ma classe de test j'ai
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64 <?php namespace App\Models; use Illuminate\Database\Eloquent\Model; /** * App\Models\Vendor. * * @property int $id_vendor * @property int|null $id_user * @property string $id_lang * @property string $id_currency * @property string $id_site * @property string $name * @property string $ref * @property string $description * @property string|null $file_logo * @property int $status * @property \Carbon\Carbon|null $created_at * @property \Carbon\Carbon|null $updated_at * * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Vendor whereCreatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Vendor whereDescription($value) * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Vendor whereFileLogo($value) * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Vendor whereIdCurrency($value) * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Vendor whereIdLang($value) * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Vendor whereIdSite($value) * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Vendor whereIdUser($value) * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Vendor whereIdVendor($value) * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Vendor whereName($value) * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Vendor whereRef($value) * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Vendor whereStatus($value) * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Vendor whereUpdatedAt($value) * @mixin \Eloquent * * @property string|null $country_code * @property string|null $category * * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Vendor whereCategory($value) * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Vendor whereCountryCode($value) * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Vendor newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Vendor newQuery() * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Vendor query() */ class Vendor extends Model { const STATUS_INACTIVE = 0; const STATUS_ACTIVE = 1; protected $table = 'vendor'; protected $primaryKey = 'id_vendor'; protected $fillable = [ 'id_user', 'id_lang', 'id_currency', 'id_site', 'name', 'ref', 'description', ]; }
J'ai comme retour en console avec phpunit
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 // init factory for database $user = factory(User::class)->create(); $this->vendor = factory(Vendor::class)->create([ $user->id_user ]); die;
Le problème c'est que je peux faire un create
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 Illuminate\Database\QueryException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'updated_at' in 'field list' (SQL: insert into `VC_vendor` (`id_lang`, `id_currency`, `name`, `id_site`, `ref`, `file_logo`, `description`, `id_user`, `updated_at`, `created_at`) values (fr, EUR, phpunit test name vendor, 1, 1234, , description phpunit vendor, 60, 2019-04-25 13:36:08, 2019-04-25 13:36:08))
Mais avec le factory il ne supporte pas le create et update comment faire en sorte qui les ignores?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 $vendor = Vendor::create([ 'id_user' => $user->id_user, 'id_lang' => $r_vendor['id_lang'], 'id_currency' => $r_vendor['id_currency'], 'id_site' => $r_vendor['id_site'], 'name' => $r_vendor['name'], 'ref' => $r_vendor['ref'], 'description' => (isset($r_vendor['description'])) ? $r_vendor['description'] : '', ]);
Partager