Completed
Pull Request — master (#6485)
by Alessandro
24:54
created

GH5804Test::testTextColumnSaveAndRetrieve2()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 0
1
<?php
2
3
namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5
use Doctrine\DBAL\Types\Type as DBALType;
6
use Doctrine\Tests\DbalTypes\GH5804Type;
7
use Doctrine\Tests\Models\GH5804\GH5804Article;
8
use Doctrine\Tests\OrmFunctionalTestCase;
9
10
/**
11
 * @group 6402
12
 */
13
class GH5804Test extends OrmFunctionalTestCase
14
{
15
    protected function setUp()
16
    {
17
        $this->useModelSet('gh5804');
18
        $this->registerType(GH5804Type::class);
19
20
        parent::setUp();
21
    }
22
23
    /**
24
     * @group GH-5804
25
     */
26
    public function testTextColumnSaveAndRetrieve2()
27
    {
28
        $firstArticle = new GH5804Article;
29
        $firstArticle->text = 'Max';
30
        $this->_em->persist($firstArticle);
31
        $this->_em->flush();
32
33
        self::assertSame(1, $firstArticle->version);
34
35
        $firstArticle->text = 'Moritz';
36
        $this->_em->persist($firstArticle);
37
        $this->_em->flush();
38
39
        self::assertSame(2, $firstArticle->version);
40
    }
41
42
    /**
43
     * @param string $className
44
     *
45
     * @throws \Doctrine\DBAL\DBALException
46
     *
47
     * @return void
48
     */
49
    private function registerType(string $className)
50
    {
51
        $type = constant($className . '::NAME');
52
53
        if (DBALType::hasType($type)) {
54
            DBALType::overrideType($type, $className);
55
            return;
56
        }
57
58
        DBALType::addType($type, $className);
59
    }
60
}
61