-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
109 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Bundle\MongoDBBundle\Tests; | ||
|
||
use Doctrine\Bundle\MongoDBBundle\ManagerRegistry; | ||
use Doctrine\ODM\MongoDB\DocumentManager; | ||
use Doctrine\Persistence\ObjectManager; | ||
use MongoDBManagerRepositoryTestResetContainer; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Dumper\PhpDumper; | ||
|
||
class ManagerRegistryTest extends TestCase | ||
{ | ||
public function testReset(): void | ||
{ | ||
$container = new ContainerBuilder(); | ||
$container->register('manager.default', DocumentManagerStub::class) | ||
->setPublic(true); | ||
$container->register('manager.lazy', DocumentManagerStub::class) | ||
->setPublic(true) | ||
->setLazy(true) | ||
->addTag('proxy', ['interface' => ObjectManager::class]); | ||
$container->compile(); | ||
|
||
$dumper = new PhpDumper($container); | ||
eval('?' . '>' . $dumper->dump(['class' => 'MongoDBManagerRepositoryTestResetContainer'])); | ||
|
||
$container = new MongoDBManagerRepositoryTestResetContainer(); | ||
$repository = new ManagerRegistry('MongoDB', [], [ | ||
'default' => 'manager.default', | ||
'lazy' => 'manager.lazy', | ||
], '', '', '', $container); | ||
Check failure on line 34 in tests/ManagerRegistryTest.php GitHub Actions / Static Analysis with Psalm (8.2)InvalidArgument
|
||
|
||
DocumentManagerStub::$clearCount = 0; | ||
|
||
$repository->reset(); | ||
|
||
// Service was not initialized, so reset should not be called | ||
$this->assertSame(0, DocumentManagerStub::$clearCount); | ||
Check failure on line 41 in tests/ManagerRegistryTest.php GitHub Actions / Static Analysis with Psalm (8.2)RedundantCondition
|
||
|
||
// The lazy service is reinitialized instead of being cleared | ||
$container->get('manager.lazy')->flush(); | ||
$repository->reset(); | ||
$this->assertSame(0, DocumentManagerStub::$clearCount); | ||
|
||
// The default service is cleared when initialized | ||
$container->get('manager.default')->flush(); | ||
$repository->reset(); | ||
$this->assertSame(1, DocumentManagerStub::$clearCount); | ||
} | ||
} | ||
|
||
class DocumentManagerStub extends DocumentManager | ||
{ | ||
public static int $clearCount; | ||
|
||
public function __construct() | ||
{ | ||
} | ||
|
||
public function clear($objectName = null): void | ||
Check failure on line 63 in tests/ManagerRegistryTest.php GitHub Actions / Coding Standards / Coding Standards (8.3)
|
||
{ | ||
self::$clearCount++; | ||
} | ||
|
||
public function flush(array $options = []): void | ||
{ | ||
} | ||
} |