Skip to content

Commit 5dae87b

Browse files
committed
Add testable CustomSignable and CustomSigned
1 parent bf59081 commit 5dae87b

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

tests/XML/CustomSignable.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\XMLSecurity\Test\XML;
6+
7+
use SimpleSAML\XML\AbstractXMLElement;
8+
use SimpleSAML\XML\Chunk;
9+
use SimpleSAML\XMLSecurity\XML\SignableElementInterface;
10+
use SimpleSAML\XMLSecurity\XML\SignableElementTrait;
11+
12+
/**
13+
* @package simplesamlphp\saml2
14+
*/
15+
final class CustomSignable extends AbstractXMLElement implements SignableElementInterface
16+
{
17+
use SignableElementTrait;
18+
19+
/** @var \SimpleSAML\XML\Chunk $element */
20+
protected $element;
21+
22+
/**
23+
* Constructor
24+
*
25+
* @param \SimpleSAML\XML\Chunk $elt
26+
*/
27+
public function __construct(Chunk $elt) {
28+
$this->setElement($elt);
29+
}
30+
31+
32+
33+
/**
34+
* Collect the value of the $element property
35+
*
36+
* @return \SimpleSAML\XML\XML\Chunk
37+
*/
38+
public function getElement(): Chunk
39+
{
40+
return $this->element;
41+
}
42+
43+
44+
/**
45+
* Set the value of the elment-property
46+
*
47+
* @param \SimpleSAML\XML\Chunk $elt
48+
*/
49+
private function setElement(Chunk $elt): void
50+
{
51+
$this->element = $elt;
52+
}
53+
}

tests/XML/CustomSigned.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\XMLSecurity\Test\XML;
6+
7+
use SimpleSAML\XML\Exception\TooManyElementsException;
8+
use SimpleSAML\XMLSecurity\XML\ds\Signature;
9+
use SimpleSAML\XMLSecurity\XML\SignedElementInterface;
10+
use SimpleSAML\XMLSecurity\XML\SignedElementTrait;
11+
12+
/**
13+
* @package simplesamlphp\saml2
14+
*/
15+
final class CustomSigned extends AbstractSignedXMLElement
16+
{
17+
use SignedElementTrait;
18+
19+
20+
/**
21+
* Create a class from XML
22+
*
23+
* @param \DOMElement $xml
24+
* @return self
25+
*/
26+
public static function fromXML(DOMElement $xml): object
27+
{
28+
$signature = Signature::getChildrenOfClass($xml);
29+
Assert::count($signature, 1, TooManyElementsException::class);
30+
31+
$element = CustomSignable::getChildrenOfClass($xml);
32+
Assert::count($element, 1, TooManyElementsException::class);
33+
34+
return new self(
35+
$xml,
36+
array_pop($element),
37+
array_pop($signature)
38+
);
39+
}
40+
}

0 commit comments

Comments
 (0)