User tests: Successful: Unsuccessful:
JSession is currently a nightmare when trying to unit test parts of the CMS. This is largely because PHPUnit starts a session before the start of all tests.
One of the solutions to this is to abstract out the session_start stuff. So I've done this. The interface comes almost directly from symfony - https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/Session/Storage/SessionStorageInterface.php (with the Bag stuff removed as we don't need to go there yet)
Then moved all our code into a class that implements this session. This should make unit testing easier in the future. It easier for people who integrate sessions with Joomla to do so and in the future unit tests to be easier to write (as we can add in mock classes implementing the interface like here https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php)
One of the current issues is the compulsory cookie style stuff. I'm not sure how to deal with some of the set_cookie things so left them in JSession now to err on the side of caution. But I'm pretty sure with the right knowledge/adaptation of the interface we can move it into the handler class.
Clearly session is a pretty important part of Joomla so it goes without saying this needs some pretty hard testing!!
Labels |
Added:
?
|
Category | ⇒ | Libraries |
Category | Libraries | ⇒ | Libraries Unit Tests |
Well they all fail because I don't have an adpater class to inject in yet to replace the session_start crap. As I said you'd need a version of mock array session storage like https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpFoundation/Session/Storage/MockArraySessionStorage.php before you could run the tests
Status | Pending | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2014-09-14 19:28:34 |
Status | Closed | ⇒ | New |
Did those tests ever pass?
Yes. All we're carried to the Framework except JSessionTest because of the
problems you listed here.
On Sunday, September 14, 2014, George Wilson notifications@github.com
wrote:
Did those tests ever pass?
—
Reply to this email directly or view it on GitHub
#4279 (comment).
Well I copied in the symfony package above and tests nearly pass. Getting name and id fail because the test is testing them against session_name() and session_id() which of course is different to the name/id being used by the array system.
getFormToken also fails. Not sure about that. Will push up that. Gotta focus on some other stuff now. But gives you an idea.
This is weird. travis is failing all the tests and using the "native" session bridges. It should be injecting the array based thing into all of them. Only 3 fail on my computer :(
I removed the skeletons because it was cluttering my pr when i was going through it for debug times ealier
Status | New | ⇒ | Pending |
I have no clue why these tests are failing. I tried a huge number of combo's and every time travis decides to play Gandalf
Create a new branch from this one and put some var_dumps into JSessionTest then change it so only that test is getting run on Travis. That should help give an idea what's going on, then when you figure it out you merge the fixes back onto this branch and the PR gets updated without all the extra history.
So I just ran the full suite locally and I'm getting the same errors as Travis. But the test runs fine in isolation. Which means there's something else in the test suite which is screwing up the test platform.
That might help. My computer has always errored when running the full test suite so not sure what the solution is :/
Ughh 10 fold increased my memory limit and got places. JSession::getInstance() is being called before this test in other places. So it's returning the statically stored variable which has the native handler
I have a new PR for you. We basically need to inject mocks into JFactory in a lot more places (and make sure that doesn't cause failures).
I've cheated. See latest commit. Agree your PR is better long term solution
Ya, that'll work. But it doesn't actually address the real problems in the testing platform. Let's try not to introduce more hacks please?
Squashed commits down a bit and rebased on master. Let's see how travis goes.
Status | Pending | ⇒ | Closed |
Closed_Date | 2014-09-14 19:28:34 | ⇒ | 2014-10-04 17:36:47 |
Try porting over some of https://github.com/joomla/joomla-platform/tree/staging/tests/suites/unit/joomla/session and see what happens.