File: DDC2825Test.php

package info (click to toggle)
doctrine 3.5.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 11,552 kB
  • sloc: php: 108,302; xml: 1,340; makefile: 35; sh: 14
file content (75 lines) | stat: -rw-r--r-- 2,061 bytes parent folder | download | duplicates (2)
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
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Tests\Models\DDC2825\ExplicitSchemaAndTable;
use Doctrine\Tests\Models\DDC2825\SchemaAndTableInTableName;
use Doctrine\Tests\OrmFunctionalTestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;

/**
 * This class makes tests on the correct use of a database schema when entities are stored
 */
#[Group('DDC-2825')]
class DDC2825Test extends OrmFunctionalTestCase
{
    protected function setUp(): void
    {
        parent::setUp();

        $platform = $this->_em->getConnection()->getDatabasePlatform();

        if (! $platform->supportsSchemas()) {
            self::markTestSkipped('This test is only useful for databases that support schemas or can emulate them.');
        }
    }

    /** @param class-string $className */
    #[DataProvider('getTestedClasses')]
    public function testPersistenceOfEntityWithSchemaMapping(string $className, string $expectedSchemaName, string $expectedTableName): void
    {
        $this->createSchemaForModels($className);

        $this->_em->persist(new $className());
        $this->_em->flush();
        $this->_em->clear();

        self::assertCount(1, $this->_em->getRepository($className)->findAll());
    }

    /** @return list<array{class-string}> */
    public static function getTestedClasses(): array
    {
        return [
            [ExplicitSchemaAndTable::class],
            [SchemaAndTableInTableName::class],
            [DDC2825ClassWithImplicitlyDefinedSchemaAndQuotedTableName::class],
            [File::class],
        ];
    }
}

#[ORM\Entity]
#[ORM\Table(name: 'myschema.order')]
class DDC2825ClassWithImplicitlyDefinedSchemaAndQuotedTableName
{
    /** @var int */
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column(type: 'integer')]
    public $id;
}

#[ORM\Entity]
#[ORM\Table(name: '`file`', schema: 'yourschema')]
class File
{
    #[ORM\Id]
    #[ORM\Column]
    #[ORM\GeneratedValue]
    public int $id;
}