Methods summary
public
|
#
__construct( )
Construct an instance of an Impersonator.
Construct an instance of an Impersonator.
Throws
Overrides
|
public static
Chromabits\Nucleus\Testing\Impersonator
|
|
public
mixed
|
#
make( string $target )
Attempt to build the provided class.
Attempt to build the provided class.
Be aware that complex classes might not be resolved automatically.
For example, scalar types are currently not supported.
Parameters
Returns
mixed
Throws
|
public
|
#
provide( mixed $mock )
Provide a mock.
Here we do some "magic" to attempt to figure out what the mock
implements. In order for mock resolution to be fast, relationships
between types and mocks are stored on a hash table ($this->provided).
This means that if you have objects implementing the same interface or
that are instances of the same class, then the last object provided
will be the one used.
For scenarios where you have two parameters of the same type in the
constructor or conflicting interfaces, it is recommended that you build
the object manually.
Parameters
Returns
$this
Throws
|
public
|
|
public static
Mockery\MockInterface
|
|
protected
ReflectionParameter[]
|
#
getArgumentTypes( mixed $target )
Reflect about a class' constructor parameter types.
Reflect about a class' constructor parameter types.
Parameters
Returns
ReflectionParameter[]
Throws
|
protected
array
|
#
mockArguments( array $parameters, array $overrides = [] )
Attempt to automatically mock the arguments of a function.
Attempt to automatically mock the arguments of a function.
Parameters
Returns
array
Throws
|
protected
Mockery\MockInterface
|
#
resolveMock( ReflectionClass $type )
Resolve which mock instance to use.
Resolve which mock instance to use.
Here we mainly decide whether to use something that was provided to or
go ahead an build an empty mock.
Parameters
Returns
Mockery\MockInterface
|
protected
Mockery\MockInterface
|
#
buildMock( ReflectionClass $type )
Build an empty mock.
Override this method if you would like to use a different mocking library
or if you would like all your mocks having some properties in common.
Parameters
Returns
Mockery\MockInterface
|
public static
Chromabits\Nucleus\Testing\Mocking\CallExpectation
|
#
on( string $methodName, array $arguments, mixed|null $return = null, integer $times = 1 )
Shortcut for constructing an instance of a CallExpectation.
Shortcut for constructing an instance of a CallExpectation.
Parameters
- $methodName
- $arguments
- $return
- $times
Returns
|
public static
Chromabits\Nucleus\Testing\Mocking\CallAndThrowExpectation
|
#
throwOn( string $methodName, array $arguments, string $exceptionClass, string $exceptionMessage, integer $exceptionCode )
Shortcut for constructing an instance of a CallAndThrowExpectation.
Shortcut for constructing an instance of a CallAndThrowExpectation.
Parameters
- $methodName
- $arguments
- $exceptionClass
- $exceptionMessage
- $exceptionCode
Returns
|
public
mixed
|
#
makeAndCall( string $target, string $methodName, array $arguments = [] )
Construct an instance of the target class and call the method while
injecting any argument that was not provided.
Construct an instance of the target class and call the method while
injecting any argument that was not provided.
Parameters
- $target
- $methodName
- $arguments
Returns
mixed
|
public
mixed
|
#
call( mixed $target, string $methodName, array $arguments = [] )
Call the method on the target object while injecting any missing
arguments using objects defined on this Impersonator instance.
Call the method on the target object while injecting any missing
arguments using objects defined on this Impersonator instance.
This allows one to easily call methods that define dependencies in their
arguments rather than just on the constructor of the class they reside
in.
Impersonator will apply a similar algorithm to make(). Dependencies that
are not provided, will be automatically be replaced with a dummy mock.
However, in the case of method calls, any provided argument will take
precedence over any injection.
Parameters
- $target
- $methodName
- $arguments
Returns
mixed
|