Symfony Testing - ClockMock / DateTime

I am looking for help in creating a complex test for our application based on the JSON API.

Short problem scenario:

  • Check the creation of a temporary entity (for comparison)
  • EntityManagerMock is configured to wait persist ($ temporEntity)
  • Check real call method with some parameters
  • Create an object and try to save
  • The test fails because the change in time within 1 second

enter image description here

We tried to use ClockMock , but it only works for the class where / for the namespace was called. Our method is in a different namespace, and the entity is created in the following.

PHP \DateTime ClockMock / ( ). ClockMock Symfony, : -/.

- ? ( - get_declared_class() clockMock:: register - 15 000 : -/.

!

+4
1

ClockMock new \DateTime(), PHP, .

:

, , new DateTime(), DateTime::createFromFormat('U', time()), mocked time().

, , : DateTime named-constructor .

+4

Source: https://habr.com/ru/post/1671395/


All Articles