src/MockHelper.php
public function mockObject($objectClassName, ...$configurations)
    {
        foreach ($configurations as &$configuration) {
            $this->prepareMockConfig($configuration);
        }

        $config = call_user_func_array('array_replace_recursive', $configurations);

        $willReturn = $this->pullOutArrayValue($config, 'willReturn', []);
        $will = $this->pullOutArrayValue($config, 'will');
        $mockType = $this->pullOutArrayValue($config, 'mockType', self::MOCK_TYPE_DEFAULT);

        // 'methods' must be null for 'getMock' to not replace any element
        // (unlike 'getMockForAbstractClass')
        if (empty($config['methods'])) {
            if ($mockType == self::MOCK_TYPE_DEFAULT) {
                $config['methods'] = null;
            }
        }

        $mockBuilder = $this->testCase->getMockBuilder($objectClassName);

        foreach ($config as $property => $value) {
            $method = "set$property";
            if (method_exists($mockBuilder, $method)) {
                $mockBuilder->$method($value);
            }
        }

        if ($this->getArrayValue($config, 'disableOriginalConstructor', true)) {
            $mockBuilder->disableOriginalConstructor();
        }

        $mockMethod = $this->getMockMethod($mockType);
        /** @var \PHPUnit_Framework_MockObject_MockObject $mock */
        $mock = $mockBuilder->$mockMethod();

        foreach ($willReturn as $method => $value) {
            $mock->method($method)->willReturn($value);
        }

        foreach ($will as $method => $value) {
            $mock->method($method)->will($value);
        }

        return $mock;
    }
public function mockObject($objectClassName, ...$configurations)
    {
        foreach ($configurations as &$configuration) {
            $this->prepareMockConfig($configuration);
        }

        $config = call_user_func_array('array_replace_recursive', $configurations);

        $willReturn = $this->pullOutArrayValue($config, 'willReturn', []);
        $will = $this->pullOutArrayValue($config, 'will');
        $mockType = $this->pullOutArrayValue($config, 'mockType', self::MOCK_TYPE_DEFAULT);

        // 'methods' must be null for 'getMock' to not replace any element
        // (unlike 'getMockForAbstractClass')
        if (empty($config['methods'])) {
            if ($mockType == self::MOCK_TYPE_DEFAULT) {
                $config['methods'] = null;
            }
        }

        $mockBuilder = $this->testCase->getMockBuilder($objectClassName);

        foreach ($config as $property => $value) {
            $method = "set$property";
            if (method_exists($mockBuilder, $method)) {
                $mockBuilder->$method($value);
            }
        }

        if ($this->getArrayValue($config, 'disableOriginalConstructor', true)) {
            $mockBuilder->disableOriginalConstructor();
        }

        $mockMethod = $this->getMockMethod($mockType);
        /** @var \PHPUnit_Framework_MockObject_MockObject $mock */
        $mock = $mockBuilder->$mockMethod();

        foreach ($willReturn as $method => $value) {
            $mock->method($method)->willReturn($value);
        }

        foreach ($will as $method => $value) {
            $mock->method($method)->will($value);
        }

        return $mock;
    }
public function mockObject ( $ objectClassName , ... $ configurations ) { foreach ( $ configurations as & $ configuration ) { $ this -> prepareMockConfig ( $ configuration ) ; } $ config = call_user_func_array ( 'array_replace_recursive' , $ configurations ) ; $ willReturn = $ this -> pullOutArrayValue ( $ config , 'willReturn' , [ ] ) ; $ will = $ this -> pullOutArrayValue ( $ config , 'will' ) ; $ mockType = $ this -> pullOutArrayValue ( $ config , 'mockType' , self :: MOCK_TYPE_DEFAULT ) ; // 'methods' must be null for 'getMock' to not replace any element // (unlike 'getMockForAbstractClass') if ( empty ( $ config [ 'methods' ] ) ) { if ( $ mockType == self :: MOCK_TYPE_DEFAULT ) { $ config [ 'methods' ] = null ; } } $ mockBuilder = $ this -> testCase -> getMockBuilder ( $ objectClassName ) ; foreach ( $ config as $ property => $ value ) { $ method = "set$property" ; if ( method_exists ( $ mockBuilder , $ method ) ) { $ mockBuilder -> $ method ( $ value ) ; } } if ( $ this -> getArrayValue ( $ config , 'disableOriginalConstructor' , true ) ) { $ mockBuilder -> disableOriginalConstructor ( ) ; } $ mockMethod = $ this -> getMockMethod ( $ mockType ) ; /** @var \PHPUnit_Framework_MockObject_MockObject $mock */ $ mock = $ mockBuilder -> $ mockMethod ( ) ; foreach ( $ willReturn as $ method => $ value ) { $ mock -> method ( $ method ) -> willReturn ( $ value ) ; } foreach ( $ will as $ method => $ value ) { $ mock -> method ( $ method ) -> will ( $ value ) ; } return $ mock ; }
General method for mocking objects

@param string $objectClassName
@param array[] $configurations A variable number of configurations for creating of mock.
You can use this feature, for example, to gather a several configurations from different sources
and then just pass them to the `mockObject` method instead of merging them.
It will merge them itself.

Each configuration must be an array. Otherwise you will get an error.
As default each item of array is considered as a name of property for which a getter may exist in the original mock builder.
For example, the parameter `constructorArgs` actually will be used to make the method name `setConstructorArgs`.
The values of these parameters are used as values which must be passed to the matched methods.

But there are also special parameters that are handled in their own way.
They are:
- `constructor` - It's a shortcut of the `disableOriginalConstructor` parameter of the original mock builder.
The value of parameter constructor is used to set the parameter `disableOriginalConstructor`.
The value of the `constructor` must be a boolean value. The inverted boolean value will be set
to the parameter `disableOriginalConstructor`.
For example, if you'll set `constructor => false`, the parameter `disableOriginalConstructor` will get
the value `false`.
Note that the original parameter `disableOriginalConstructor` has a higher priority than parameter `constructor`.
If the parameter `disableOriginalConstructor` is set, the parameter `constructor` will be ignored.
- `willReturn` - It's a shortcut for the separated setting of returned values for methods.
It must be an array.
The keys of the array are considered as method names.
The values of the array are considered as values, that must be returned by the appropriate methods.
```php
// This part of configuration ...
[
// ...
'willReturn' => [
'method1' => 'value1',
'method2' => 'value2',
]
// ...
]

// ... equals to
$mock->method('method1')->willReturn('value1');
$mock->method('method2')->willReturn('value2');
```
- `will` - It's similar to `willReturn` but the method `will()` will used instead of `willReturn()`.
- `mockType` - It's a type of mock.
Allowed values are:
- `default` (MockHelper::MOCK_TYPE_DEFAULT)
- `abstract` (MockHelper::MOCK_TYPE_ABSTRACT)
- `trait` (MockHelper::MOCK_TYPE_TRAIT)
The value of this parameter is used to select a method of the original mock builder that must be used to create a mock.

@return \PHPUnit_Framework_MockObject_MockObject
@throws InvalidMockTypeException
General method for mocking objects