File: DDC6573Test.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 (108 lines) | stat: -rw-r--r-- 3,629 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
106
107
108
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\ORM\AbstractQuery;
use Doctrine\Tests\Models\DDC6573\DDC6573Currency;
use Doctrine\Tests\Models\DDC6573\DDC6573Item;
use Doctrine\Tests\Models\DDC6573\DDC6573Money;
use Doctrine\Tests\OrmFunctionalTestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;

#[Group('DDC-6573')]
final class DDC6573Test extends OrmFunctionalTestCase
{
    /** @var list<DDC6573Item> */
    private $fixtures;

    protected function setUp(): void
    {
        parent::setUp();

        $this->createSchemaForModels(
            DDC6573Item::class,
        );

        $item1 = new DDC6573Item('Plate', new DDC6573Money(5, new DDC6573Currency('GBP')));
        $item2 = new DDC6573Item('Iron', new DDC6573Money(50, new DDC6573Currency('EUR')));
        $item3 = new DDC6573Item('Teapot', new DDC6573Money(10, new DDC6573Currency('GBP')));

        $this->_em->persist($item1);
        $this->_em->persist($item2);
        $this->_em->persist($item3);

        $this->_em->flush();
        $this->_em->clear();

        $this->fixtures = [$item1, $item2, $item3];
    }

    protected function tearDown(): void
    {
        $this->_em->createQuery('DELETE FROM Doctrine\Tests\Models\DDC6573\DDC6573Item i')->execute();
    }

    public static function provideDataForHydrationMode(): iterable
    {
        yield [AbstractQuery::HYDRATE_ARRAY];
        yield [AbstractQuery::HYDRATE_OBJECT];
    }

    #[DataProvider('provideDataForHydrationMode')]
    public function testShouldSupportsMultipleNewOperator(int $hydrationMode): void
    {
        $dql = '
            SELECT
                new Doctrine\Tests\Models\DDC6573\DDC6573Money(
                    i.priceAmount,
                    new Doctrine\Tests\Models\DDC6573\DDC6573Currency(i.priceCurrency)
                )
            FROM
                Doctrine\Tests\Models\DDC6573\DDC6573Item i
            ORDER BY
                i.priceAmount ASC';

        $query  = $this->_em->createQuery($dql);
        $result = $query->getResult($hydrationMode);

        self::assertCount(3, $result);

        self::assertInstanceOf(DDC6573Money::class, $result[0]);
        self::assertInstanceOf(DDC6573Money::class, $result[1]);
        self::assertInstanceOf(DDC6573Money::class, $result[2]);

        self::assertEquals($this->fixtures[0]->getPrice(), $result[0]);
        self::assertEquals($this->fixtures[2]->getPrice(), $result[1]);
        self::assertEquals($this->fixtures[1]->getPrice(), $result[2]);
    }

    #[DataProvider('provideDataForHydrationMode')]
    public function testShouldSupportsBasicUsage(int $hydrationMode): void
    {
        $dql = '
            SELECT
                new Doctrine\Tests\Models\DDC6573\DDC6573Currency(
                    i.priceCurrency
                )
            FROM
                Doctrine\Tests\Models\DDC6573\DDC6573Item i
            ORDER BY
                i.priceAmount';

        $query  = $this->_em->createQuery($dql);
        $result = $query->getResult($hydrationMode);

        self::assertCount(3, $result);

        self::assertInstanceOf(DDC6573Currency::class, $result[0]);
        self::assertInstanceOf(DDC6573Currency::class, $result[1]);
        self::assertInstanceOf(DDC6573Currency::class, $result[2]);

        self::assertEquals($this->fixtures[0]->getPrice()->getCurrency(), $result[0]);
        self::assertEquals($this->fixtures[1]->getPrice()->getCurrency(), $result[2]);
        self::assertEquals($this->fixtures[2]->getPrice()->getCurrency(), $result[1]);
    }
}