Skip to content

DateTime Precision is lost when adding date to model factories #24214

Closed
@jamiehd

Description

@jamiehd
  • Laravel Version: v5.6.17
  • PHP Version: 7.1.17

Description:

When using a model factory with a fixed date the microseconds are lost. This means when asserting in a unit test dates do not match when they should.

Steps To Reproduce:

public function some_test() {
        Carbon::setTestNow(new Carbon());
        $t = factory(Model::class)->make(['date_field' => Carbon::now()->addWeeks(2)]);
        $this->assertEquals($t->date_field, Carbon::now()->addWeeks(2));
}

Failed asserting that two DateTime objects are equal.
--- Expected
+++ Actual
@@ @@
-2018-05-28T21:53:00.000000+0000
+2018-05-28T21:53:00.613965+0000

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions