Skip to content

Commit e3af3f1

Browse files
committed
minor #57483 [DoctrineBridge] Test reset with a true manager (MatTheCat)
This PR was merged into the 5.4 branch. Discussion ---------- [DoctrineBridge] Test reset with a true manager | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | N/A | License | MIT Now that [assertions were added to the `AbstractManagerRegistry`](doctrine/persistence#375), the `ManagerRegistryTest` must register instances of `ObjectManager` to avoid tests failing with ``` assert(): assert($service instanceof ObjectManager) failed ``` Changes mostly come from #48484 but the ProxyManager is still used on 5.4, so beware when merging this in 6.4. Commits ------- 79b03db [DoctrineBridge] Test reset with a true manager
2 parents 53a3024 + 79b03db commit e3af3f1

File tree

2 files changed

+85
-9
lines changed

2 files changed

+85
-9
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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): void
19+
{
20+
}
21+
22+
public function remove($object): void
23+
{
24+
}
25+
26+
public function merge($object)
27+
{
28+
}
29+
30+
public function clear($objectName = null): void
31+
{
32+
}
33+
34+
public function detach($object): void
35+
{
36+
}
37+
38+
public function refresh($object): void
39+
{
40+
}
41+
42+
public function flush(): void
43+
{
44+
}
45+
46+
public function getRepository($className): ObjectRepository
47+
{
48+
}
49+
50+
public function getClassMetadata($className): ClassMetadata
51+
{
52+
}
53+
54+
public function getMetadataFactory(): ClassMetadataFactory
55+
{
56+
}
57+
58+
public function initializeObject($obj): void
59+
{
60+
}
61+
62+
public function contains($object): bool
63+
{
64+
}
65+
66+
public function isUninitializedObject($value): bool
67+
{
68+
}
69+
}

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy