ConfigReplaceTokensTest.php
2.78 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
namespace Test\Phinx\Config;
use Phinx\Config\Config;
/**
* Class ConfigReplaceTokensTest
* @package Test\Phinx\Config
* @group config
*/
class ConfigReplaceTokensTest extends AbstractConfigTest
{
/**
* Data to be saved to $_SERVER and checked later
* @var array
*/
protected static $server = array(
'PHINX_TEST_VAR_1' => 'some-value',
'NON_PHINX_TEST_VAR_1' => 'some-other-value',
'PHINX_TEST_VAR_2' => 213456,
);
/**
* Pass vars to $_SERVER
*/
public function setUp()
{
foreach (static::$server as $name => $value) {
$_SERVER[$name] = $value;
}
}
/**
* Clean-up
*/
public function tearDown()
{
foreach (static::$server as $name => $value) {
unset($_SERVER[$name]);
}
}
/**
* @covers \Phinx\Config\Config::replaceTokens
* @covers \Phinx\Config\Config::recurseArrayForTokens
*/
public function testReplaceTokens()
{
$config = new Config(array(
'some-var-1' => 'includes/%%PHINX_TEST_VAR_1%%',
'some-var-2' => 'includes/%%NON_PHINX_TEST_VAR_1%%',
'some-var-3' => 'includes/%%PHINX_TEST_VAR_2%%',
'some-var-4' => 123456,
));
$this->assertContains(
static::$server['PHINX_TEST_VAR_1'].'', // force convert to string
$config->offsetGet('some-var-1')
);
$this->assertNotContains(
static::$server['NON_PHINX_TEST_VAR_1'].'', // force convert to string
$config->offsetGet('some-var-2')
);
$this->assertContains(
static::$server['PHINX_TEST_VAR_2'].'', // force convert to string
$config->offsetGet('some-var-3')
);
}
/**
* @covers \Phinx\Config\Config::replaceTokens
* @covers \Phinx\Config\Config::recurseArrayForTokens
*/
public function testReplaceTokensRecursive()
{
$config = new Config(array(
'folding' => array(
'some-var-1' => 'includes/%%PHINX_TEST_VAR_1%%',
'some-var-2' => 'includes/%%NON_PHINX_TEST_VAR_1%%',
'some-var-3' => 'includes/%%PHINX_TEST_VAR_2%%',
'some-var-4' => 123456,
)
));
$folding = $config->offsetGet('folding');
$this->assertContains(
static::$server['PHINX_TEST_VAR_1'].'', // force convert to string
$folding['some-var-1']
);
$this->assertNotContains(
static::$server['NON_PHINX_TEST_VAR_1'].'', // force convert to string
$folding['some-var-2']
);
$this->assertContains(
static::$server['PHINX_TEST_VAR_2'].'', // force convert to string
$folding['some-var-3']
);
}
}