summaryrefslogtreecommitdiffstats
path: root/tests/mocks/database/schema
diff options
context:
space:
mode:
authorAndrey Andreev <narf@bofh.bg>2012-04-27 11:18:26 +0200
committerAndrey Andreev <narf@bofh.bg>2012-04-27 11:18:26 +0200
commit1fcce9667fe8d1925a36549e22124411f5828230 (patch)
tree56e5cb2c50831a50b7c79ea216645846ea59e8ab /tests/mocks/database/schema
parentb8949fab60082e17f219fc89c6c8a85d3ff73f19 (diff)
parentced2c9ab41450cb632c042730604111ec2a24e1f (diff)
Merge branch 'develop' of github.com:EllisLab/CodeIgniter into develop-db-mssql
Diffstat (limited to 'tests/mocks/database/schema')
-rw-r--r--tests/mocks/database/schema/.gitkeep0
-rw-r--r--tests/mocks/database/schema/skeleton.php98
2 files changed, 98 insertions, 0 deletions
diff --git a/tests/mocks/database/schema/.gitkeep b/tests/mocks/database/schema/.gitkeep
deleted file mode 100644
index e69de29bb..000000000
--- a/tests/mocks/database/schema/.gitkeep
+++ /dev/null
diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php
new file mode 100644
index 000000000..a3d5bac65
--- /dev/null
+++ b/tests/mocks/database/schema/skeleton.php
@@ -0,0 +1,98 @@
+<?php
+
+class Mock_Database_Schema_Skeleton {
+
+ /**
+ * @var object Database Holder
+ */
+ public static $db;
+
+ /**
+ * @var object Forge Holder
+ */
+ public static $forge;
+
+ /**
+ * @var object Driver Holder
+ */
+ public static $driver;
+
+ /**
+ * Initialize both database and forge components
+ */
+ public static function init($driver)
+ {
+ if (empty(static::$db) && empty(static::$forge))
+ {
+ $config = Mock_Database_DB::config($driver);
+ $connection = new Mock_Database_DB($config);
+ $db = Mock_Database_DB::DB($connection->set_dsn($driver), TRUE);
+
+ CI_TestCase::instance()->ci_instance_var('db', $db);
+
+ $loader = new Mock_Core_Loader();
+ $loader->dbforge();
+ $forge = CI_TestCase::instance()->ci_instance_var('dbforge');
+
+ static::$db = $db;
+ static::$forge = $forge;
+ static::$driver = $driver;
+ }
+
+ return static::$db;
+ }
+
+
+ /**
+ * Create the dummy tables
+ *
+ * @return void
+ */
+ public static function create_tables()
+ {
+ // Job Table
+ static::$forge->add_field(array(
+ 'id' => array(
+ 'type' => 'INTEGER',
+ 'constraint' => 3,
+ ),
+ 'name' => array(
+ 'type' => 'VARCHAR',
+ 'constraint' => 40,
+ ),
+ 'description' => array(
+ 'type' => 'TEXT',
+ ),
+ ));
+ static::$forge->add_key('id', TRUE);
+ static::$forge->create_table('job', (strpos(static::$driver, 'pgsql') === FALSE));
+ }
+
+ /**
+ * Create the dummy datas
+ *
+ * @return void
+ */
+ public static function create_data()
+ {
+ // Job Data
+ $data = array(
+ 'job' => array(
+ array('id' => 1, 'name' => 'Developer', 'description' => 'Awesome job, but sometimes makes you bored'),
+ array('id' => 2, 'name' => 'Politician', 'description' => 'This is not really a job'),
+ array('id' => 3, 'name' => 'Accountant', 'description' => 'Boring job, but you will get free snack at lunch'),
+ array('id' => 4, 'name' => 'Musician', 'description' => 'Only Coldplay can actually called Musician'),
+ ),
+ );
+
+ foreach ($data as $table => $dummy_data)
+ {
+ static::$db->truncate($table);
+
+ foreach ($dummy_data as $single_dummy_data)
+ {
+ static::$db->insert($table, $single_dummy_data);
+ }
+ }
+ }
+} \ No newline at end of file