Passed
Pull Request — 2.6 (#7296)
by Michael
09:12
created

GH7286Test   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A testLockModeIsRespected() 0 24 1
1
<?php
2
3
namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5
use Doctrine\Tests\OrmFunctionalTestCase;
6
7
final class GH7286Test extends OrmFunctionalTestCase
8
{
9
    /**
10
     * {@inheritDoc}
11
     */
12
    protected function setUp()
13
    {
14
        parent::setUp();
15
16
        $this->setUpEntitySchema(
17
            [
18
                GH7286Entity::class,
19
            ]
20
        );
21
    }
22
23
    public function testLockModeIsRespected()
24
    {
25
        $entityA = new GH7286Entity('foo', 1);
26
        $entityB = new GH7286Entity('foo', 2);
27
        $entityC = new GH7286Entity('bar', 3);
28
29
        $this->_em->persist($entityA);
30
        $this->_em->persist($entityB);
31
        $this->_em->persist($entityC);
32
        $this->_em->flush();
33
        $this->_em->clear();
34
35
        $query = $this->_em->createQuery(
36
            'SELECT CONCAT(e.type, MIN(e.version)) pair'
37
            . ' FROM ' . GH7286Entity::class . ' e'
38
            . ' GROUP BY e.type ORDER BY e.type'
39
        );
40
41
        self::assertSame(
42
            [
43
                ['pair' => 'bar3'],
44
                ['pair' => 'foo1'],
45
            ],
46
            $query->getArrayResult()
47
        );
48
    }
49
}
50
51
/**
52
 * @Entity
53
 */
54
class GH7286Entity
55
{
56
    /**
57
     * @Id
58
     * @Column(type="integer")
59
     * @GeneratedValue
60
     * @var int
61
     */
62
    public $id;
63
64
    /**
65
     * @Column
66
     * @var string
67
     */
68
    public $type;
69
70
    /**
71
     * @Column(type="integer")
72
     * @var int
73
     */
74
    public $version;
75
76
    public function __construct(string $type, int $version)
77
    {
78
        $this->type    = $type;
79
        $this->version = $version;
80
    }
81
}
82