drahak / Restful

Drahak\Restful - Nette REST API bundle
0 stars 0 forks source link

Testing resource presenters #37

Open MartinMystikJonas opened 10 years ago

MartinMystikJonas commented 10 years ago

Is there any best practice for testing ResourcePresenters? We start using your library (which is by far best we can found), but we struggle in creation of Input objects, because it seems hard-coded to use HttpRequest.

So my question is: how to you test ResourcePresenter? It there some practice I missed?

If not I will prepare PR with changes which allows to do so (basically just customizable InputFactory which allows to make explicit request)

drahak commented 10 years ago

but we struggle in creation of Input objects, because it seems hard-coded to use HttpRequest.

Problem is in ApiRequestFactory. I'm using it to be able to override request method. It creates Nette HttpRequest object so it's quite strict. I'll have to change it.

how to you test ResourcePresenter? It there some practice I missed?

If you want to unit test resource presenters, there is not. I'm using black box testing to test presenters and I haven't found better way yet.

Although I've been still working on the library it is just an experimental project and you should consider using RestRoute or something similar.

MartinMystikJonas commented 10 years ago

We resolved it by creating ExplicitInputFactory - input factory for which you set params not by passing HttpRequest but by setters ($inputFactpry->setGetParams(), etc.). It test we just replace default InputFactory with our implementation and test it this way.

I can prepare PR with this change. It is not complicated - just add IInputFactoryInterface with two diferent impmenetations HttpInputFactory and ExplicitInputFactory.

I examined few other Rest implementations but your library I like most. We will create our own fork so we are not influenced byt BC breaks. We will use it only on some non business critical apps. For now it works well and if we came across some bugs or problems we will just fix it and submit as PR.

MartinSadovy commented 9 years ago

@MartinMystikJonas :+1: could you create PR, please? Thank you :-)