Skip to content

Commit 23f8d33

Browse files
committed
Testing coverage back at 100%
1 parent 34d7c9a commit 23f8d33

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed

tests/Sabre/XML/Element/Eater.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
namespace Sabre\XML\Element;
4+
5+
use Sabre\XML;
6+
7+
/**
8+
* The intention for this reader class, is to read past the end element. This
9+
* should trigger a ParseException
10+
*
11+
* @copyright Copyright (C) 2007-2013 Rooftop Solutions. All rights reserved.
12+
* @author Evert Pot (http://www.rooftopsolutions.nl/)
13+
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
14+
*/
15+
class Eater implements XML\Element {
16+
17+
/**
18+
* The serialize method is called during xml writing.
19+
*
20+
* It should use the $writer argument to encode this object into XML.
21+
*
22+
* Important note: it is not needed to create the parent element. The
23+
* parent element is already created, and we only have to worry about
24+
* attributes, child elements and text (if any).
25+
*
26+
* Important note 2: If you are writing any new elements, you are also
27+
* responsible for closing them.
28+
*
29+
* @param XML\Writer $writer
30+
* @return void
31+
*/
32+
public function serializeXml(XML\Writer $writer) {
33+
34+
$writer->startElement('{http://sabredav.org/ns}elem1');
35+
$writer->write('hiiii!');
36+
$writer->endElement();
37+
38+
}
39+
40+
/**
41+
* The deserialize method is called during xml parsing.
42+
*
43+
* This method is called statictly, this is because in theory this method
44+
* may be used as a type of constructor, or factory method.
45+
*
46+
* Often you want to return an instance of the current class, but you are
47+
* free to return other data as well.
48+
*
49+
* Important note 2: You are responsible for advancing the reader to the
50+
* next element. Not doing anything will result in a never-ending loop.
51+
*
52+
* If you just want to skip parsing for this element altogether, you can
53+
* just call $reader->next();
54+
*
55+
* $reader->parseSubTree() will parse the entire sub-tree, and advance to
56+
* the next element.
57+
*
58+
* @param XML\Reader $reader
59+
* @return mixed
60+
*/
61+
static public function deserializeXml(XML\Reader $reader) {
62+
63+
$reader->next();
64+
65+
$count = 1;
66+
while($count) {
67+
68+
$reader->read();
69+
if ($reader->nodeType === $reader::END_ELEMENT) {
70+
$count--;
71+
}
72+
73+
}
74+
$reader->read();
75+
76+
}
77+
78+
}

tests/Sabre/XML/ReaderTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,5 +172,27 @@ function testParseProblem() {
172172

173173
}
174174

175+
/**
176+
* @expectedException \Sabre\XML\ParseException
177+
*/
178+
function testBrokenParserClass() {
179+
180+
$input = <<<BLA
181+
<?xml version="1.0"?>
182+
<root xmlns="http://sabredav.org/ns">
183+
<elem1 />
184+
</root>
185+
BLA;
186+
187+
$reader = new Reader();
188+
$reader->elementMap = [
189+
'{http://sabredav.org/ns}elem1' => 'Sabre\\XML\\Element\\Eater'
190+
];
191+
$reader->xml($input);
192+
$reader->parse();
193+
194+
195+
}
196+
175197
}
176198

tests/bootstrap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55

66
// Some extra classes
77
include __DIR__ . '/Sabre/XML/Element/Mock.php';
8+
include __DIR__ . '/Sabre/XML/Element/Eater.php';

0 commit comments

Comments
 (0)