Welcome Guest, Not a member yet? Register   Sign In
Call to a member function sess_save() on a non-object
#1

Code:
Call to a member function sess_save() on a non-object /home/site/vendor/codeigniter/framework/system/libraries/Session/Session.php 302
 
Getting this when running unit tests with Codeception. 

I was able to run these before the last time I ran "composer update" not even sure where to start looking to what would be throwing this error.

Web side seems fine, I'm only running into this error when running unit tests in terminal. Any ideas?
Reply
#2

I think the problem is due to trying to use sessions from a direct CLI call. If you take a look at the Session class, it kicks you out if being called from the CLI, which means many of the functions might not be available.

IIRC I ran into this while getting some tests running in Codeception, also, and had to ensure that I wasn't autoloading the Session library. In other areas of testing, I had to extend their test class and do some other work on the setup files to grab an instance of CI and make it available so I could mock it, or parts of it. If you want to see what I did there check out this tests folder and you can see the customizations that I'm currently running with.

Hope that helps.
Reply
#3

I think I found the issue, I removed the session driver from my autoload, but it looks like MY_Controller is being loaded, which has a bunch of calls to the session driver on the web site to handle things (login session, user identification). 

Seems like there needs to be a session testing driver that could be load in place of the cookie driver to work for unit testing. Otherwise there's no way to test any methods that use the Session driver without running into this.
Reply
#4

As I know, you can't use sessions with CLI, because sessions (the key of the session) are saved in browser. Or am I wrong?
Reply
#5

(01-08-2015, 04:05 AM)Avenirer Wrote: As I know, you can't use sessions with CLI, because sessions (the key of the session) are saved in browser. Or am I wrong?

Yes, but there's more to it than that.

Sessions rely on the browser receiving, storing and sending a session cookie, but the issue at hand is that CI_Session is explicitly disabled under CLI. You otherwise can simulate a browser sending a cookie by manipulating the $_COOKIE superglobal.

What you can't do is send headers while using php-cli, force PHPUnit to not show output before any header() calls (in case you've hacked it to run the php-cgi binary instead of php-cli) and in any case - do any kind of session testing without mocking the library.
Reply
#6

I ended up making a flat file session driver that is loaded when my tests are being run 
Session_codeception.php
https://gist.github.com/withremote/99c0ad36999da43fb127

Then I made a MY_Session.php override which only loads this driver if it detects i'm running my tests.
MY_Session.php 
https://gist.github.com/withremote/7b7c8fed47f39524c0ba

Dirty, but it worked. I didn't need to test that session were being stored, just that the session driver was available to my libraries when running tests.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB