File tree Expand file tree Collapse file tree 2 files changed +26
-7
lines changed Expand file tree Collapse file tree 2 files changed +26
-7
lines changed Original file line number Diff line number Diff line change @@ -589,7 +589,8 @@ public function toString($format = '')
589
589
} else {
590
590
preg_match_all ('/\{\{([a-z0-9_]+)\}\}/is ' , $ format , $ matches );
591
591
foreach ($ matches [1 ] as $ var ) {
592
- $ format = str_replace ('{{ ' . $ var . '}} ' , $ this ->getData ($ var ), $ format );
592
+ $ replace = is_null ($ this ->getData ($ var )) ? '' : $ this ->getData ($ var );
593
+ $ format = str_replace ('{{ ' . $ var . '}} ' , $ replace , $ format );
593
594
}
594
595
$ str = $ format ;
595
596
}
Original file line number Diff line number Diff line change @@ -166,15 +166,33 @@ public function provideGetDataData(): Generator
166
166
}
167
167
168
168
/**
169
+ * @dataProvider provideToString
169
170
* @group Varien_Object
170
171
*/
171
- public function testToString (): void
172
+ public function testToString (string $ expectedResult , string $ format ): void
172
173
{
173
- $ this ->subject ->setString1 ('open ' );
174
- $ this ->subject ->setString2 ('mage ' );
175
- $ this ->assertSame ('open, mage ' , $ this ->subject ->toString ());
176
- $ this ->assertSame ('openmage ' , $ this ->subject ->toString ('{{string1}}{{string2}} ' ));
177
- $ this ->assertSame ('open ' , $ this ->subject ->toString ('{{string1}}{{string_not_exists}} ' ));
174
+ $ this ->subject ->setString0 ('0 ' );
175
+ $ this ->subject ->setString1 ('one ' );
176
+ $ this ->subject ->setString2 ('two ' );
177
+ $ this ->subject ->setString3 ('three ' );
178
+
179
+ $ this ->assertSame ($ expectedResult , $ this ->subject ->toString ($ format ));
180
+ }
181
+
182
+ public function provideToString (): Generator
183
+ {
184
+ yield 'no format ' => [
185
+ '0, one, two, three ' ,
186
+ '' ,
187
+ ];
188
+ yield 'valid ' => [
189
+ '0 one two ' ,
190
+ '{{string0}} {{string1}} {{string2}} ' ,
191
+ ];
192
+ yield 'invalid ' => [
193
+ 'three 0 ' ,
194
+ '{{string3}} {{string_not_exists}} {{string0}} ' ,
195
+ ];
178
196
}
179
197
180
198
/**
You can’t perform that action at this time.
0 commit comments