Task_DB_Test_Load::_execute()   B
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 28
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 8.8571
c 0
b 0
f 0
nc 2
cc 3
eloc 19
nop 1
1
<?php defined('SYSPATH') OR die('No direct script access.');
2
3
/**
4
 * Load the latest structure to the test database.
5
 * Will also load all the sql files from test/test_data/structure/test-schema-<type>.sql
6
 * where <type> is based on the test database type.
7
 */
8
class Task_DB_Test_Load extends Minion_Database {
9
10
	protected function _execute(array $options)
11
	{
12
		$db = $this->db_params(Kohana::TESTING);
13
14
		Minion_Task::factory(array(
15
				'task' => 'db:structure:load',
16
				'database' => Kohana::TESTING,
17
				'force' => NULL,
18
				'file' => NULL,
19
			))
20
			->execute();
21
22
		$structure_files = array_filter(array_map(function($dir) use ($db) {
23
			$file = $dir.'tests'.DIRECTORY_SEPARATOR.'database'.DIRECTORY_SEPARATOR.'structure'.DIRECTORY_SEPARATOR.strtolower($db['type']).'.sql';
24
			return is_file($file) ? $file : NULL;
25
		}, Kohana::modules()));
26
27
		foreach ($structure_files as $schema)
28
		{
29
			Minion_Task::factory(array(
30
				'task' => 'db:structure:load',
31
				'database' => Kohana::TESTING,
32
				'force' => NULL,
33
				'file' => $schema,
34
			))
35
			->execute();
36
		}
37
	}
38
}
39