Skip to content

Commit

Permalink
change test to use a real ObjectManager
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh committed Jun 22, 2024
1 parent 6a4d229 commit 0fc7293
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
26 changes: 17 additions & 9 deletions src/Symfony/Bridge/Doctrine/Tests/LegacyManagerRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@

namespace Symfony\Bridge\Doctrine\Tests;

use Doctrine\Persistence\ObjectManager;
use PHPUnit\Framework\TestCase;
use ProxyManager\Proxy\LazyLoadingInterface;
use ProxyManager\Proxy\ValueHolderInterface;
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 @@ -28,9 +29,16 @@ class LegacyManagerRegistryTest extends TestCase
{
public static function setUpBeforeClass(): void
{
if (!class_exists(\LazyServiceProjectServiceContainer::class, false)) {
eval('?>'.PhpDumperTest::dumpLazyServiceProjectServiceContainer());
}
$container = new ContainerBuilder();

$container->register('foo', DummyManager::class)->setPublic(true);
$container->getDefinition('foo')->setLazy(true)->addTag('proxy', ['interface' => ObjectManager::class]);
$container->compile();

$dumper = new PhpDumper($container);
$dumper->setProxyDumper(new ProxyDumper());

eval('?>'.$dumper->dump(['class' => 'LazyServiceProjectServiceContainer']));
}

public function testResetService()
Expand All @@ -47,8 +55,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(ObjectManager::class, $foo);
$this->assertFalse(isset($foo->bar));
}

/**
Expand Down Expand Up @@ -80,7 +88,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 @@ -94,7 +102,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 @@ -107,7 +115,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
4 changes: 0 additions & 4 deletions src/Symfony/Bridge/Doctrine/Tests/ManagerRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@

use Doctrine\Persistence\ObjectManager;
use PHPUnit\Framework\TestCase;
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\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
Expand Down

0 comments on commit 0fc7293

Please sign in to comment.