File: GH7006Test.php

package info (click to toggle)
doctrine 3.3.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 11,236 kB
  • sloc: php: 105,633; xml: 1,312; makefile: 35; sh: 14
file content (105 lines) | stat: -rw-r--r-- 2,748 bytes parent folder | download | duplicates (3)
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
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Tests\OrmFunctionalTestCase;

class GH7006Test extends OrmFunctionalTestCase
{
    protected function setUp(): void
    {
        parent::setUp();

        $this->createSchemaForModels(GH7006Book::class, GH7006PCT::class, GH7006PCTFee::class);
    }

    public function testIssue(): void
    {
        $book               = new GH7006Book();
        $book->exchangeCode = 'first';
        $this->_em->persist($book);

        $book->exchangeCode = 'second'; // change sth.

        $paymentCardTransaction       = new GH7006PCT();
        $paymentCardTransaction->book = $book;
        $paymentCardTransactionFee    = new GH7006PCTFee($paymentCardTransaction);

        $this->_em->persist($paymentCardTransaction);

        $this->_em->flush();

        self::assertIsInt($book->id);
        self::assertIsInt($paymentCardTransaction->id);
        self::assertIsInt($paymentCardTransactionFee->id);
    }
}

#[ORM\Entity]
class GH7006Book
{
    /** @var int */
    #[ORM\Id]
    #[ORM\Column(type: 'integer')]
    #[ORM\GeneratedValue(strategy: 'AUTO')]
    public $id;

    /** @var string */
    #[ORM\Column(type: 'string', length: 255, nullable: true)]
    public $exchangeCode;

    /** @var GH7006PCT */
    #[ORM\OneToOne(targetEntity: GH7006PCT::class, cascade: ['persist', 'remove'])]
    #[ORM\JoinColumn(name: 'paymentCardTransactionId', referencedColumnName: 'id')]
    public $paymentCardTransaction;
}

#[ORM\Entity]
class GH7006PCT
{
    /** @var int */
    #[ORM\Id]
    #[ORM\Column(type: 'integer')]
    #[ORM\GeneratedValue(strategy: 'AUTO')]
    public $id;

    /** @var GH7006Book */
    #[ORM\ManyToOne(targetEntity: GH7006Book::class)]
    #[ORM\JoinColumn(name: 'bookingId', referencedColumnName: 'id', nullable: false)]
    public $book;

    /** @var Collection<int, GH7006PCTFee> */
    #[ORM\OneToMany(targetEntity: GH7006PCTFee::class, mappedBy: 'pct', cascade: ['persist', 'remove'])]
    #[ORM\OrderBy(['id' => 'ASC'])]
    public $fees;

    public function __construct()
    {
        $this->fees = new ArrayCollection();
    }
}

#[ORM\Entity]
class GH7006PCTFee
{
    /** @var int */
    #[ORM\Id]
    #[ORM\Column(type: 'integer')]
    #[ORM\GeneratedValue(strategy: 'AUTO')]
    public $id;

    /** @var GH7006PCT */
    #[ORM\ManyToOne(targetEntity: GH7006PCT::class, inversedBy: 'fees')]
    #[ORM\JoinColumn(name: 'paymentCardTransactionId', referencedColumnName: 'id', nullable: false)]
    public $pct;

    public function __construct(GH7006PCT $pct)
    {
        $this->pct = $pct;
        $pct->fees->add($this);
    }
}