Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dev: Finish first remote API unit test
- Loading branch information
1 parent
b478314
commit 9dcffbb
Showing
1 changed file
with
30 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9dcffbb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand how you can test remopte control inside LimeSurvey APP ?
Dodn't we need a script more external ? and here TestBaseClass is inside LS .
the biggest issue in RC is get_session_key : i don't see how to try get_session_key inside LimeSurvey ?
9dcffbb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm testing the remote API helper class, not the remote API controller.
9dcffbb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Shnoulle Just a note: To make the code easier to test, only the CONTROLLER should contain interaction with the outside world, like the request object. Really important to separate concerns for test-driven development.
9dcffbb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can actually be taken one step further, to clearly separate functions with side-effects (writing/reading to file or database) from functions without.
9dcffbb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another technique that has become very popular the last years is something called dependency injection. This means that if class A depends on class DB, A will not ask for DB, but DB will be injected into A, e.g. in the constructor (there are frameworks that deal with this in a systematic matter). This makes it easier to create a dummy class DB_dummy when we're trying to test A.
9dcffbb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here it must be https://github.com/LimeSurvey/LimeSurvey/blob/master/application/controllers/admin/remotecontrol.php right ?
Or do you write this about a specific commit in done ?
9dcffbb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a general remark.
9dcffbb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, i try then :).
For example, i have the bad habit to add Permission::model check inside model. But this must be a Class variable or a function param : right ?
9dcffbb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, not sure. What's the context?
9dcffbb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LimeSurvey/application/models/Survey.php
Line 223 in 4f704d3
9dcffbb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. So, in a system with dependency injection you would instead have
This way, when doing tests, you can insert a dummy permission class:
Instead, now I have to hack the session:
LimeSurvey/tests/TestBaseClass.php
Line 66 in 4f704d3
9dcffbb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The question is how to handle the case when number of dependencies increases a lot. For models, we also have a dependency on the database, for example. Often the request is required. The session. And so on. When testing, all these objects have to be hacked around in different ways, making the code pretty fragile.