Ad
How To Test A Second Parameter In A PHPUnit Mock Object
This is what I have:
$observer = $this->getMock('SomeObserverClass', array('method'));
$observer->expects($this->once())
->method('method')
->with($this->equalTo($arg1));
But the method should take two parameters. I am only testing that the first parameter is being passed correctly (as $arg1).
How do test the second parameter?
Ad
Answer
I believe the way to do this is:
$observer->expects($this->once())
->method('method')
->with($this->equalTo($arg1),$this->equalTo($arg2));
Or
$observer->expects($this->once())
->method('method')
->with($arg1, $arg2);
If you need to perform a different type of assertion on the 2nd arg, you can do that, too:
$observer->expects($this->once())
->method('method')
->with($this->equalTo($arg1),$this->stringContains('some_string'));
If you need to make sure some argument passes multiple assertions, use logicalAnd()
$observer->expects($this->once())
->method('method')
->with($this->logicalAnd($this->stringContains('a'), $this->stringContains('b')));
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad