@@ -26,16 +26,87 @@ public function testGetThrowsInvalidArgumentExceptionIfEnvNameContainsNonWordCha
26
26
27
27
public function testMergeWillNotDuplicateIdenticalParameters ()
28
28
{
29
- $ originalPlaceholders = array ('database_host ' => array ('localhost ' ));
30
- $ firstBag = new EnvPlaceholderParameterBag ($ originalPlaceholders );
29
+ $ envVariableName = 'DB_HOST ' ;
30
+ $ parameter = sprintf ('env(%s) ' , $ envVariableName );
31
+ $ firstBag = new EnvPlaceholderParameterBag ();
31
32
32
33
// initialize placeholders
33
- $ firstBag ->get (' env(database_host) ' );
34
+ $ firstBag ->get ($ parameter );
34
35
$ secondBag = clone $ firstBag ;
35
36
36
37
$ firstBag ->mergeEnvPlaceholders ($ secondBag );
37
38
$ mergedPlaceholders = $ firstBag ->getEnvPlaceholders ();
38
39
39
- $ this ->assertCount (1 , $ mergedPlaceholders ['database_host ' ]);
40
+ $ placeholderForVariable = $ mergedPlaceholders [$ envVariableName ];
41
+ $ placeholder = array_values ($ placeholderForVariable )[0 ];
42
+
43
+ $ this ->assertCount (1 , $ placeholderForVariable );
44
+ $ this ->assertInternalType ('string ' , $ placeholder );
45
+ $ this ->assertContains ($ envVariableName , $ placeholder );
46
+ }
47
+
48
+ public function testMergeWhereFirstBagIsEmptyWillWork ()
49
+ {
50
+ $ envVariableName = 'DB_HOST ' ;
51
+ $ parameter = sprintf ('env(%s) ' , $ envVariableName );
52
+ $ firstBag = new EnvPlaceholderParameterBag ();
53
+ $ secondBag = new EnvPlaceholderParameterBag ();
54
+
55
+ // initialize placeholder only in second bag
56
+ $ secondBag ->get ($ parameter );
57
+
58
+ $ this ->assertEmpty ($ firstBag ->getEnvPlaceholders ());
59
+
60
+ $ firstBag ->mergeEnvPlaceholders ($ secondBag );
61
+ $ mergedPlaceholders = $ firstBag ->getEnvPlaceholders ();
62
+
63
+ $ placeholderForVariable = $ mergedPlaceholders [$ envVariableName ];
64
+ $ placeholder = array_values ($ placeholderForVariable )[0 ];
65
+
66
+ $ this ->assertCount (1 , $ placeholderForVariable );
67
+ $ this ->assertInternalType ('string ' , $ placeholder );
68
+ $ this ->assertContains ($ envVariableName , $ placeholder );
69
+ }
70
+
71
+ public function testMergeWherePlaceholderOnlyExistsInSecond ()
72
+ {
73
+ $ uniqueEnvName = 'DB_HOST ' ;
74
+ $ commonEnvName = 'DB_USER ' ;
75
+
76
+ $ uniqueParamName = sprintf ('env(%s) ' , $ uniqueEnvName );
77
+ $ commonParamName = sprintf ('env(%s) ' , $ commonEnvName );
78
+
79
+ $ firstBag = new EnvPlaceholderParameterBag ();
80
+ // initialize common placeholder
81
+ $ firstBag ->get ($ commonParamName );
82
+ $ secondBag = clone $ firstBag ;
83
+
84
+ // initialize unique placeholder
85
+ $ secondBag ->get ($ uniqueParamName );
86
+
87
+ $ firstBag ->mergeEnvPlaceholders ($ secondBag );
88
+ $ merged = $ firstBag ->getEnvPlaceholders ();
89
+
90
+ $ this ->assertCount (1 , $ merged [$ uniqueEnvName ]);
91
+ // second bag has same placeholder for commonEnvName
92
+ $ this ->assertCount (1 , $ merged [$ commonEnvName ]);
93
+ }
94
+
95
+ public function testMergeWithDifferentIdentifiersForPlaceholders ()
96
+ {
97
+ $ envName = 'DB_USER ' ;
98
+ $ paramName = sprintf ('env(%s) ' , $ envName );
99
+
100
+ $ firstBag = new EnvPlaceholderParameterBag ();
101
+ $ secondBag = new EnvPlaceholderParameterBag ();
102
+ // initialize placeholders
103
+ $ firstPlaceholder = $ firstBag ->get ($ paramName );
104
+ $ secondPlaceholder = $ secondBag ->get ($ paramName );
105
+
106
+ $ firstBag ->mergeEnvPlaceholders ($ secondBag );
107
+ $ merged = $ firstBag ->getEnvPlaceholders ();
108
+
109
+ $ this ->assertNotEquals ($ firstPlaceholder , $ secondPlaceholder );
110
+ $ this ->assertCount (2 , $ merged [$ envName ]);
40
111
}
41
112
}
0 commit comments