8000 [DoctrineBridge] Test reset with a true manager by MatTheCat · Pull Request #57483 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DoctrineBridge] Test reset with a true manager #57483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions src/Symfony/Bridge/Doctrine/Tests/Fixtures/DummyManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace Symfony\Bridge\Doctrine\Tests\Fixtures;

use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\Mapping\ClassMetadataFactory;
use Doctrine\Persistence\ObjectManager;
use Doctrine\Persistence\ObjectRepository;

class DummyManager implements ObjectManager
{
public $bar;

public function find($className, $id): ?object
{
}

public function persist($object): void
{
}

public function remove($object): void
{
}

public function merge($object)
{
}

public function clear($objectName = null): void
{
}

public function detach($object): void
{
}

public function refresh($object): void
{
}

public function flush(): void
{
}

public function getRepository($className): ObjectRepository
{
}

public function getClassMetadata($className): ClassMetadata
{
}

public function getMetadataFactory(): ClassMetadataFactory
{
}

public function initializeObject($obj): void
{
}

public function contains($object): bool
{
}

public function isUninitializedObject($value): bool
{
}
}
25 changes: 16 additions & 9 deletions src/Symfony/Bridge/Doctrine/Tests/ManagerRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
use ProxyManager\Proxy\LazyLoadingInterface;
use ProxyManager\Proxy\ValueHolderInterface;
use Symfony\Bridge\Doctrine\ManagerRegistry;
use Symfony\Bridge\Doctrine\Tests\Fixtures\DummyManager;
use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper;
use Symfony\Bridge\ProxyManager\Tests\LazyProxy\Dumper\PhpDumperTest;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
Expand All @@ -26,13 +26,20 @@ class ManagerRegistryTest extends TestCase
{
public static function setUpBeforeClass(): void
{
$test = new PhpDumperTest();
$test->testDumpContainerWithProxyServiceWillShareProxies();
$container = new ContainerBuilder();

$container->register('foo', DummyManager::class)->setPublic(true);
$container->getDefinition('foo')->setLazy(true);
$container->compile();

$dumper = new PhpDumper($container);
$dumper->setProxyDumper(new ProxyDumper());
eval('?>'.$dumper->dump(['class' => 'LazyServiceDoctrineBridgeContainer']));
}

public function testResetService()
{
$container = new \LazyServiceProjectServiceContainer();
$container = new \LazyServiceDoctrineBridgeContainer();

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

$this->assertSame($foo, $container->get('foo'));
$this->assertInstanceOf(\stdClass::class, $foo);
$this->assertFalse(property_exists($foo, 'bar'));
$this->assertInstanceOf(DummyManager::class, $foo);
$this->assertFalse(isset($foo->bar));
}

/**
Expand Down Expand Up @@ -77,7 +84,7 @@ public function testResetServiceWillNotNestFurtherLazyServicesWithinEachOther()

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

self::assertInstanceOf(\stdClass::class, $service);
self::assertInstanceOf(DummyManager::class, $service);
self::assertInstanceOf(LazyLoadingInterface::class, $service);
self::assertInstanceOf(ValueHolderInterface::class, $service);
self::assertFalse($service->isProxyInitialized());
Expand All @@ -91,7 +98,7 @@ public function testResetServiceWillNotNestFurtherLazyServicesWithinEachOther()
$service->initializeProxy();

$wrappedValue = $service->getWrappedValueHolderValue();
self::assertInstanceOf(\stdClass::class, $wrappedValue);
self::assertInstanceOf(DummyManager::class, $wrappedValue);
self::assertNotInstanceOf(LazyLoadingInterface::class, $wrappedValue);
self::assertNotInstanceOf(ValueHolderInterface::class, $wrappedValue);
}
Expand All @@ -104,7 +111,7 @@ private function dumpLazyServiceProjectAsFilesServiceContainer()

$container = new ContainerBuilder();

$container->register('foo', \stdClass::class)
$container->register('foo', DummyManager::class)
->setPublic(true)
->setLazy(true);
$container->compile();
Expand Down
Loading
0