Skip to content

Commit 0108e45

Browse files
alongoszclaude
andcommitted
[Tests] Added coverage for SiteAccessAwareEntityManager::find()
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 5b68b8c commit 0108e45

1 file changed

Lines changed: 68 additions & 0 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Ibexa\Tests\Core\Persistence\Doctrine;
10+
11+
use Doctrine\DBAL\LockMode;
12+
use Doctrine\ORM\EntityManagerInterface;
13+
use Ibexa\Bundle\Core\Entity\EntityManagerFactory;
14+
use Ibexa\Core\Persistence\Doctrine\SiteAccessAwareEntityManager;
15+
use PHPUnit\Framework\TestCase;
16+
use stdClass;
17+
18+
final class SiteAccessAwareEntityManagerTest extends TestCase
19+
{
20+
/** @var \Doctrine\ORM\EntityManagerInterface&\PHPUnit\Framework\MockObject\MockObject */
21+
private EntityManagerInterface $wrappedEntityManager;
22+
23+
private SiteAccessAwareEntityManager $entityManager;
24+
25+
protected function setUp(): void
26+
{
27+
$this->wrappedEntityManager = $this->createMock(EntityManagerInterface::class);
28+
29+
$entityManagerFactory = $this->createMock(EntityManagerFactory::class);
30+
$entityManagerFactory
31+
->method('getEntityManager')
32+
->willReturn($this->wrappedEntityManager);
33+
34+
$this->entityManager = new SiteAccessAwareEntityManager($entityManagerFactory);
35+
}
36+
37+
public function testFindForwardsLockModeAndLockVersion(): void
38+
{
39+
$entity = new stdClass();
40+
41+
$this->wrappedEntityManager
42+
->expects(self::once())
43+
->method('find')
44+
->with(stdClass::class, 1, LockMode::PESSIMISTIC_WRITE, 2)
45+
->willReturn($entity);
46+
47+
self::assertSame(
48+
$entity,
49+
$this->entityManager->find(stdClass::class, 1, LockMode::PESSIMISTIC_WRITE, 2)
50+
);
51+
}
52+
53+
public function testFindWithoutLockArgumentsForwardsNullDefaults(): void
54+
{
55+
$entity = new stdClass();
56+
57+
$this->wrappedEntityManager
58+
->expects(self::once())
59+
->method('find')
60+
->with(stdClass::class, 1, null, null)
61+
->willReturn($entity);
62+
63+
self::assertSame(
64+
$entity,
65+
$this->entityManager->find(stdClass::class, 1)
66+
);
67+
}
68+
}

0 commit comments

Comments
 (0)