/** * Replaces the parameters within the given $methodInvocation with type-safe interface jails, whenever applicable * * @param AbstractMethodInvocation $methodInvocation * * @return void * * @throws ExceptionInterface * @throws HierarchyException */ public function __invoke(AbstractMethodInvocation $methodInvocation) { $method = $methodInvocation->getMethod(); $arguments =& Closure::bind(function &(AbstractMethodInvocation $methodInvocation) { return $methodInvocation->arguments; }, null, AbstractMethodInvocation::class)->__invoke($methodInvocation); foreach ($arguments as $parameterIndex => &$argument) { if (null === $argument) { continue; } if (!($interface = $this->getParameterInterfaceType($parameterIndex, $method))) { continue; } $argument = $this->jailFactory->createInstanceJail($argument, $interface); } }
public function testWillSkipWhenReflectionMethodIsUnavailable() { $parameters = [new \stdClass(), new \stdClass()]; /* @var $methodInvocation AbstractMethodInvocation|\PHPUnit_Framework_MockObject_MockObject */ $methodInvocation = $this->getMockForAbstractClass(AbstractMethodInvocation::class, [], '', false); $invocationArgs = new ReflectionProperty(AbstractMethodInvocation::class, 'arguments'); $invocationArgs->setAccessible(true); $invocationArgs->setValue($methodInvocation, $parameters); $this->jailFactory->expects($this->never())->method('createInstanceJail'); $this->jailer->__invoke($methodInvocation); $this->assertSame($parameters, $invocationArgs->getValue($methodInvocation)); }
public function createAggregateJail($aggregate, $typeOrAlias) { $type = $this->typeAliasManager->getType($typeOrAlias) ?: $typeOrAlias; return $this->jailFactory->createAggregateJail($aggregate, $type); }
public function testCreateProxyFromAProxy() { $proxy = $this->createMock(ProxyInterface::class); $this->assertSame($proxy, $this->factory->createInstanceJail($proxy, ProxyInterface::class)); }
public function testCreateProxyFromAProxy() { $proxy = $this->factory->createInstanceJail(new BaseClass(), BaseClass::class); $this->assertNotNull($proxy, $this->factory->createInstanceJail($proxy, BaseClass::class)); }