/** * Creates a new function prophecy using the specified function name * and arguments. * * @param string $functionName function name * @param array $arguments arguments * * @return MethodProphecy function prophecy */ public function __call($functionName, array $arguments) { $delegateBuilder = new MockDelegateFunctionBuilder(); $delegateBuilder->build($functionName); $prophecy = $this->prophet->prophesize($delegateBuilder->getFullyQualifiedClassName()); $this->revelations[] = new Revelation($this->namespace, $functionName, $prophecy); return $prophecy->__call(MockDelegateFunctionBuilder::METHOD, $arguments); }
/** * Builds a function mock. * * Disable this mock after the test with Mockery::close(). * * @param string $namespace The function namespace. * @param string $name The function name. * * @return Expectation The mockery expectation. * @SuppressWarnings(PHPMD) */ public static function mock($namespace, $name) { $delegateBuilder = new MockDelegateFunctionBuilder(); $delegateBuilder->build($name); $mockeryMock = Mockery::mock($delegateBuilder->getFullyQualifiedClassName()); $expectation = $mockeryMock->makePartial()->shouldReceive(MockDelegateFunctionBuilder::METHOD); $builder = new MockBuilder(); $builder->setNamespace($namespace)->setName($name)->setFunctionProvider($mockeryMock); $mock = $builder->build(); $mock->enable(); $disabler = new MockDisabler($mock); Mockery::getContainer()->rememberMock($disabler); return $expectation; }
/** * Returns the enabled function mock. * * This mock will be disabled automatically after the test run. * * @param string $namespace The function namespace. * @param string $name The function name. * * @return \PHPUnit_Framework_MockObject_MockObject The PHPUnit mock. */ public function getFunctionMock($namespace, $name) { $delegateBuilder = new MockDelegateFunctionBuilder(); $delegateBuilder->build($name); $mock = $this->getMockBuilder($delegateBuilder->getFullyQualifiedClassName())->getMockForAbstractClass(); $mock->__phpunit_getInvocationMocker()->addMatcher(new DefaultArgumentRemover()); $functionMockBuilder = new MockBuilder(); $functionMockBuilder->setNamespace($namespace)->setName($name)->setFunctionProvider($mock); $functionMock = $functionMockBuilder->build(); $functionMock->enable(); $this->registerForTearDown($functionMock); $proxy = new MockObjectProxy($mock); return $proxy; }