Testing Laravel 8-使用“的PHPUnit测试问题;日期变异因子“;和骗子

Testing Laravel 8-使用“的PHPUnit测试问题;日期变异因子“;和骗子,testing,phpunit,faker,mutators,laravel-8,Testing,Phpunit,Faker,Mutators,Laravel 8,我注意到在模型中设置受保护日期数组中的日期变量字段,在伪造者中使用的日期格式被修改为碳对象,并且不返回在伪造者中设置的格式;这正常吗 为了解释这个问题,该模型类似于: <?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Factories\HasFactory; class Post extends Model { use Ha

我注意到在模型中设置
受保护日期
数组中的日期变量字段,在
伪造者
中使用的日期格式被修改为
对象,并且不返回在
伪造者
中设置的格式;这正常吗

为了解释这个问题,该模型类似于:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class Post extends Model
{
    use HasFactory;

    protected $dates = [
        'seen_at'
    ];

    // other code here...
}
测试
类为:

<?php
namespace App\Tests\Feature;

use Tests\TestCase;
use App\Factories\PostFactory;

class PostControllerTest extends TestCase
{
    public function setUp(): void
    {
        parent::setUp();

        $post = PostFactory::new()->make();
        dd($post->seen_at);

        // other code here....
    }
}
日期
伪造者
中指定的格式不匹配,该格式应为
'Y-m-d\TH:i:s.vP'
;但是是
1977-03-2503:40:14.0+00:00

如果我从
protected$dates
数组中删除
seen_at
,再次运行测试,则输出正确:

"1970-02-10T03:13:34.000+00:00"
另一种想法是,如果我
dd()
整个模型都是从
Faker
生成的,带有
protected$dates
,其中包含
seen\u at

class PostControllerTest extends TestCase
{
    public function setUp(): void
    {
        parent::setUp();

        $post = PostFactory::new()->make();
        dd($post);

        // other code here....
    }
}
输出包含正确的日期:

App\Models\Post {#2399
  #table: "post"
  . . .
  #attributes: array:39 [
    "number" => 8
    "seen_at" => "1970-02-10T03:13:34.000+00:00"
    "quality" => "AB"
  ]
  . . .
  #guarded: array:1 [
    0 => "*"
  ]
}
这种行为正常吗?如果“是”,如何返回正确的日期格式

多谢各位

class PostControllerTest extends TestCase
{
    public function setUp(): void
    {
        parent::setUp();

        $post = PostFactory::new()->make();
        dd($post);

        // other code here....
    }
}
App\Models\Post {#2399
  #table: "post"
  . . .
  #attributes: array:39 [
    "number" => 8
    "seen_at" => "1970-02-10T03:13:34.000+00:00"
    "quality" => "AB"
  ]
  . . .
  #guarded: array:1 [
    0 => "*"
  ]
}