Eric Cope
Eric Cope

Reputation: 877

PHPUnit CIUnit Issue

When I run a specific test suite,

phpunit --testsuite LibTests

I get my expected results (passing tests). However, when I run "phpunit", I get an error claiming:

Fatal error: Call to a member function rss_feed_url() on a non-object in /Users/Shared/Jenkins/Home/jobs/Fanpilot_CT_3.0/workspace/tests/libs/VoltampMediaRSSFeedTest.php on line 20

where rss_feed_url() is a method of a class I loaded in setup().

Here is a snippet of my phpunit.xml file

<testsuites>
    <testsuite name="LibTests">
      <directory suffix=".php">tests/libs</directory>
    </testsuite>
</testsuites>

Thanks in advance!

Upvotes: 0

Views: 306

Answers (2)

Eric Cope
Eric Cope

Reputation: 877

The issue was I was not reinitializing $this->CI to the proper controller. It was stale from the last test. In every setUp()m you need to be sure to initialize $this-CI, like this:

$this->CI = set_controller();

In my case, I have a custom MY_Controller (applications/core/My_Controller.php). Therefore, I can do this if I need to leverage my custom controller.

$this->CI = set_controller('MY_Controller');

As a side note, I finally figured it out by dumping both the get_class and the get_parent_class within the CIU_Loader method, _ci_load_class, and I noticed that these values depending on whether I ran it as a single test or as everything.

Upvotes: 1

Gordon Forsythe
Gordon Forsythe

Reputation: 406

It seems in phpunit that most class variables get unset between test methods. If that's the issue (it sounds like it, with the non-object error). I believe I solved this issue for myself by making those variables private and/or static.

Upvotes: 0

Related Questions