1

Code:

$mockObject = $this->getMock('ORM_User');

$mockObject->expects($this->at(0))
    ->method('xxx')
    ->with($this->equalTo('a'))
    ->will($this->returnValue('aaa'));

$mockObject->expects($this->at(1))
    ->method('xxx')
    ->with($this->equalTo('b'))
    ->will($this->returnValue('bbb'));

var_dump("-".$mockObject->xxx('a'));
var_dump($mockObject->xxx('b'));  

$tmp = new ORM_User();
var_dump($tmp->xxx('a'));
var_dump($tmp->xxx('b'));

Output:


string(4) "-aaa"
string(3) "bbb"
NULL
NULL

2
  • 3
    In your code mock returns data, and real object returns nulls. Commented Jan 27, 2011 at 4:00
  • zerkms, there are some way to do it? thank's Commented Jan 27, 2011 at 4:17

1 Answer 1

3

The does to exactly what you tell it too and works fine as far as i can see it.

You create a "fake" ORM_User and tell the xxx function to return "aaa" and "bbb" and it does that.

Then you create a real ORM_USER and call it, that returns null but that is behond the scope of phpunit. You are just calling the real class there to i don't see where you are getting at this that.

Maybe tell us what you are trying to do ?

Sign up to request clarification or add additional context in comments.

3 Comments

Additional: It seems, that you (Felipe) use __call() to catch all calls to undefined methods and return null. If not, you should think about your naming conventions for methods (xxx() is not a good name).
KingCrunch, the name "xxx" only was a example :D
edorian, I finally do it... Thank's

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.