• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Testing with CIUnit

#1
[eluser]dsloan[/eluser]
I was investigating PHPUnit and having problems getting it working within the CI framework when I found this thread on CI Unit. Looks very interesting.

My first problem though is when attempting to run a test on my application (just a very simple assertTrue test for starters) I am getting a "call to a member function on a non-object" error. The object in question ($this->phpsession) is created automatically via the $autoload['libraries'] array when running via a browser but doesn't seem to be instantiated when running via the command line.

I tried loading it manually using $this->CI->load->library('phpsession') in the test case but to no avail.

Any ideas?

#2
[eluser]sophistry[/eluser]
i don't think sessions would work from the command line because a typical session depends on cookies. if you are running php directly from the command line there are no cookies. you'd have to use a cookie-aware command line tool like curl or wget.

#3
[eluser]rafsoaken[/eluser]
[quote author="dsloan" date="1218201216"] "call to a member function on a non-object" error. The object in question ($this->phpsession) is created automatically via the $autoload['libraries'] array when running via a browser but doesn't seem to be instantiated when running via the command line.
[/quote]

Hi,
the CIUnit class needs a database connection setting that is called the same as your usual db, just with and '_test' appended. So, if you'd use (in your database.php) $db['my_db_conn'], CIUnit looks for a setting $db['my_db_conn_test']. If that's not there, your phpsession class could call a member function on the database connection class, which of course is not instantiated correctly. Otherwise the use of phpsession shouldn't give any problems (besides when you want to test functions only logged-in users can access, then you have to bypass it - you would have to set the logged in flag manually for the tests).

Hope that helps - I'm onto creating a mailinglist and a public repository for CIUnit, so issues like this will be resolved faster..
cheers clemens

#4
[eluser]rafsoaken[/eluser]
Please note that autoloading classes has been fixed in the latest version of CIUnit (v0.13). That should fix any autoloading issues.

You can get the latest version of CIUnit on the official site here.

cheers
raf


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.