I'm a professional PHP, Python and Javascript developer from the UK. I've worked with Django, Laravel, and React, among others. I also maintain a legacy Zend 1 application.
This particular use case was a test for a read-only Doctrine entity. The ID is something that would never be set manually, only by getting it back from a Doctrine repository. As such, there was no reason to mock anything, and no reason to create a setter method just for test purposes.
To be fair, this is very much an edge case, though.
I'm a professional PHP, Python and Javascript developer from the UK. I've worked with Django, Laravel, and React, among others. I also maintain a legacy Zend 1 application.
Well, this is my own project I'm testing. If the property name does change in future either I'll know and will remember to update it in the test, or I'll forget and the tests will break in Travis CI, reminding me to fix them. Given that this is a Doctrine entity and so it expects the property in question to be called $id, that's fairly unlikely.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Mocks aren't useful in this case.
This particular use case was a test for a read-only Doctrine entity. The ID is something that would never be set manually, only by getting it back from a Doctrine repository. As such, there was no reason to mock anything, and no reason to create a setter method just for test purposes.
To be fair, this is very much an edge case, though.
How do you get the property name? It is private and may change at any time in subsequent versions.
Well, this is my own project I'm testing. If the property name does change in future either I'll know and will remember to update it in the test, or I'll forget and the tests will break in Travis CI, reminding me to fix them. Given that this is a Doctrine entity and so it expects the property in question to be called
$id
, that's fairly unlikely.