PHP Class Eloquent\Phony\Mock\Builder\MockBuilder

Show file Open project: eloquent/phony

Public Methods

Method Description
__clone ( ) Clone this builder.
__construct ( mixed $types, MockFactory $factory, HandleFactory $handleFactory, InvocableInspector $invocableInspector, FeatureDetector $featureDetector ) Construct a new mock builder.
addConstant ( string $name, mixed $value ) Add a custom class constant.
addMethod ( string $name, callable | null $callback = null ) Add a custom method.
addProperty ( string $name, mixed $value = null ) Add a custom property.
addStaticMethod ( string $name, callable | null $callback = null ) Add a custom static method.
addStaticProperty ( string $name, mixed $value = null ) Add a custom static property.
build ( boolean $createNew = false ) : ReflectionClass Generate and define the mock class.
className ( boolean $createNew = false ) : string Generate and define the mock class, and return the class name.
definition ( ) : MockDefinition Get the mock definitions.
factory ( ) : MockFactory Get the factory.
featureDetector ( ) : FeatureDetector Get the feature detector.
finalize ( ) Finalize the mock builder.
full ( ) : Eloquent\Phony\Mock\Mock Create a new full mock.
get ( ) : Eloquent\Phony\Mock\Mock Get a mock.
handleFactory ( ) : HandleFactory Get the handle factory.
invocableInspector ( ) : InvocableInspector Get the invocable inspector.
isBuilt ( ) : boolean Returns true if the mock class has been built.
isFinalized ( ) : boolean Returns true if this builder is finalized.
like ( mixed $type ) Add classes, interfaces, or traits.
named ( string | null $className = null ) Set the class name.
partial ( ) : Eloquent\Phony\Mock\Mock Create a new partial mock.
partialWith ( Arguments | array | null $arguments = [] ) : Eloquent\Phony\Mock\Mock Create a new partial mock.
source ( MockGenerator $generator = null ) : string Get the generated source code of the mock class.
types ( ) : ReflectionClass>\array Get the types.

Private Methods

Method Description
define ( $definition )
normalizeDefinition ( )
resolveInternalInterface ( $interface, $preferred, $alternate )

Method Details

__clone() public method

Clone this builder.
public __clone ( )

__construct() public method

Each value in $types can be either a class name, or an ad hoc mock definition. If only a single type is being mocked, the class name or definition can be passed without being wrapped in an array.
public __construct ( mixed $types, MockFactory $factory, HandleFactory $handleFactory, InvocableInspector $invocableInspector, FeatureDetector $featureDetector )
$types mixed The types to mock.
$factory Eloquent\Phony\Mock\MockFactory The factory to use.
$handleFactory Eloquent\Phony\Mock\Handle\HandleFactory The handle factory to use.
$invocableInspector Eloquent\Phony\Invocation\InvocableInspector The invocable inspector.
$featureDetector Eloquent\Phony\Reflection\FeatureDetector The feature detector to use.

addConstant() public method

Add a custom class constant.
public addConstant ( string $name, mixed $value )
$name string The name.
$value mixed The value.

addMethod() public method

Add a custom method.
public addMethod ( string $name, callable | null $callback = null )
$name string The name.
$callback callable | null The callback.

addProperty() public method

Add a custom property.
public addProperty ( string $name, mixed $value = null )
$name string The name.
$value mixed The value.

addStaticMethod() public method

Add a custom static method.
public addStaticMethod ( string $name, callable | null $callback = null )
$name string The name.
$callback callable | null The callback.

addStaticProperty() public method

Add a custom static property.
public addStaticProperty ( string $name, mixed $value = null )
$name string The name.
$value mixed The value.

build() public method

Calling this method will finalize the mock builder.
public build ( boolean $createNew = false ) : ReflectionClass
$createNew boolean True if a new class should be created even when a compatible one exists.
return ReflectionClass The class.

className() public method

Calling this method will finalize the mock builder.
public className ( boolean $createNew = false ) : string
$createNew boolean True if a new class should be created even when a compatible one exists.
return string The class name.

definition() public method

Calling this method will finalize the mock builder.
public definition ( ) : MockDefinition
return MockDefinition The mock definition.

factory() public method

Get the factory.
public factory ( ) : MockFactory
return Eloquent\Phony\Mock\MockFactory The factory.

featureDetector() public method

Get the feature detector.
public featureDetector ( ) : FeatureDetector
return Eloquent\Phony\Reflection\FeatureDetector The feature detector.

finalize() public method

Finalize the mock builder.
public finalize ( )

full() public method

This method will always create a new mock, and will replace the current mock. Calling this method will finalize the mock builder.
public full ( ) : Eloquent\Phony\Mock\Mock
return Eloquent\Phony\Mock\Mock The mock instance.

get() public method

This method will return the current mock, only creating a new mock if no existing mock is available. If no existing mock is available, the created mock will be a full mock. Calling this method will finalize the mock builder.
public get ( ) : Eloquent\Phony\Mock\Mock
return Eloquent\Phony\Mock\Mock The mock instance.

handleFactory() public method

Get the handle factory.
public handleFactory ( ) : HandleFactory
return Eloquent\Phony\Mock\Handle\HandleFactory The handle factory.

invocableInspector() public method

Get the invocable inspector.
public invocableInspector ( ) : InvocableInspector
return Eloquent\Phony\Invocation\InvocableInspector The invocable inspector.

isBuilt() public method

Returns true if the mock class has been built.
public isBuilt ( ) : boolean
return boolean True if the mock class has been built.

isFinalized() public method

Returns true if this builder is finalized.
public isFinalized ( ) : boolean
return boolean True if finalized.

like() public method

Each value in $types can be either a class name, or an ad hoc mock definition. If only a single type is being mocked, the class name or definition can be passed without being wrapped in an array.
public like ( mixed $type )
$type mixed A type, or types to add.

named() public method

Set the class name.
public named ( string | null $className = null )
$className string | null The class name, or null to use a generated name.

partial() public method

This method will always create a new mock, and will replace the current mock. Calling this method will finalize the mock builder.
public partial ( ) : Eloquent\Phony\Mock\Mock
return Eloquent\Phony\Mock\Mock The mock instance.

partialWith() public method

This method will always create a new mock, and will replace the current mock. Calling this method will finalize the mock builder. This method supports reference parameters.
public partialWith ( Arguments | array | null $arguments = [] ) : Eloquent\Phony\Mock\Mock
$arguments Eloquent\Phony\Call\Arguments | array | null The constructor arguments, or null to bypass the constructor.
return Eloquent\Phony\Mock\Mock The mock instance.

source() public method

Calling this method will finalize the mock builder.
public source ( MockGenerator $generator = null ) : string
$generator Eloquent\Phony\Mock\MockGenerator The mock generator to use.
return string The source code.

types() public method

Get the types.
public types ( ) : ReflectionClass>\array
return ReflectionClass>\array