Completed
Pull Request — master (#6485)
by Alessandro
14:15
created

GH5804Generator   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 10
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 1
dl 0
loc 10
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A generate() 0 4 1
1
<?php
2
3
namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5
use Doctrine\DBAL\Platforms\AbstractPlatform;
6
use Doctrine\ORM\EntityManager;
7
use Doctrine\ORM\Id\AbstractIdGenerator;
8
use Doctrine\Tests\Models\GH5804\GH5804Article;
9
use Doctrine\Tests\OrmFunctionalTestCase;
10
11
/**
12
 * @group 6402
13
 */
14
class GH5804Test extends OrmFunctionalTestCase
15
{
16
    protected function setUp()
17
    {
18
        $this->useModelSet('gh5804');
19
        parent::setUp();
20
    }
21
22
    public static function setUpBeforeClass()
23
    {
24
        \Doctrine\DBAL\Types\Type::addType('GH5804Type', GH5804Type::class);
25
    }
26
27
    /**
28
     * @group GH-5804
29
     */
30
    public function testTextColumnSaveAndRetrieve2()
31
    {
32
        $firstArticle = new GH5804Article;
33
        $firstArticle->text = 'Max';
34
        $this->_em->persist($firstArticle);
35
        $this->_em->flush();
36
37
        self::assertSame(1, $firstArticle->version);
38
39
        $firstArticle->text = 'Moritz';
40
        $this->_em->persist($firstArticle);
41
        $this->_em->flush();
42
43
        self::assertSame(2, $firstArticle->version);
44
    }
45
}
46
47
class GH5804Generator extends AbstractIdGenerator
48
{
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function generate(EntityManager $em, $entity)
53
    {
54
        return 'test5804';
55
    }
56
}
57
58
class GH5804Type extends \Doctrine\DBAL\Types\Type
59
{
60
    public function getName()
61
    {
62
        return 'GH5804Type';
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
69
    {
70
        return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration);
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function convertToDatabaseValue($value, AbstractPlatform $platform)
77
    {
78
        if (empty($value)) {
79
            return null;
80
        }
81
        return 'testGh5804DbValue';
82
    }
83
}
84