Yii Framework Forum: phpUnit and getMock - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

phpUnit and getMock Rate Topic: -----

#1 User is offline   gavicus 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 20-June 12

Posted 02 August 2012 - 01:49 PM

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
0

#2 User is offline   Alex.net 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 07-December 12

Posted 25 December 2012 - 09:30 AM

View Postgavicus, on 02 August 2012 - 01:49 PM, said:

~


Similar trouble, but I'm stuck with attaching Mock object.

CException: "__METHOD__" and its behaviors do not have a method or closure named "attach".


Can someone suggest an example for Yii and getMock(), please?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users