note 110344 added to functions.anonymous
| From: | michaelrfairhurst at gmail dot com | Date: | Sun, 14 Oct 2012 06:44:43 +0000 |
| Subject: | note 110344 added to functions.anonymous | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-191281@lists.php.net to get a copy of this message | ||
While PHPUnit's mocking framework did a pretty good job at keeping a compact
API (more or less) there are times where a mocked return value would be better
handled as a test class property.
<?php
$this->mock = $this->getMock('StdClass');
$_ = $this;
$this->mock->expects($this->once())
->method('getProperty')
->will($this->returnCallback(function() use($_) {
return $_->property;
}));
$this->property = '12345';
$this->assertEquals('12345', $this->mock->getProperty());
// OK (1 Test, 2 Assertions)
?>
BUT:
[[ Just remember the law of demeter, if your mock object is really behaving as _just_
a parameter, you should probably refactor your SUT to just take another parameter
instead of giving it a completely unnecessary dependency. ]]
----
Server IP: 69.147.83.199
Probable Submitter: 74.93.186.249
----
Manual Page -- http://www.php.net/manual/en/functions.anonymous.php
Edit -- https://master.php.net/note/edit/110344
Del: integrated -- https://master.php.net/note/delete/110344/integrated
Del: useless -- https://master.php.net/note/delete/110344/useless
Del: bad code -- https://master.php.net/note/delete/110344/bad+code
Del: spam -- https://master.php.net/note/delete/110344/spam
Del: non-english -- https://master.php.net/note/delete/110344/non-english
Del: in docs -- https://master.php.net/note/delete/110344/in+docs
Del: other reasons-- https://master.php.net/note/delete/110344
Reject -- https://master.php.net/note/reject/110344
Search -- https://master.php.net/manage/user-notes.php