22
33namespace spec \XmlTv ;
44
5+ use XmlTv \Exceptions \ValidationException ;
56use XmlTv \Tv ;
67use XmlTv \XmlElement ;
78use XmlTv \XmlTv ;
@@ -21,7 +22,25 @@ function it_generates_an_xml_file_from_an_empty_tv_object()
2122 $ this ->generate (new Tv (), false )->shouldReturn ($ xml );
2223 }
2324
24- function it_generates_an_xml_file ()
25+ function it_generates_a_basic_xml_file ()
26+ {
27+ $ xml = file_get_contents (__DIR__ .'/../epg-basic.xml ' );
28+
29+ $ tv = new Tv ();
30+ $ channel = new Tv \Channel ('test ' );
31+ $ channel ->addDisplayName (new Tv \Elements \DisplayName ('foo ' ));
32+ $ programme = new Tv \Programme ('test ' , '1 ' , '2 ' );
33+ $ programme ->addTitle (new Tv \Elements \Title ('bar ' ));
34+ $ programme ->video = new Tv \Elements \Video ('yes ' );
35+ $ programme ->audio = new Tv \Elements \Audio ('no ' );
36+
37+ $ tv ->addChannel ($ channel );
38+ $ tv ->addProgramme ($ programme );
39+
40+ $ this ->generate ($ tv , false )->shouldReturn ($ xml );
41+ }
42+
43+ function it_generates_a_xml_file ()
2544 {
2645 $ xml = file_get_contents (__DIR__ .'/../epg.xml ' );
2746 $ date = gmdate (Tv::DATE_FORMAT , 100000 );
@@ -85,12 +104,19 @@ function it_generates_an_xml_file()
85104
86105 function it_throws_if_the_generated_xml_does_not_validate ()
87106 {
88- $ this ->shouldThrow (' XmlTv\Exceptions\ ValidationException' )->duringGenerate (new InvalidTv (), true );
107+ $ this ->shouldThrow (ValidationException::class )->duringGenerate (new InvalidTv (), true );
89108 }
90109
91- function it_triggers_a_warning_if_an_element_cannot_be_serialized ()
110+ function it_throws_if_an_element_cannot_be_serialized ()
92111 {
93- $ this ->shouldTrigger (E_USER_WARNING )->duringGenerate (new UnserializableChild (), false );
112+ $ this ->shouldThrow (\TypeError::class)->duringGenerate (new UnserializableChild (), false );
113+ }
114+
115+ function it_provides_support_for_legacy_code ()
116+ {
117+ $ xml = '<?xml version="1.0"?> ' . PHP_EOL . '<tv/> ' . PHP_EOL ;
118+
119+ $ this ->generate (new LegacyMethods (), false )->shouldReturn ($ xml );
94120 }
95121}
96122
@@ -108,6 +134,15 @@ class UnserializableChild extends Tv
108134 public function xmlSerialize (): XmlElement
109135 {
110136 return (new XmlElement ('tv ' ))
111- ->withOptionalChild (new \stdClass ());
137+ ->withChild (new \stdClass ());
138+ }
139+ }
140+
141+ class LegacyMethods extends Tv
142+ {
143+ public function xmlSerialize (): XmlElement
144+ {
145+ return (new XmlElement ('tv ' ))
146+ ->withOptionalChild (new XmlElement ('foo ' ));
112147 }
113148}
0 commit comments