Automattic / wordbless

WorDBless allows you to use WordPress core functions in your PHPUnit tests without having to set up a database and the whole WordPress environment
Other
131 stars 6 forks source link

Metadata: Allow all metadata to be returned for an object #53

Open pablinos opened 2 years ago

pablinos commented 2 years ago

While testing some code that was setting post metadata, I was debugging it by outputting all the metadata for a post with a call to get_post_meta( $post_id ). I noticed that the tests started passing but I was still getting an empty array from the get_post_meta call.

Getting a specific key was working, which led me to look at the Metadata code here, which currently doesn't deal with the case of the key being an empty value.

This change refactors the get function, but is probably not optimal, as we change the shape of the object's metadata using array_reduce on each call. It illustrates the issue, and I'm happy to optimise it if we want to go this route.

leogermani commented 2 years ago

Thanks for this!

I think it's fine if things are not super performant, This is meant to run test suites so a little bit of overload is accepted (as we are removing a lot of overload by not having a database!).

Do you think you could write some tests for this? And then, from there, we can look at the best implementation