File: DefaultQuoteStrategyTest.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 (86 lines) | stat: -rw-r--r-- 2,819 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
76
77
78
79
80
81
82
83
84
85
86
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Mapping;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Name\UnquotedIdentifierFolding;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Mapping\DefaultQuoteStrategy;
use Doctrine\Tests\Models\NonPublicSchemaJoins\User as NonPublicSchemaUser;
use Doctrine\Tests\OrmTestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\RequiresPhpunit;

use function assert;
use function enum_exists;
use function sprintf;

/**
 * Doctrine\Tests\ORM\Mapping\DefaultQuoteStrategyTest
 */
class DefaultQuoteStrategyTest extends OrmTestCase
{
    #[Group('DDC-3590')]
    #[Group('DDC-1316')]
    #[RequiresPhpunit('< 12')]
    public function testGetJoinTableName(): void
    {
        $em       = $this->getTestEntityManager();
        $metadata = $em->getClassMetadata(NonPublicSchemaUser::class);
        $strategy = new DefaultQuoteStrategy();
        $platform = $this->getMockForAbstractClass(AbstractPlatform::class, enum_exists(UnquotedIdentifierFolding::class) ? [UnquotedIdentifierFolding::UPPER] : []);
        assert($platform instanceof AbstractPlatform);

        self::assertSame(
            'readers.author_reader',
            $strategy->getJoinTableName($metadata->associationMappings['readers'], $metadata, $platform),
        );
    }

    #[DataProvider('fullTableNameProvider')]
    public function testGetTableName(string $expectedFullTableName, string $tableName): void
    {
        $classMetadata = new ClassMetadata(self::class);
        $classMetadata->setPrimaryTable(['name' => $tableName]);

        $platform = $this->createStub(AbstractPlatform::class);
        $platform->method('quoteSingleIdentifier')
            ->willReturnCallback(
                static fn (string $identifier): string => sprintf('✌️%s✌️', $identifier),
            );

        $quotedTableName = (new DefaultQuoteStrategy())->getTableName(
            $classMetadata,
            $platform,
        );

        self::assertSame($expectedFullTableName, $quotedTableName);
    }

    /** @return iterable<string, array{string, string}> */
    public static function fullTableNameProvider(): iterable
    {
        yield 'quoted table name with schema' => [
            '✌️custom✌️.✌️reserved✌️',
            'custom.`reserved`',
        ];

        yield 'unquoted table name with schema' => [
            'custom.non_reserved',
            'custom.non_reserved',
        ];

        yield 'quoted table name without schema' => [
            '✌️reserved✌️',
            '`reserved`',
        ];

        yield 'unquoted table name without schema' => [
            'non_reserved',
            'non_reserved',
        ];
    }
}