1: <?php
2: /**
3: * Basic Horde test case helper.
4: *
5: * PHP version 5
6: *
7: * @category Horde
8: * @package Test
9: * @author Chuck Hagenbuch <chuck@horde.org>
10: * @author Jan Schneider <jan@horde.org>
11: * @license http://www.horde.org/licenses/lgpl21 LGPL
12: * @link http://www.horde.org/components/Horde_Test
13: */
14:
15: /**
16: * Basic Horde test case helper.
17: *
18: * Copyright 2009-2012 Horde LLC (http://www.horde.org/)
19: *
20: * See the enclosed file COPYING for license information (LGPL). If you
21: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
22: *
23: * @category Horde
24: * @package Test
25: * @author Chuck Hagenbuch <chuck@horde.org>
26: * @author Jan Schneider <jan@horde.org>
27: * @license http://www.horde.org/licenses/lgpl21 LGPL
28: * @link http://www.horde.org/components/Horde_Test
29: */
30: class Horde_Test_Case extends PHPUnit_Framework_TestCase
31: {
32: /**
33: * Useful shorthand if you are mocking a class with a private constructor
34: */
35: public function getMockSkipConstructor($className, array $methods = array(), array $arguments = array(), $mockClassName = '')
36: {
37: return $this->getMock($className, $methods, $arguments, $mockClassName, /* $callOriginalConstructor */ false);
38: }
39:
40: /**
41: * Helper method for loading test configuration from a file.
42: *
43: * The configuration can be specified by an environment variable. If the
44: * variable content is a file name, the configuration is loaded from the
45: * file. Otherwise it's assumed to be a json encoded configuration hash. If
46: * the environment variable is not set, the method tries to load a conf.php
47: * file from the same directory as the test case.
48: *
49: * @param string $env An environment variable name.
50: * @param string $path The path to use.
51: * @param array $default Some default values that are merged into the
52: * configuration if specified as a json hash.
53: *
54: * @return mixed The value of the configuration file's $conf variable, or
55: * null.
56: */
57: static public function getConfig($env, $path = null, $default = array())
58: {
59: $config = getenv($env);
60: if ($config) {
61: $json = json_decode($config, true);
62: if ($json) {
63: return Horde_Array::replaceRecursive($default, $json);
64: }
65: } else {
66: if (!$path) {
67: $backtrace = new Horde_Support_Backtrace();
68: $caller = $backtrace->getCurrentContext();
69: $path = dirname($caller['file']);
70: }
71: $config = $path . '/conf.php';
72: }
73:
74: if (file_exists($config)) {
75: require $config;
76: return $conf;
77: }
78:
79: return null;
80: }
81: }
82: