Documentation

MockBuilder
in package

FinalYes
Tags
template
no-named-arguments

Parameter names are not covered by the backward compatibility promise for PHPUnit

Table of Contents

Properties

$allowMockingUnknownTypes  : bool
$autoload  : bool
$callOriginalMethods  : bool
$cloneArguments  : bool
$constructorArgs  : array<string|int, mixed>
$emptyMethodsArray  : bool
$generator  : Generator
$methods  : array<int, non-empty-string>
$mockClassName  : class-string|null
$originalClone  : bool
$originalConstructor  : bool
$proxyTarget  : object|null
$returnValueGeneration  : bool
$testCase  : TestCase
$type  : class-string|trait-string

Methods

__construct()  : mixed
addMethods()  : $this
Specifies methods that don't exist in the class which you want to mock.
allowMockingUnknownTypes()  : $this
disableArgumentCloning()  : $this
Disables the cloning of arguments passed to mocked methods.
disableAutoload()  : $this
Disables the use of class autoloading while creating the mock object.
disableAutoReturnValueGeneration()  : $this
disableOriginalClone()  : $this
Disables the invocation of the original clone constructor.
disableOriginalConstructor()  : $this
Disables the invocation of the original constructor.
disableProxyingToOriginalMethods()  : $this
Disables the invocation of the original methods.
disallowMockingUnknownTypes()  : $this
enableArgumentCloning()  : $this
Enables the cloning of arguments passed to mocked methods.
enableAutoload()  : $this
Enables the use of class autoloading while creating the mock object.
enableAutoReturnValueGeneration()  : $this
enableOriginalClone()  : $this
Enables the invocation of the original clone constructor.
enableOriginalConstructor()  : $this
Enables the invocation of the original constructor.
enableProxyingToOriginalMethods()  : $this
Enables the invocation of the original methods.
getMock()  : MockedType|MockObject
Creates a mock object using a fluent interface.
getMockForAbstractClass()  : MockedType|MockObject
Creates a mock object for an abstract class using a fluent interface.
getMockForTrait()  : MockedType|MockObject
Creates a mock object for a trait using a fluent interface.
onlyMethods()  : $this
Specifies the subset of methods to mock, requiring each to exist in the class.
setConstructorArgs()  : $this
Specifies the arguments for the constructor.
setMockClassName()  : $this
Specifies the name for the mock class.
setProxyTarget()  : $this
Sets the proxy target.
calledFromTestCase()  : bool

Properties

$allowMockingUnknownTypes

private bool $allowMockingUnknownTypes = true

$callOriginalMethods

private bool $callOriginalMethods = false

$cloneArguments

private bool $cloneArguments = false

$constructorArgs

private array<string|int, mixed> $constructorArgs = []

$emptyMethodsArray

private bool $emptyMethodsArray = false

$methods

private array<int, non-empty-string> $methods = []

$mockClassName

private class-string|null $mockClassName = null

$originalConstructor

private bool $originalConstructor = true

$proxyTarget

private object|null $proxyTarget = null

$returnValueGeneration

private bool $returnValueGeneration = true

$type read-only

private class-string|trait-string $type

Methods

__construct()

public __construct(TestCase $testCase, class-string|trait-string $type) : mixed
Parameters
$testCase : TestCase
$type : class-string|trait-string

addMethods()

Specifies methods that don't exist in the class which you want to mock.

public addMethods(array<int, non-empty-string> $methods) : $this

https://github.com/sebastianbergmann/phpunit/issues/5320

Parameters
$methods : array<int, non-empty-string>
Tags
throws
CannotUseAddMethodsException
ReflectionException
RuntimeException
Return values
$this

allowMockingUnknownTypes()

public allowMockingUnknownTypes() : $this

https://github.com/sebastianbergmann/phpunit/issues/5308

Return values
$this

disableArgumentCloning()

Disables the cloning of arguments passed to mocked methods.

public disableArgumentCloning() : $this

https://github.com/sebastianbergmann/phpunit/issues/5315

