-
Notifications
You must be signed in to change notification settings - Fork 888
Expand file tree
/
Copy pathConfigReplaceTokensTest.php
More file actions
103 lines (93 loc) · 2.9 KB
/
ConfigReplaceTokensTest.php
File metadata and controls
103 lines (93 loc) · 2.9 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
102
103
<?php
namespace Test\Phinx\Config;
use Phinx\Config\Config;
/**
* Class ConfigReplaceTokensTest
*
* @package Test\Phinx\Config
* @group config
*/
class ConfigReplaceTokensTest extends AbstractConfigTestCase
{
/**
* Data to be saved to $_SERVER and checked later
*
* @var array<string, mixed>
*/
protected static $server = [
'PHINX_TEST_VAR_1' => 'some-value',
'NON_PHINX_TEST_VAR_1' => 'some-other-value',
'PHINX_TEST_VAR_2' => 213456,
];
/**
* Pass vars to $_SERVER
*/
protected function setUp(): void
{
foreach (static::$server as $name => $value) {
$_SERVER[$name] = $value;
}
}
/**
* Clean-up
*/
protected function tearDown(): void
{
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([
'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->assertStringContainsString(
static::$server['PHINX_TEST_VAR_1'] . '', // force convert to string
$config->offsetGet('some-var-1'),
);
$this->assertStringNotContainsString(
static::$server['NON_PHINX_TEST_VAR_1'] . '', // force convert to string
$config->offsetGet('some-var-2'),
);
$this->assertStringContainsString(
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([
'folding' => [
'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->assertStringContainsString(
static::$server['PHINX_TEST_VAR_1'] . '', // force convert to string
$folding['some-var-1'],
);
$this->assertStringNotContainsString(
static::$server['NON_PHINX_TEST_VAR_1'] . '', // force convert to string
$folding['some-var-2'],
);
$this->assertStringContainsString(
static::$server['PHINX_TEST_VAR_2'] . '', // force convert to string
$folding['some-var-3'],
);
}
}