Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

phpUnit and getMock

$
0
0
I am using phpunit in my yii project. I'm new to phpUnit and have run into a tough problem.

I am testing a function in a class whose constructor I absolutely have to disable because it news up an object that I can't access from the test. So, I use the code:

public function testConnect(){
    $mock = $this->getMockBuilder('FSCall')
        ->setMethods(array('setOpened'))
        ->disableAutoload()
        ->disableOriginalConstructor()
        ->getMock();
    $call = new FSCall;
    $call->connect();
}


...where 'setOpened' is a local function that function connect calls, but I don't need it to actually call the function for the unit test.

The problem is that phpUnit returns the error "Call to undefined method FSCall::connect()". The function is in the FSCall class. Now I can "fix" the error by doing a...

$mock->expects($this->any())->method('connects')


...but then the connects function doesn't actually get called.

What am I misunderstanding here?

Any help will be greatly appreciated.

G

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>