forked from vlucas/Spot
/
init.php
59 lines (51 loc) · 1.23 KB
/
init.php
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/**
* @package Spot
*/
// Require Spot_Config
require_once dirname(__DIR__) . '/lib/Spot/Config.php';
// Date setup
date_default_timezone_set('America/Chicago');
// Setup available adapters for testing
$cfg = new \Spot\Config();
if ($_ENV['db_type'] == "mysql") {
// MySQL
$cfg->addConnection('test', $_ENV['db_dsn']);
}
elseif ($GLOBALS['db_type'] == "mongo")
{
// MongoDB with adapter options
$cfg->addConnection('test_mongodb', $_ENV['db_dsn'], array(
'cursor' => array(
'timeout' => 10
),
'mapper' => array(
'translate_id' => true
)
));
}
else
{
// Db Type hasn't been configured
exit(1);
}
/**
* Return Spot mapper for use
*/
$mapper = new \Spot\Mapper($cfg);
function test_spot_mapper() {
global $mapper;
return $mapper;
}
/**
* Autoload test fixtures
*/
function test_spot_autoloader($className) {
// Only autoload classes that start with "Test_" and "Entity_"
if(false === strpos($className, 'Test_') && false === strpos($className, 'Entity_')) {
return false;
}
$classFile = str_replace('_', '/', $className) . '.php';
require __DIR__ . '/' . $classFile;
}
spl_autoload_register('test_spot_autoloader');