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 = '')
589589 } else {
590590 preg_match_all ('/\{\{([a-z0-9_]+)\}\}/is ' , $ format , $ matches );
591591 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 );
593594 }
594595 $ str = $ format ;
595596 }
Original file line number Diff line number Diff line change @@ -166,15 +166,33 @@ public function provideGetDataData(): Generator
166166 }
167167
168168 /**
169+ * @dataProvider provideToString
169170 * @group Varien_Object
170171 */
171- public function testToString (): void
172+ public function testToString (string $ expectedResult , string $ format ): void
172173 {
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+ ];
178196 }
179197
180198 /**
You can’t perform that action at this time.
0 commit comments