bovigo/callmap
Stub and mock PHP method and function calls via a callmap. Define fixed returns, callbacks, consecutive results, or thrown exceptions, then verify invocations and arguments. Works with any unit test framework; argument checks via bovigo/assert or PHPUnit.
#[\ReturnTypeWillChange] to generated proxy methods if a PHP-internal class is mocked to prevent deprecation notices, as their return types available via reflection are not always up to date, e.g. for \XSLTProcessor where reflection delivers no return type information for the single methods of this classget_parent_class() in generated proxyis_callable(['parent', $someMethod])bovigo\callmap\FunctionProxy::returns() and bovigo\callmap\FunctionProxy::throws() so the instance is further recognized as a callable.\IteratorAggregate by providing specific return type
information, as reflection doesn't provide a return type for \IteratorAggregate::getIterator().returns() containing methods that don't have a return type declaration will result in an InvalidArgumentException.ReflectionParameter::getClass() by ::getType() (#22) PHP 8 deprecates the usage of ::getClass. So switch to an implementation using getType equal to the existing resolveUnionTypes function.verify()->wasCalled*(), verify()->receivedNothing()) now increase assertion counter of PHPUnitNewCallable::of() and NewCallable::stub() to callable&\bovigo\callmap\FunctionProxybovigo\callmap\NewInstance::of() and bovigo\callmap\NewInstance::stub() have the proper intersection typebovigo\callmap\ClassProxy::stub(string ...$methods) to allow stubbing of methods
on a proxy instance that otherwise forwards method calls to the original classbovigo\callmap\ClassProxy::mapCalls() and bovigo\callmap\FunctionProxy::mapCall(), deprecated since 3.2.0voidbovigo\callmap\ClassProxy::returns(), bovigo\callmap\ClassProxy::mapCalls() is now an alias for this and should be considered deprecatedbovigo\callmap\FunctionProxy::returns(), bovigo\callmap\FunctionProxy::mapCall() is now an alias for this and should be considered deprecatedbovigo\callmap\FunctionProxy::throws()call_user_func_array(), instead call functions and methods directlybovigo\callmap\throws() now accepts all instances of \Throwable, not just \Exceptionself was not used correctly and lead to a fatal error when creating callmap instances of interfaces or classes using such a return type hintbovigo\callmap\NewInstance::of() and bovigo\callmap\NewInstance::stub() now throw a bovigo\callmap\ProxyCreationFailure instead of \ReflectionException when creation of proxy failsnull called original method instead of returning nullbovigo\callmap\Verification is now automatically blacklisted in PHPUnit and will not appear in PHPUnit error stacks any moreonConsecutiveCalls() now falls back to the default return value in case a method gets invoked more often than results are definedonConsecutiveCalls() should allow callables which are executedbovigo\callmap\wrap()bovigo\callmap\verify() as possibility to verify an expected call amount as well as expected arguments\InvalidArgumentException\InvalidArgumentExceptionbovigo\callmap\Proxy::callsReceivedFor() to internal, use verify()->was*() insteadbovigo\callmap\Proxy::argumentsReceivedFor() to internal, use verify()->received*() insteadbovigo\callmap\NewInstance::*() with a final class now throws an \InvalidArgumentExceptionbovigo\callmap\Proxy::mapCalls() which doesn't exist or is not applicable for mapping now throws an \InvalidArgumentExceptionbovigo\callmap\Proxy::argumentsReceived() to bovigo\callmap\Proxy::argumentsReceivedFor()& for parameters that must be passed by referencebovigo\callmap\throws()bovigo\callmap\NewInstance::classname() to retrieve the name of the generated proxybovigo\callmap\onConsecutiveCalls() for passing a list of invocation results, removing api status from bovigo\callmap\InvocationResultsHow can I help you explore Laravel packages today?