public static function PHPUnit_Framework_MockObject_Generator::getMock

Returns a mock object for the specified class.

@since Method available since Release 1.0.0

Parameters

string $originalClassName:

array $methods:

array $arguments:

string $mockClassName:

boolean $callOriginalConstructor:

boolean $callOriginalClone:

boolean $callAutoload:

boolean $cloneArguments:

Return value

object

Throws

InvalidArgumentException

5 calls to PHPUnit_Framework_MockObject_Generator::getMock()
Framework_MockObject_GeneratorTest::testGetMockCanCreateNonExistingFunctions in drupal/core/vendor/phpunit/phpunit-mock-objects/Tests/GeneratorTest.php
@covers PHPUnit_Framework_MockObject_Generator::getMock
Framework_MockObject_GeneratorTest::testGetMockFailsWhenInvalidFunctionNameIsPassedInAsAFunctionToMock in drupal/core/vendor/phpunit/phpunit-mock-objects/Tests/GeneratorTest.php
@covers PHPUnit_Framework_MockObject_Generator::getMock @expectedException PHPUnit_Framework_Exception
Framework_MockObject_GeneratorTest::testGetMockGeneratorFails in drupal/core/vendor/phpunit/phpunit-mock-objects/Tests/GeneratorTest.php
@covers PHPUnit_Framework_MockObject_Generator::getMock @expectedException PHPUnit_Framework_Exception @expectedExceptionMessage duplicates: "foo, foo"
PHPUnit_Framework_MockObject_Generator::getMockForAbstractClass in drupal/core/vendor/phpunit/phpunit-mock-objects/PHPUnit/Framework/MockObject/Generator.php
Returns a mock object for the specified abstract class with all abstract methods of the class mocked. Concrete methods to mock can be specified with the last parameter
PHPUnit_Framework_TestCase::getMock in drupal/core/vendor/phpunit/phpunit/PHPUnit/Framework/TestCase.php
Returns a mock object for the specified class.

File

drupal/core/vendor/phpunit/phpunit-mock-objects/PHPUnit/Framework/MockObject/Generator.php, line 153

Class

PHPUnit_Framework_MockObject_Generator
Mock Object Code Generator

Code

public static function getMock($originalClassName, $methods = array(), array $arguments = array(), $mockClassName = '', $callOriginalConstructor = TRUE, $callOriginalClone = TRUE, $callAutoload = TRUE, $cloneArguments = TRUE) {
  if (!is_string($originalClassName)) {
    throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
  }
  if (!is_string($mockClassName)) {
    throw PHPUnit_Util_InvalidArgumentHelper::factory(4, 'string');
  }
  if (!is_array($methods) && !is_null($methods)) {
    throw new InvalidArgumentException();
  }
  if (NULL !== $methods) {
    foreach ($methods as $method) {
      if (!preg_match('~[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*~', $method)) {
        throw new PHPUnit_Framework_Exception(sprintf('Cannot stub or mock method with invalid name "%s"', $method));
      }
    }
    if ($methods != array_unique($methods)) {
      throw new PHPUnit_Framework_Exception(sprintf('Cannot stub or mock using a method list that contains duplicates: "%s"', implode(', ', $methods)));
    }
  }
  if ($mockClassName != '' && class_exists($mockClassName, FALSE)) {
    $reflect = new ReflectionClass($mockClassName);
    if (!$reflect
      ->implementsInterface("PHPUnit_Framework_MockObject_MockObject")) {
      throw new PHPUnit_Framework_Exception(sprintf('Class "%s" already exists.', $mockClassName));
    }
  }
  $mock = self::generate($originalClassName, $methods, $mockClassName, $callOriginalClone, $callAutoload, $cloneArguments);
  return self::getObject($mock['code'], $mock['mockClassName'], $originalClassName, $callOriginalConstructor, $callAutoload, $arguments);
}