Файл: symfony-2.7/src/Symfony/Bridge/ProxyManager/Tests/LazyProxy/ContainerBuilderTest.php
Строк: 103
<?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 SymfonyBridgeProxyManagerTestsLazyProxy;
require_once __DIR__.'/Fixtures/includes/foo.php';
use SymfonyBridgeProxyManagerLazyProxyInstantiatorRuntimeInstantiator;
use SymfonyComponentDependencyInjectionContainerBuilder;
/**
* Integration tests for {@see SymfonyComponentDependencyInjectionContainerBuilder} combined
* with the ProxyManager bridge.
*
* @author Marco Pivetta <ocramius@gmail.com>
*/
class ContainerBuilderTest extends PHPUnit_Framework_TestCase
{
/**
* @covers SymfonyComponentDependencyInjectionContainerBuilder::createService
*/
public function testCreateProxyServiceWithRuntimeInstantiator()
{
$builder = new ContainerBuilder();
$builder->setProxyInstantiator(new RuntimeInstantiator());
$builder->register('foo1', 'ProxyManagerBridgeFooClass')->setFile(__DIR__.'/Fixtures/includes/foo.php');
$builder->getDefinition('foo1')->setLazy(true);
/* @var $foo1 ProxyManagerProxyLazyLoadingInterface|ProxyManagerProxyValueHolderInterface */
$foo1 = $builder->get('foo1');
$this->assertSame($foo1, $builder->get('foo1'), 'The same proxy is retrieved on multiple subsequent calls');
$this->assertInstanceOf('ProxyManagerBridgeFooClass', $foo1);
$this->assertInstanceOf('ProxyManagerProxyLazyLoadingInterface', $foo1);
$this->assertFalse($foo1->isProxyInitialized());
$foo1->initializeProxy();
$this->assertSame($foo1, $builder->get('foo1'), 'The same proxy is retrieved after initialization');
$this->assertTrue($foo1->isProxyInitialized());
$this->assertInstanceOf('ProxyManagerBridgeFooClass', $foo1->getWrappedValueHolderValue());
$this->assertNotInstanceOf('ProxyManagerProxyLazyLoadingInterface', $foo1->getWrappedValueHolderValue());
}
}