1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Rad\Configure\Tests\Engine; |
4
|
|
|
|
5
|
|
|
use PHPUnit_Framework_TestCase; |
6
|
|
|
use Rad\Configure\Config; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* PhpConfig Engine Test |
10
|
|
|
* |
11
|
|
|
* @package Rad\Configure\Tests\Engine |
12
|
|
|
*/ |
13
|
|
|
class PhpConfigTest extends PHPUnit_Framework_TestCase |
14
|
|
|
{ |
15
|
|
|
protected static $fixtures; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @inheritdoc |
19
|
|
|
*/ |
20
|
|
|
public static function setUpBeforeClass() |
21
|
|
|
{ |
22
|
|
|
self::$fixtures = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'Fixtures'; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Test load php config file |
27
|
|
|
*/ |
28
|
|
|
public function testLoad() |
29
|
|
|
{ |
30
|
|
|
$this->assertTrue(Config::load(self::$fixtures . '/Engine/PhpConfig/base_config.php')); |
31
|
|
|
|
32
|
|
|
$this->setExpectedExceptionRegExp( |
33
|
|
|
'Rad\Configure\Exception', |
34
|
|
|
'/Input file "not-exist-php-config-file.php" is not exist or is not readable/' |
35
|
|
|
); |
36
|
|
|
Config::load('not-exist-php-config-file.php'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Test load invalid return config file |
41
|
|
|
*/ |
42
|
|
|
public function testLoadInvalidReturnConfig() |
43
|
|
|
{ |
44
|
|
|
$this->setExpectedExceptionRegExp( |
45
|
|
|
'Rad\Configure\Exception', |
46
|
|
|
'/You must return array in config file/' |
47
|
|
|
); |
48
|
|
|
Config::load(self::$fixtures . '/Engine/PhpConfig/invalid_return_config.php'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Test load from array |
53
|
|
|
*/ |
54
|
|
|
public function testLoadFromArray() |
55
|
|
|
{ |
56
|
|
|
$this->assertTrue(Config::load(['alice' => 'bob'])); |
57
|
|
|
$this->assertEquals(Config::get('alice'), 'bob'); |
58
|
|
|
|
59
|
|
|
$this->setExpectedExceptionRegExp( |
60
|
|
|
'Rad\Configure\Exception', |
61
|
|
|
'/Input data is not valid/' |
62
|
|
|
); |
63
|
|
|
Config::load(new \stdClass('Input data is not valid')); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Test PhpConfig dump |
68
|
|
|
*/ |
69
|
|
|
public function testDump() |
70
|
|
|
{ |
71
|
|
|
Config::load(self::$fixtures . '/Engine/PhpConfig/base_config.php'); |
72
|
|
|
$filename = sprintf('/tmp/%s/config.php', uniqid()); |
73
|
|
|
|
74
|
|
|
$this->assertTrue(Config::dump($filename)); |
75
|
|
|
Config::load($filename, 'default', false); |
76
|
|
|
$this->assertEquals(Config::get('key2.sub-key1.sub-sub-key2'), 'val2'); |
77
|
|
|
|
78
|
|
|
chmod($filename, 0400); |
79
|
|
|
$this->setExpectedExceptionRegExp( |
80
|
|
|
'Rad\Configure\Exception', |
81
|
|
|
sprintf('/File "%s" is not writable/', preg_quote($filename, '/')) |
82
|
|
|
); |
83
|
|
|
Config::dump($filename); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.