55use bupy7 \xml \constructor \RuntimeException ;
66use bupy7 \xml \constructor \XmlConstructor ;
77
8- use function preg_replace ;
9-
108/**
119 * @since 1.2.1
1210 */
@@ -112,6 +110,20 @@ public function testDefaultDocument2()
112110 $ this ->assertEquals ($ expected , $ out );
113111 }
114112
113+ /**
114+ * @since 2.0.2
115+ */
116+ public function testDefaultDocument3 ()
117+ {
118+ $ expected = <<<XML
119+ <?xml version="1.0" encoding="UTF-8"?>
120+
121+ XML ;
122+ $ xml = new XmlConstructor ();
123+ $ out = $ xml ->toOutput ();
124+ $ this ->assertEquals ($ expected , $ out );
125+ }
126+
115127 /**
116128 * @since 2.0.1
117129 */
@@ -247,10 +259,11 @@ public function testCdataContent()
247259 <tag1><![CDATA[<b>content1</b>]]></tag1>
248260 <tag2>content2</tag2>
249261</root>
262+
250263XML ;
251264 $ xml = new XmlConstructor ();
252265 $ out = $ xml ->fromArray ($ this ->in3 )->toOutput ();
253- $ this ->assertEquals ($ this -> prepare ( $ expected) , $ this -> prepare ( $ out) );
266+ $ this ->assertEquals ($ expected , $ out );
254267 }
255268
256269 /**
@@ -260,73 +273,81 @@ public function testInvalidConfiguration()
260273 {
261274 $ expected = <<<XML
262275<?xml version="1.0" encoding="UTF-8"?>
276+
263277XML ;
264278 $ xml = new XmlConstructor ();
265279 $ out = $ xml ->fromArray (['incorrect ' => 'array ' ])->toOutput ();
266- $ this ->assertEquals ($ this -> prepare ( $ expected) , $ this -> prepare ( $ out) );
280+ $ this ->assertEquals ($ expected , $ out );
267281 }
268282
269283 /**
270- * @since 2.0.0
284+ * @since 2.0.2
271285 */
272- public function testDoubleToOutput ()
286+ public function testDoubleToOutput1 ()
273287 {
274- $ expected = <<<XML
275- <?xml version="1.0" encoding="UTF-8"?>
276- <root>
277- <tag1 attr1="val1" attr2="val2"/>
278- <tag2>content2</tag2>
279- <tag3>
280- <tag4>content4</tag4>
281- </tag3>
282- </root>
283- XML ;
284288 $ xml = new XmlConstructor ();
285289
286- $ out = $ xml ->fromArray ($ this ->in1 )->toOutput ();
287- $ this ->assertEquals ($ this ->prepare ($ expected ), $ this ->prepare ($ out ));
290+ $ xml ->fromArray ($ this ->in1 )->toOutput ();
288291
289292 $ this ->expectException (RuntimeException::class);
290293 $ this ->expectExceptionMessage ('The constructor is closed. You have to create new one to flush its again. ' );
291294 $ xml ->toOutput ();
292295 }
293296
294297 /**
295- * @since 2.0.0
298+ * @since 2.0.2
296299 */
297- public function testDoubleFromArray ()
300+ public function testDoubleToOutput2 ()
298301 {
299- $ expected = <<<XML
300- <?xml version="1.1" encoding="ASCII"?>
301- <root>
302- <tag1 attr1="val1" attr2="val2"/>
303- <tag2>content2</tag2>
304- <tag3>
305- <tag4>content4</tag4>
306- </tag3>
307- </root>
302+ $ xml = new XmlConstructor ();
308303
309- XML ;
310- $ xml = new XmlConstructor ([
311- 'startDocument ' => ['1.1 ' , 'ASCII ' ],
312- 'indentString ' => ' ' ,
313- ]);
304+ $ xml ->toOutput ();
314305
315- $ out = $ xml ->fromArray ($ this ->in1 )->toOutput ();
316- $ this ->assertEquals ($ expected , $ out );
306+ $ this ->expectException (RuntimeException::class);
307+ $ this ->expectExceptionMessage ('The constructor is closed. You have to create new one to flush its again. ' );
308+ $ xml ->toOutput ();
309+ }
310+
311+ /**
312+ * @since 2.0.2
313+ */
314+ public function testDoubleFromArray1 ()
315+ {
316+ $ xml = new XmlConstructor ();
317+
318+ $ xml ->fromArray ($ this ->in1 );
317319
318320 $ this ->expectException (RuntimeException::class);
319- $ this ->expectExceptionMessage ('The constructor is closed. You have to create new one to create '
320- . 'an XML document again. ' );
321+ $ this ->expectExceptionMessage ('XML document is made already. ' );
321322 $ xml ->fromArray ($ this ->in1 );
322323 }
323324
324325 /**
325- * @param string $xml
326- * @return string
326+ * @since 2.0.2
327327 */
328- private function prepare ( $ xml )
328+ public function testDoubleFromArray2 ( )
329329 {
330- return preg_replace ('/\s/ ' , '' , $ xml );
330+ $ xml = new XmlConstructor ();
331+
332+ $ xml ->fromArray ($ this ->in1 )->toOutput ();
333+
334+ $ this ->expectException (RuntimeException::class);
335+ $ this ->expectExceptionMessage ('XML document is made already. ' );
336+ $ xml ->fromArray ($ this ->in1 );
337+ }
338+
339+ /**
340+ * @since 2.0.3
341+ */
342+ public function testDoubleFromArray3 ()
343+ {
344+ $ xml = new XmlConstructor ();
345+
346+ $ xml ->toOutput ();
347+
348+ $ this ->expectException (RuntimeException::class);
349+ $ this ->expectExceptionMessage ('The constructor is closed. You have to create new one to create an XML '
350+ . 'document again. ' );
351+ $ xml ->fromArray ($ this ->in1 );
331352 }
332353}
0 commit comments