File: StatementParserTest.php

package info (click to toggle)
php-horde-db 2.1.4-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 884 kB
  • ctags: 2,259
  • sloc: php: 8,675; xml: 804; sql: 22; sh: 11; makefile: 2
file content (34 lines) | stat: -rw-r--r-- 1,341 bytes parent folder | download | duplicates (6)
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
<?php
class Horde_Db_StatementParserTest extends Horde_Test_Case
{
    public function testParserFindsMultilineCreateStatement()
    {
        $expected = array(
            'DROP TABLE IF EXISTS `exp_actions`',
            'SET @saved_cs_client     = @@character_set_client',
            'SET character_set_client = utf8',
            'CREATE TABLE `exp_actions` (
              `action_id` int(4) unsigned NOT NULL auto_increment,
              `class` varchar(50) NOT NULL,
              `method` varchar(50) NOT NULL,
              PRIMARY KEY  (`action_id`)
            ) ENGINE=MyISAM AUTO_INCREMENT=20 DEFAULT CHARSET=latin1',
            'SET character_set_client = @saved_cs_client',
        );
        $this->assertParser($expected, 'drop_create_table.sql');
    }

    public function assertParser(array $expectedStatements, $filename)
    {
        $file = new SplFileObject(__DIR__ . '/fixtures/' . $filename, 'r');
        $parser = new Horde_Db_StatementParser($file);

        foreach ($expectedStatements as $i => $expected) {
            // Strip any whitespace before comparing the strings.
            $this->assertEquals(preg_replace('/\s/', '', $expected),
                                preg_replace('/\s/', '', $parser->next()),
                                "Parser differs on statement #$i");
        }
    }

}