Skip to content
Advertisement

Carbon object in mockery php test

Thank you for your time. I have stripped out the fluff from the code/test.

The furthest I have got with this is that setAttribute requires two strings as param´s, but i am passing in an Carbon object, which Mockery as a test suite does not like? Is this the case, is there a better way to test dates with Mockery/PHPUnit? Other tests and code works, it seems like it´s only this test that is an issue.

Error

JavaScript

Bit of the test

JavaScript

Bit of the code

JavaScript

Advertisement

Answer

It’s not clear from your example who’s calling setAttribute. But I guess that you are probably using magic setters.

The reason why your expectation is failing is because you are comparing two different objects. From the docs:

JavaScript

You can loosen the comparison by using the equalTo hamcrest matcher:

JavaScript

You will still get into trouble because the time will always be slightly off. Fortunately, Carbon provides a way to fix “now” for testing purposes. You just have to set it in your test case:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement