summaryrefslogtreecommitdiffstats
path: root/tests/Components/FieldDefinitionTest.php
blob: 11cac32d3fe49160bfeeaaf2d64470888a6b5679 (plain)
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
<?php

namespace SqlParser\Tests\Components;

use SqlParser\Parser;
use SqlParser\Components\FieldDefinition;

use SqlParser\Tests\TestCase;

class FieldDefinitionTest extends TestCase
{

    public function testParse()
    {
        $component = FieldDefinition::parse(
            new Parser(),
            $this->getTokensList('(str TEXT, FULLTEXT INDEX indx (str)')
        );
        $this->assertEquals('str', $component[0]->name);
        $this->assertEquals('FULLTEXT INDEX', $component[1]->key->type);
        $this->assertEquals('indx', $component[1]->key->name);
        $this->assertEquals('FULLTEXT INDEX `indx` (`str`)', $component[1]);
    }

    public function testBuild() {
        $parser = new Parser(
            'CREATE TABLE `payment` (' .
            '-- snippet' . "\n" .
            '`customer_id` smallint(5) unsigned NOT NULL,' .
            'CONSTRAINT `fk_payment_customer` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`customer_id`) ON UPDATE CASCADE,' .
            ') ENGINE=InnoDB")'
        );
        $this->assertEquals(
            'CONSTRAINT `fk_payment_customer` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`customer_id`) ON UPDATE CASCADE',
            FieldDefinition::build($parser->statements[0]->fields[1])
        );
    }
}