/
PhpDumperTest.php
74 lines (59 loc) · 2.37 KB
/
PhpDumperTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?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 Symfony\Bridge\ProxyManager\Tests\LazyProxy\Dumper;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
/**
* Integration tests for {@see \Symfony\Component\DependencyInjection\Dumper\PhpDumper} combined
* with the ProxyManager bridge.
*
* @author Marco Pivetta <ocramius@gmail.com>
*/
class PhpDumperTest extends TestCase
{
public function testDumpContainerWithProxyService()
{
$container = new ContainerBuilder();
$container->register('foo', 'stdClass');
$container->getDefinition('foo')->setLazy(true);
$container->compile();
$dumper = new PhpDumper($container);
$dumper->setProxyDumper(new ProxyDumper());
$dumpedString = $dumper->dump();
$this->assertStringMatchesFormatFile(
__DIR__.'/../Fixtures/php/lazy_service_structure.txt',
$dumpedString,
'->dump() does generate proxy lazy loading logic.'
);
}
/**
* Verifies that the generated container retrieves the same proxy instance on multiple subsequent requests.
*/
public function testDumpContainerWithProxyServiceWillShareProxies()
{
// detecting ProxyManager v2
if (class_exists('ProxyManager\ProxyGenerator\LazyLoading\MethodGenerator\StaticProxyConstructor')) {
require_once __DIR__.'/../Fixtures/php/lazy_service_with_hints.php';
} else {
require_once __DIR__.'/../Fixtures/php/lazy_service.php';
}
$container = new \LazyServiceProjectServiceContainer();
/* @var $proxy \stdClass_c1d194250ee2e2b7d2eab8b8212368a8 */
$proxy = $container->get('foo');
$this->assertInstanceOf('stdClass_c1d194250ee2e2b7d2eab8b8212368a8', $proxy);
$this->assertSame($proxy, $container->get('foo'));
$this->assertFalse($proxy->isProxyInitialized());
$proxy->initializeProxy();
$this->assertTrue($proxy->isProxyInitialized());
$this->assertSame($proxy, $container->get('foo'));
}
}