File: DDC1719Test.php

package info (click to toggle)
doctrine 2.14.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 10,612 kB
  • sloc: php: 113,660; xml: 4,630; makefile: 28; sh: 14
file content (108 lines) | stat: -rw-r--r-- 2,710 bytes parent folder | download
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\Table;
use Doctrine\Tests\OrmFunctionalTestCase;

/** @group DDC-1719 */
class DDC1719Test extends OrmFunctionalTestCase
{
    protected function setUp(): void
    {
        parent::setUp();

        $this->createSchemaForModels(DDC1719SimpleEntity::class);
    }

    public function testCreateRetrieveUpdateDelete(): void
    {
        $e1 = new DDC1719SimpleEntity('Bar 1');
        $e2 = new DDC1719SimpleEntity('Foo 1');

        // Create
        $this->_em->persist($e1);
        $this->_em->persist($e2);
        $this->_em->flush();
        $this->_em->clear();

        $e1Id = $e1->id;
        $e2Id = $e2->id;

        // Retrieve
        $e1 = $this->_em->find(DDC1719SimpleEntity::class, $e1Id);
        $e2 = $this->_em->find(DDC1719SimpleEntity::class, $e2Id);

        self::assertInstanceOf(DDC1719SimpleEntity::class, $e1);
        self::assertInstanceOf(DDC1719SimpleEntity::class, $e2);

        self::assertEquals($e1Id, $e1->id);
        self::assertEquals($e2Id, $e2->id);

        self::assertEquals('Bar 1', $e1->value);
        self::assertEquals('Foo 1', $e2->value);

        $e1->value = 'Bar 2';
        $e2->value = 'Foo 2';

        // Update
        $this->_em->persist($e1);
        $this->_em->persist($e2);
        $this->_em->flush();

        self::assertEquals('Bar 2', $e1->value);
        self::assertEquals('Foo 2', $e2->value);

        self::assertInstanceOf(DDC1719SimpleEntity::class, $e1);
        self::assertInstanceOf(DDC1719SimpleEntity::class, $e2);

        self::assertEquals($e1Id, $e1->id);
        self::assertEquals($e2Id, $e2->id);

        self::assertEquals('Bar 2', $e1->value);
        self::assertEquals('Foo 2', $e2->value);

        // Delete
        $this->_em->remove($e1);
        $this->_em->remove($e2);
        $this->_em->flush();

        $e1 = $this->_em->find(DDC1719SimpleEntity::class, $e1Id);
        $e2 = $this->_em->find(DDC1719SimpleEntity::class, $e2Id);

        self::assertNull($e1);
        self::assertNull($e2);
    }
}

/**
 * @Entity
 * @Table(name="`ddc-1719-simple-entity`")
 */
class DDC1719SimpleEntity
{
    /**
     * @var int
     * @Id
     * @Column(type="integer", name="`simple-entity-id`")
     * @GeneratedValue(strategy="AUTO")
     */
    public $id;

    /**
     * @var string
     * @Column(type="string", name="`simple-entity-value`")
     */
    public $value;

    public function __construct(string $value)
    {
        $this->value = $value;
    }
}