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