Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 91 lines (76 sloc) 3.574 kb
dd7436b @iarna import from OLB SVN
iarna authored
1 #!/usr/bin/env php
2 <?php
3 /**
4 * Copyright © 2011 Online Buddies, Inc. - All Rights Reserved
5 *
c52a016 @iarna phpdoc package name updates
iarna authored
6 * @package Modyllic
dd7436b @iarna import from OLB SVN
iarna authored
7 * @author bturner@online-buddies.com
8 */
9
136d06b @iarna delete now unused lime tests. Add "make test" target.
iarna authored
10 require_once dirname(__FILE__)."/../testlib/testmore.php";
dd7436b @iarna import from OLB SVN
iarna authored
11
6cb56f2 @iarna Fix test counts
iarna authored
12 plan(29);
dd7436b @iarna import from OLB SVN
iarna authored
13
7f40e17 @iarna Load the specific classes we need for the tests
iarna authored
14 require_ok("Modyllic/Parser.php");
dd7436b @iarna import from OLB SVN
iarna authored
15
c2d73cd @iarna A handful of missing renames for SQL->Modyllic
iarna authored
16 $parser = new Modyllic_Parser();
dd7436b @iarna import from OLB SVN
iarna authored
17
18 $sql = <<<EOSQL
19 CREATE TABLE test ( id INT );
20 CREATE TABLE test2 ( id INT );
21 EOSQL;
22
adb5dbf @iarna Fix bug in how dynamically named indexes were emitted. Now use the na…
iarna authored
23 $schema = $parser->parse( $sql );
dd7436b @iarna import from OLB SVN
iarna authored
24
b605f42 @iarna Switch to testmore.php, for testing which is both simpler and actuall…
iarna authored
25 diag("Tests of the first schema" );
dd7436b @iarna import from OLB SVN
iarna authored
26
adb5dbf @iarna Fix bug in how dynamically named indexes were emitted. Now use the na…
iarna authored
27 ok( $schema instanceOf Modyllic_Schema, "Parse returns an Modyllic_Schema object" );
dd7436b @iarna import from OLB SVN
iarna authored
28
adb5dbf @iarna Fix bug in how dynamically named indexes were emitted. Now use the na…
iarna authored
29 is( count($schema->tables), 2, "Parsed two table" );
30 is( count($schema->routines), 0, "Parsed no routines" );
dd7436b @iarna import from OLB SVN
iarna authored
31
adb5dbf @iarna Fix bug in how dynamically named indexes were emitted. Now use the na…
iarna authored
32 $test_table = $schema->tables['test'];
c2d73cd @iarna A handful of missing renames for SQL->Modyllic
iarna authored
33 ok( $test_table instanceOf Modyllic_Table, "We got an Modyllic_Schema_Table object for the table test" );
b605f42 @iarna Switch to testmore.php, for testing which is both simpler and actuall…
iarna authored
34 is( $test_table->name, "test", "The name attribute got set" );
35 is( $test_table->engine, "InnoDB", "The default engine got set" );
36 is( $test_table->charset, "utf8", "The default charset got set" );
37 is( count($test_table->columns), 1, "One column found" );
38 is( count($test_table->indexes), 0, "No indexes found" );
dd7436b @iarna import from OLB SVN
iarna authored
39 $column = $test_table->columns['id'];
c2d73cd @iarna A handful of missing renames for SQL->Modyllic
iarna authored
40 ok( $column instanceOf Modyllic_Column, "Column id isa Modyllic_Column" );
b605f42 @iarna Switch to testmore.php, for testing which is both simpler and actuall…
iarna authored
41 is( $column->name, "id", "Column name set" );
42 is( count($column->aliases), 0, "No aliases" );
c2d73cd @iarna A handful of missing renames for SQL->Modyllic
iarna authored
43 ok( $column->type instanceOf Modyllic_Integer, "Column type set" );
b605f42 @iarna Switch to testmore.php, for testing which is both simpler and actuall…
iarna authored
44 ok( $column->null, "Column is nullable by default" );
45 is( $column->default, "NULL", "Column is nullable and therefor has an implicit default of NULL" );
46 ok( ! $column->auto_increment, "Column is not autoincrement" );
47 ok( is_null($column->on_update), "No on update" );
48 is( $column->docs, "", "No docs" );
49 is( $column->after, "", "Column is the first column" );
dd7436b @iarna import from OLB SVN
iarna authored
50
adb5dbf @iarna Fix bug in how dynamically named indexes were emitted. Now use the na…
iarna authored
51 $sql = <<<EOSQL
dd7436b @iarna import from OLB SVN
iarna authored
52 CREATE TABLE test (
adb5dbf @iarna Fix bug in how dynamically named indexes were emitted. Now use the na…
iarna authored
53 id INT,
54 KEY (id)
dd7436b @iarna import from OLB SVN
iarna authored
55 ) ENGINE=InnoDB
56 EOSQL;
adb5dbf @iarna Fix bug in how dynamically named indexes were emitted. Now use the na…
iarna authored
57 $schema = $parser->parse($sql);
58 $table = $schema->tables['test'];
59 $index = array_pop($table->indexes);
60 is( $index->name, "id", "Generated index name is correct");
61 is( $index->dynamic_name, true, "Generated index name is flagged as dynamic");
3cd72f9 @iarna Improve error messages for invalid delimiters (#82)
iarna authored
62
63 $msg = "Trailing words on DELIMITERs produce reasonable error messages";
64 try {
65 $sql = 'DELIMITER ; |';
66 $schema = $parser->parse($sql);
67 fail($msg);
68 }
69 catch (Modyllic_Exception $e) {
70 if ( ! ok( ! preg_match("/Modyllic_Token/",$e->getMessage()), $msg ) ) {
71 foreach (explode("\n",$e->getMessage()) as $line) {
72 diag($line);
73 }
74 }
75 }
1e70bec @iarna Allow loading of schema pointed to by symlinks
iarna authored
76
77 require_once "Modyllic/Loader.php";
78
79 list( $source, $loader ) = Modyllic_Loader::determine_loader( dirname(__FILE__)."/test_schema/test1.sql" );
80 is( $loader, "Modyllic_Loader_File", "Plain file schema are loaded with File" );
81 list( $source, $loader ) = Modyllic_Loader::determine_loader( dirname(__FILE__)."/test_schema/test2.sql" );
82 is( $loader, "Modyllic_Loader_File", "Symlinks to plain file schema are loaded with File" );
83 list( $source, $loader ) = Modyllic_Loader::determine_loader( dirname(__FILE__)."/test_schema/test3" );
84 is( $loader, "Modyllic_Loader_Dir", "Directory schema are loaded with Dir" );
85 list( $source, $loader ) = Modyllic_Loader::determine_loader( dirname(__FILE__)."/test_schema/test4" );
86 is( $loader, "Modyllic_Loader_Dir", "Symlinks to directory schema are loaded with Dir" );
87 list( $source, $loader ) = Modyllic_Loader::determine_loader( "mysql:dbname=test" );
88 is( $loader, "Modyllic_Loader_DB", "DSN schema are loaded with DB" );
89 list( $source, $loader ) = Modyllic_Loader::determine_loader( dirname(__FILE__)."/test_schema/invalid" );
90 is( $loader, null, "Invalid schema result in no loader" );
Something went wrong with that request. Please try again.