? Failure
Referenced as Related to: # 4453

User tests: Successful: Unsuccessful:

avatar wilsonge
wilsonge
14 Sep 2014

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!!

avatar wilsonge wilsonge - open - 14 Sep 2014
avatar jissues-bot jissues-bot - change - 14 Sep 2014
Labels Added: ?
avatar wilsonge wilsonge - change - 14 Sep 2014
The description was changed
avatar zero-24 zero-24 - change - 14 Sep 2014
Category Libraries
avatar mbabker
mbabker - comment - 14 Sep 2014
avatar zero-24 zero-24 - change - 14 Sep 2014
Category Libraries Libraries Unit Tests
avatar wilsonge
wilsonge - comment - 14 Sep 2014

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

avatar wilsonge wilsonge - close - 14 Sep 2014
avatar wilsonge wilsonge - close - 14 Sep 2014
avatar wilsonge wilsonge - change - 14 Sep 2014
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2014-09-14 19:28:34
avatar wilsonge wilsonge - reopen - 14 Sep 2014
avatar wilsonge wilsonge - reopen - 14 Sep 2014
avatar wilsonge wilsonge - change - 14 Sep 2014
Status Closed New
avatar wilsonge
wilsonge - comment - 14 Sep 2014

Did those tests ever pass?

avatar mbabker
mbabker - comment - 14 Sep 2014

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).

avatar wilsonge
wilsonge - comment - 14 Sep 2014

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.

avatar wilsonge
wilsonge - comment - 14 Sep 2014

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

avatar vdespa vdespa - change - 15 Sep 2014
Status New Pending
avatar wilsonge
wilsonge - comment - 15 Sep 2014

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

avatar mbabker
mbabker - comment - 15 Sep 2014

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.

avatar mbabker
mbabker - comment - 15 Sep 2014

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.

avatar wilsonge
wilsonge - comment - 15 Sep 2014

That might help. My computer has always errored when running the full test suite so not sure what the solution is :/

avatar wilsonge
wilsonge - comment - 15 Sep 2014

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

avatar mbabker
mbabker - comment - 15 Sep 2014

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).

avatar wilsonge
wilsonge - comment - 15 Sep 2014

I've cheated. See latest commit. Agree your PR is better long term solution

avatar mbabker
mbabker - comment - 15 Sep 2014

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?

avatar wilsonge
wilsonge - comment - 15 Sep 2014

Squashed commits down a bit and rebased on master. Let's see how travis goes.

avatar wilsonge wilsonge - close - 4 Oct 2014
avatar wilsonge wilsonge - change - 4 Oct 2014
Status Pending Closed
Closed_Date 2014-09-14 19:28:34 2014-10-04 17:36:47

Add a Comment

Login with GitHub to post a comment