Return values
$this

disableAutoload()

Disables the use of class autoloading while creating the mock object.

public disableAutoload() : $this

https://github.com/sebastianbergmann/phpunit/issues/5309

Tags
codeCoverageIgnore
Return values
$this

disableAutoReturnValueGeneration()

public disableAutoReturnValueGeneration() : $this
Return values
$this

disableOriginalClone()

Disables the invocation of the original clone constructor.

public disableOriginalClone() : $this
Return values
$this

disableOriginalConstructor()

Disables the invocation of the original constructor.

public disableOriginalConstructor() : $this
Return values
$this

disableProxyingToOriginalMethods()

Disables the invocation of the original methods.

public disableProxyingToOriginalMethods() : $this

https://github.com/sebastianbergmann/phpunit/issues/5307

Return values
$this

disallowMockingUnknownTypes()

public disallowMockingUnknownTypes() : $this

https://github.com/sebastianbergmann/phpunit/issues/5308

Return values
$this

enableArgumentCloning()

Enables the cloning of arguments passed to mocked methods.

public enableArgumentCloning() : $this

https://github.com/sebastianbergmann/phpunit/issues/5315

Return values
$this

enableAutoload()

Enables the use of class autoloading while creating the mock object.

public enableAutoload() : $this

https://github.com/sebastianbergmann/phpunit/issues/5309

Return values
$this

enableAutoReturnValueGeneration()

public enableAutoReturnValueGeneration() : $this
Return values
$this

enableOriginalClone()

Enables the invocation of the original clone constructor.

public enableOriginalClone() : $this
Return values
$this

enableOriginalConstructor()

Enables the invocation of the original constructor.

public enableOriginalConstructor() : $this
Return values
$this

enableProxyingToOriginalMethods()

Enables the invocation of the original methods.

public enableProxyingToOriginalMethods() : $this

https://github.com/sebastianbergmann/phpunit/issues/5307

Tags
codeCoverageIgnore
Return values
$this

getMock()

Creates a mock object using a fluent interface.

public getMock() : MockedType|MockObject
Tags
throws
ClassIsEnumerationException
ClassIsFinalException
DuplicateMethodException
InvalidArgumentException
InvalidMethodNameException
NameAlreadyInUseException
OriginalConstructorInvocationRequiredException
ReflectionException
RuntimeException
UnknownTypeException
Return values
MockedType|MockObject

getMockForAbstractClass()

Creates a mock object for an abstract class using a fluent interface.

public getMockForAbstractClass() : MockedType|MockObject

https://github.com/sebastianbergmann/phpunit/issues/5305

Tags
throws
Exception
ReflectionException
RuntimeException
Return values
MockedType|MockObject

getMockForTrait()

Creates a mock object for a trait using a fluent interface.

public getMockForTrait() : MockedType|MockObject

https://github.com/sebastianbergmann/phpunit/issues/5306

Tags
throws
Exception
ReflectionException
RuntimeException
Return values
MockedType|MockObject

onlyMethods()

Specifies the subset of methods to mock, requiring each to exist in the class.

public onlyMethods(array<int, non-empty-string> $methods) : $this
Parameters
$methods : array<int, non-empty-string>
Tags
throws
CannotUseOnlyMethodsException
ReflectionException
Return values
$this

setConstructorArgs()

Specifies the arguments for the constructor.

public setConstructorArgs(array<string|int, mixed> $arguments) : $this
Parameters
$arguments : array<string|int, mixed>
Return values
$this

setMockClassName()

Specifies the name for the mock class.

public setMockClassName(class-string $name) : $this
Parameters
$name : class-string
Return values
$this

setProxyTarget()

Sets the proxy target.

public setProxyTarget(object $object) : $this

https://github.com/sebastianbergmann/phpunit/issues/5307

Parameters
$object : object
Tags
codeCoverageIgnore
Return values
$this

calledFromTestCase()

private calledFromTestCase() : bool
Return values
bool
On this page

Search results