Completed
Push — 2.6 ( 46f2a4...1d71fb )
by Michael
83:49 queued 78:15
created

GH7366Entity   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getName() 0 3 1
1
<?php
2
3
namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5
use Doctrine\DBAL\LockMode;
6
use Doctrine\ORM\TransactionRequiredException;
7
use Doctrine\Tests\OrmFunctionalTestCase;
8
9
final class GH7366Test extends OrmFunctionalTestCase
10
{
11
    /**
12
     * {@inheritDoc}
13
     */
14
    protected function setUp() : void
15
    {
16
        parent::setUp();
17
18
        $this->setUpEntitySchema(
19
            [
20
                GH7366Entity::class,
21
            ]
22
        );
23
24
        $this->_em->persist(new GH7366Entity('baz'));
25
        $this->_em->flush();
26
        $this->_em->clear();
27
    }
28
29
    public function testOptimisticLockNoExceptionOnFind() : void
30
    {
31
        try {
32
            $entity = $this->_em->find(GH7366Entity::class, 1, LockMode::OPTIMISTIC);
33
        } catch (TransactionRequiredException $e) {
34
            self::fail('EntityManager::find() threw TransactionRequiredException with LockMode::OPTIMISTIC');
35
        }
36
        self::assertEquals('baz', $entity->getName());
37
    }
38
}
39
40
/**
41
 * @Entity
42
 */
43
class GH7366Entity
44
{
45
    /**
46
     * @Id
47
     * @Column(type="integer")
48
     * @GeneratedValue
49
     * @var int
50
     */
51
    public $id;
52
53
    /**
54
     * @Column(type="integer")
55
     * @Version
56
     */
57
    protected $lockVersion = 1;
58
59
    /**
60
     * @Column(length=32)
61
     * @var string
62
     */
63
    protected $name;
64
65
66
    public function __construct(string $name)
67
    {
68
        $this->name = $name;
69
    }
70
71
    public function getName(): string
72
    {
73
        return $this->name;
74
    }
75
}
76