Closed imjalpreet closed 8 years ago
@oparoz I have added the test for postCreate method. Please review it.
It's a good start :). I'm going to add some comments in-line
@oparoz I am sorry I did not see your reply. I have done the required changes.
Thinking about the failure tests that need to be added, I can see that there are some checks missing in the code.
If the metadata is null/empty, then we shouldn't try to store it, but return an error and there should be a test for that.
At some point we may want to use try-catch and exceptions here, but that's for later.
@oparoz Yeah, it is working now. I don't know earlier when I did the same thing it was giving some error.
Cool, so now you can write the 2 additional tests :)
@oparoz I am not able to figure out how to test when metadata does not get inserted. Can you give an example case that I should test?
Looking at your code, store
always returns true, so you're not going to be able to tell when there is a failure.
So, the 1st thing to do would be to fix that method. You should probably test $entity
to make sure it has an ID and if not return false.
@oparoz Actually, I have changed it on my local machine already but I was not able to figure out how do I test it?
You return a mocked entity without an ID. Contact me on IRC if you don't see how this is done or if you know it doesn't work :)
@oparoz The problem is the ID is added in the insert method of the Mapper class and I can't control it. So, the ID is automatically added if the insertion is successful.
Sure, but you should be able to control what Mapper->insert
returns by mocking it.
@oparoz Okay, I will try mocking it.
@oparoz I have added the test for dbManager error. Please have a look.
Works for me :)
The unit test for postCreate method in ImageHooks has been added.