Файл: symfony-2.7/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/PhpDumper/ProxyDumperTest.php
Строк: 130
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SymfonyBridgeProxyManagerTestsLazyProxyPhpDumper;
use SymfonyBridgeProxyManagerLazyProxyPhpDumperProxyDumper;
use SymfonyComponentDependencyInjectionDefinition;
/**
* Tests for {@see SymfonyBridgeProxyManagerLazyProxyPhpDumperProxyDumper}.
*
* @author Marco Pivetta <ocramius@gmail.com>
*
* @covers SymfonyBridgeProxyManagerLazyProxyPhpDumperProxyDumper
*/
class ProxyDumperTest extends PHPUnit_Framework_TestCase
{
/**
* @var ProxyDumper
*/
protected $dumper;
/**
* {@inheritdoc}
*/
public function setUp()
{
$this->dumper = new ProxyDumper();
}
/**
* @dataProvider getProxyCandidates
*
* @param Definition $definition
* @param bool $expected
*/
public function testIsProxyCandidate(Definition $definition, $expected)
{
$this->assertSame($expected, $this->dumper->isProxyCandidate($definition));
}
public function testGetProxyCode()
{
$definition = new Definition(__CLASS__);
$definition->setLazy(true);
$code = $this->dumper->getProxyCode($definition);
$this->assertStringMatchesFormat(
'%Aclass SymfonyBridgeProxyManagerTestsLazyProxyPhpDumperProxyDumperTest%aextends%w'
.'SymfonyBridgeProxyManagerTestsLazyProxyPhpDumperProxyDumperTest%a',
$code
);
}
public function testGetProxyFactoryCode()
{
$definition = new Definition(__CLASS__);
$definition->setLazy(true);
$code = $this->dumper->getProxyFactoryCode($definition, 'foo');
$this->assertStringMatchesFormat(
'%wif ($lazyLoad) {%w$container = $this;%wreturn $this->services['foo'] = new '
.'SymfonyBridgeProxyManagerTestsLazyProxyPhpDumperProxyDumperTest_%s(%wfunction '
.'(&$wrappedInstance, ProxyManagerProxyLazyLoadingInterface $proxy) use ($container) {'
.'%w$wrappedInstance = $container->getFooService(false);%w$proxy->setProxyInitializer(null);'
.'%wreturn true;%w}%w);%w}%w',
$code
);
}
/**
* @return array
*/
public function getProxyCandidates()
{
$definitions = array(
array(new Definition(__CLASS__), true),
array(new Definition('stdClass'), true),
array(new Definition('foo'.uniqid()), false),
array(new Definition(), false),
);
array_map(
function ($definition) {
$definition[0]->setLazy(true);
},
$definitions
);
return $definitions;
}
}