Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e5e9457

Browse files
committed
[DoctrineBridge] Test reset with a true manager
1 parent 53a3024 commit e5e9457

File tree

2 files changed

+81
-9
lines changed

2 files changed

+81
-9
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace Symfony\Bridge\Doctrine\Tests\Fixtures;
4+
5+
use Doctrine\Persistence\Mapping\ClassMetadata;
6+
use Doctrine\Persistence\Mapping\ClassMetadataFactory;
7+
use Doctrine\Persistence\ObjectManager;
8+
use Doctrine\Persistence\ObjectRepository;
9+
10+
class DummyManager implements ObjectManager
11+
{
12+
public $bar;
13+
14+
public function find($className, $id): ?object
15+
{
16+
}
17+
18+
public function persist(object $object): void
19+
{
20+
}
21+
22+
public function remove(object $object): void
23+
{
24+
}
25+
26+
public function clear(): void
27+
{
28+
}
29+
30+
public function detach(object $object): void
31+
{
32+
}
33+
34+
public function refresh(object $object): void
35+
{
36+
}
37+
38+
public function flush(): void
39+
{
40+
}
41+
42+
public function getRepository(string $className): ObjectRepository
43+
{
44+
}
45+
46+
public function getClassMetadata(string $className): ClassMetadata
47+
{
48+
}
49+
50+
public function getMetadataFactory(): ClassMetadataFactory
51+
{
52+
}
53+
54+
public function initializeObject(object $obj): void
55+
{
56+
}
57+
58+
public function contains(object $object): bool
59+
{
60+
}
61+
62+
public function isUninitializedObject($value): bool
63+
{
64+
}
65+
}

src/Symfony/Bridge/Doctrine/Tests/ManagerRegistryTest.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
use ProxyManager\Proxy\LazyLoadingInterface;
1616
use ProxyManager\Proxy\ValueHolderInterface;
1717
use Symfony\Bridge\Doctrine\ManagerRegistry;
18+
use Symfony\Bridge\Doctrine\Tests\Fixtures\DummyManager;
1819
use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper;
19-
use Symfony\Bridge\ProxyManager\Tests\LazyProxy\Dumper\PhpDumperTest;
2020
use Symfony\Component\DependencyInjection\ContainerBuilder;
2121
use Symfony\Component\DependencyInjection\ContainerInterface;
2222
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
@@ -26,13 +26,20 @@ class ManagerRegistryTest extends TestCase
2626
{
2727
public static function setUpBeforeClass(): void
2828
{
29-
$test = new PhpDumperTest();
30-
$test->testDumpContainerWithProxyServiceWillShareProxies();
29+
$container = new ContainerBuilder();
30+
31+
$container->register('foo', DummyManager::class)->setPublic(true);
32+
$container->getDefinition('foo')->setLazy(true);
33+
$container->compile();
34+
35+
$dumper = new PhpDumper($container);
36+
$dumper->setProxyDumper(new ProxyDumper());
37+
eval('?>'.$dumper->dump(['class' => 'LazyServiceDoctrineBridgeContainer']));
3138
}
3239

3340
public function testResetService()
3441
{
35-
$container = new \LazyServiceProjectServiceContainer();
42+
$container = new \LazyServiceDoctrineBridgeContainer();
3643

3744
$registry = new TestManagerRegistry('name', [], ['defaultManager' => 'foo'], 'defaultConnection', 'defaultManager', 'proxyInterfaceName');
3845
$registry->setTestContainer($container);
@@ -44,8 +51,8 @@ public function testResetService()
4451
$registry->resetManager();
4552

4653
$this->assertSame($foo, $container->get('foo'));
47-
$this->assertInstanceOf(\stdClass::class, $foo);
48-
$this->assertFalse(property_exists($foo, 'bar'));
54+
$this->assertInstanceOf(DummyManager::class, $foo);
55+
$this->assertFalse(isset($foo->bar));
4956
}
5057

5158
/**
@@ -77,7 +84,7 @@ public function testResetServiceWillNotNestFurtherLazyServicesWithinEachOther()
7784

7885
$service = $container->get('foo');
7986

80-
self::assertInstanceOf(\stdClass::class, $service);
87+
self::assertInstanceOf(DummyManager::class, $service);
8188
self::assertInstanceOf(LazyLoadingInterface::class, $service);
8289
self::assertInstanceOf(ValueHolderInterface::class, $service);
8390
self::assertFalse($service->isProxyInitialized());
@@ -91,7 +98,7 @@ public function testResetServiceWillNotNestFurtherLazyServicesWithinEachOther()
9198
$service->initializeProxy();
9299

93100
$wrappedValue = $service->getWrappedValueHolderValue();
94-
self::assertInstanceOf(\stdClass::class, $wrappedValue);
101+
self::assertInstanceOf(DummyManager::class, $wrappedValue);
95102
self::assertNotInstanceOf(LazyLoadingInterface::class, $wrappedValue);
96103
self::assertNotInstanceOf(ValueHolderInterface::class, $wrappedValue);
97104
}
@@ -104,7 +111,7 @@ private function dumpLazyServiceProjectAsFilesServiceContainer()
104111

105112
$container = new ContainerBuilder();
106113

107-
$container->register('foo', \stdClass::class)
114+
$container->register('foo', DummyManager::class)
108115
->setPublic(true)
109116
->setLazy(true);
110117
$container->compile();

0 commit comments

Comments
 (0)