Closed imjalpreet closed 8 years ago
I'll run this in a bit, but in the mean time, start writing the test for it.
@oparoz But actually, I have already used findEntity. I can't see findOneEntity in the class mapper and I think findEntity is what you are referring to findOneEntity. As there is one more which is findEntities. Am I correct or did I miss something?
You are absolutely correct. I was looking here too quickly: https://github.com/owncloud/core/blob/stable9.1/tests/lib/AppFramework/Db/MapperTest.php#L48
@oparoz Okay, So should I proceed to tests now?
Yes please, so that we can quickly move to the API implementation
@oparoz I needed some help. Can you tell how can I mock the mapper method find or findEntity? So that it returns what I want it to return.
@oparoz I meant like I have to test the retrieve method in RetrieveMetadata class, so for that I need to mock findEntity so that it returns what I want, so how I needed some help in doing that as I wasn't able to do it.
That class mentioned above is the helper and then you can use it like in this test class: https://github.com/nextcloud/news/blob/7a3a22bd2757e129c8964d9ddcde15ec53b736bb/tests/Unit/Db/ItemMapperTest.php
I'm thinking this method should be interesting: https://github.com/nextcloud/news/blob/7a3a22bd2757e129c8964d9ddcde15ec53b736bb/tests/Unit/Db/ItemMapperTest.php#L106-L115
Okay, I will have a look at all of them and see if it works.
@oparoz I have written a basic test for the retrieve method but it isn't passing as of now. Can you check what mistake am I making? DB output is not getting mocked properly.
The error is:
[OCP\AppFramework\Db\DoesNotExistException] Did expect one result but found none when executing: query "SELECT * FROM *PREFIX*mediametadata WHERE image_id = ?"; parameters Array
(
[0] => 260495
)
; limit ""; offset ""
OK, so I've made lots of comments inline :) Once this passes, we can merge it and then work on the API
@oparoz Okay, I will do all the changes. But did you have a look at the error that I mentioned above, do you have anything in mind what I have done wrong?
If you fix all the issues I reported ,the test will pass. What you did wrong is to not use the mocked DB for your test, you used a real connection which was never populated properly.
@oparoz Okay, Thanks. I will do all the changes and check.
@oparoz I have made the changes and test passed. Now we can move to API.
Could you please quickly fix the warning, otherwise we're always going to get it in future PRs.
@oparoz Done.
Code looks good, thanks!
@oparoz I have written the basic code for retrieval of metadata from DB. I have checked it and it worked.
Can you give suggestions?