File: ComparatorTestUtils.php

package info (click to toggle)
php-doctrine-dbal 4.3.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 5,092 kB
  • sloc: php: 60,293; xml: 618; makefile: 23
file content (60 lines) | stat: -rw-r--r-- 1,786 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
<?php

declare(strict_types=1);

namespace Doctrine\DBAL\Tests\Functional\Schema;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\TableDiff;
use PHPUnit\Framework\TestCase;

final class ComparatorTestUtils
{
    /** @throws Exception */
    public static function diffFromActualToDesiredTable(
        AbstractSchemaManager $schemaManager,
        Comparator $comparator,
        Table $desiredTable,
    ): TableDiff {
        return $comparator->compareTables(
            $schemaManager->introspectTable($desiredTable->getName()),
            $desiredTable,
        );
    }

    /** @throws Exception */
    public static function diffFromDesiredToActualTable(
        AbstractSchemaManager $schemaManager,
        Comparator $comparator,
        Table $desiredTable,
    ): TableDiff {
        return $comparator->compareTables(
            $desiredTable,
            $schemaManager->introspectTable($desiredTable->getName()),
        );
    }

    public static function assertDiffNotEmpty(Connection $connection, Comparator $comparator, Table $table): void
    {
        $schemaManager = $connection->createSchemaManager();

        $diff = self::diffFromActualToDesiredTable($schemaManager, $comparator, $table);

        TestCase::assertFalse($diff->isEmpty());

        $schemaManager->alterTable($diff);

        TestCase::assertTrue(
            self::diffFromActualToDesiredTable($schemaManager, $comparator, $table)
                ->isEmpty(),
        );
        TestCase::assertTrue(
            self::diffFromDesiredToActualTable($schemaManager, $comparator, $table)
                ->isEmpty(),
        );
    }
}