interfasys / mediametadata

A cloud application which provides CRUD access to the metadata stored in images
GNU Affero General Public License v3.0
5 stars 1 forks source link

Issue #27: Test for postCreate method added #30

Closed imjalpreet closed 8 years ago

imjalpreet commented 8 years ago

The unit test for postCreate method in ImageHooks has been added.

imjalpreet commented 8 years ago

@oparoz I have added the test for postCreate method. Please review it.

oparoz commented 8 years ago

It's a good start :). I'm going to add some comments in-line

imjalpreet commented 8 years ago

@oparoz I am sorry I did not see your reply. I have done the required changes.

oparoz commented 8 years ago

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.

imjalpreet commented 8 years ago

@oparoz Yeah, it is working now. I don't know earlier when I did the same thing it was giving some error.

oparoz commented 8 years ago

Cool, so now you can write the 2 additional tests :)

imjalpreet commented 8 years ago

@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?

oparoz commented 8 years ago

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.

imjalpreet commented 8 years ago

@oparoz Actually, I have changed it on my local machine already but I was not able to figure out how do I test it?

oparoz commented 8 years ago

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 :)

imjalpreet commented 8 years ago

@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.

oparoz commented 8 years ago

Sure, but you should be able to control what Mapper->insert returns by mocking it.

imjalpreet commented 8 years ago

@oparoz Okay, I will try mocking it.

imjalpreet commented 8 years ago

@oparoz I have added the test for dbManager error. Please have a look.

oparoz commented 8 years ago

Works for me :)