forked from simplesamlphp/xml-common
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypedTextContentTraitTest.php
More file actions
72 lines (58 loc) · 2.2 KB
/
TypedTextContentTraitTest.php
File metadata and controls
72 lines (58 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
declare(strict_types=1);
namespace SimpleSAML\Test\XML;
use PHPUnit\Framework\TestCase;
use SimpleSAML\Test\Helper\Base64BinaryElement;
use SimpleSAML\Test\Helper\BooleanElement;
use SimpleSAML\Test\Helper\StringElement;
use SimpleSAML\XML\DOMDocumentFactory;
use SimpleSAML\XMLSchema\Exception\InvalidValueTypeException;
use SimpleSAML\XMLSchema\Exception\SchemaViolationException;
/**
* Class \SimpleSAML\XML\TypedTextContentTraitTest
*
* @package simplesamlphp\xml-common
*/
final class TypedTextContentTraitTest extends TestCase
{
public function testTypedContentPassesForString(): void
{
$file = 'tests/resources/xml/ssp_StringElement.xml';
$doc = DOMDocumentFactory::fromFile($file);
/** @var \DOMElement $elt */
$elt = $doc->documentElement;
$stringElt = StringElement::fromXML($elt);
// @phpstan-ignore-next-line
$this->assertInstanceOf(StringElement::class, $stringElt);
}
public function testTypedContentPassesForBoolean(): void
{
$file = 'tests/resources/xml/ssp_BooleanElement.xml';
$doc = DOMDocumentFactory::fromFile($file);
/** @var \DOMElement $elt */
$elt = $doc->documentElement;
$stringElt = BooleanElement::fromXML($elt);
// @phpstan-ignore-next-line
$this->assertInstanceOf(BooleanElement::class, $stringElt);
}
public function testTypedContentFailsForWrongType(): void
{
$file = 'tests/resources/xml/ssp_BooleanElement.xml';
$doc = DOMDocumentFactory::fromFile($file);
/** @var \DOMElement $elt */
$elt = $doc->documentElement;
$elt->textContent = 'not-a-boolean';
$this->expectException(SchemaViolationException::class);
BooleanElement::fromXML($elt);
}
public function testTypedContentFailsForWrongClass(): void
{
// Base64Binary has a TEXTCONTENT_TYPE that makes no sense
$file = 'tests/resources/xml/ssp_Base64BinaryElement.xml';
$doc = DOMDocumentFactory::fromFile($file);
/** @var \DOMElement $elt */
$elt = $doc->documentElement;
$this->expectException(InvalidValueTypeException::class);
Base64BinaryElement::fromXML($elt);
}
}