Skip to content

Commit 4250cc5

Browse files
committed
s/Base64StringElementTrait/Base64ElementTrait
1 parent f4dd673 commit 4250cc5

File tree

6 files changed

+22
-31
lines changed

6 files changed

+22
-31
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
* @package simplesamlphp/xml-common
1919
*/
20-
trait Base64StringElementTrait
20+
trait Base64ElementTrait
2121
{
2222
/** @var string */
2323
protected string $content;

src/SerializableElementTrait.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ trait SerializableElementTrait
3636
public function __toString(): string
3737
{
3838
$xml = $this->toXML();
39-
/** @psalm-var \DOMDocument $xml->ownerDocument */
40-
$xml->ownerDocument->formatOutput = $this->formatOutput;
4139

42-
return $xml->ownerDocument->saveXML($xml);
40+
$doc = DOMDocumentFactory::fromString($xml->ownerDocument->saveXML());
41+
$doc->formatOutput = $this->formatOutput;
42+
43+
return $doc->saveXML($doc->firstChild);
4344
}
4445

4546

@@ -112,14 +113,4 @@ public function toArray(): array
112113
* @return \DOMElement
113114
*/
114115
abstract public function toXML(DOMElement $parent = null): DOMElement;
115-
116-
117-
/**
118-
* Create a class from XML
119-
*
120-
* @param \DOMElement $xml
121-
* @return static
122-
* @psalm-suppress MethodSignatureMismatch
123-
*/
124-
abstract public static function fromXML(DOMElement $xml): static;
125116
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
namespace SimpleSAML\Test\XML;
66

77
use SimpleSAML\XML\AbstractElement;
8-
use SimpleSAML\XML\Base64StringElementTrait;
8+
use SimpleSAML\XML\Base64ElementTrait;
99

1010
/**
11-
* Empty shell class for testing Base64StringElement.
11+
* Empty shell class for testing Base64Element.
1212
*
1313
* @package simplesaml/xml-common
1414
*/
15-
final class Base64StringElement extends AbstractElement
15+
final class Base64Element extends AbstractElement
1616
{
17-
use Base64StringElementTrait;
17+
use Base64ElementTrait;
1818

1919
/** @var string */
2020
public const NS = 'urn:x-simplesamlphp:namespace';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<ssp:Base64Element xmlns:ssp="urn:x-simplesamlphp:namespace">/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=</ssp:Base64Element>

tests/resources/xml/ssp_Base64StringElement.xml

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/src/Base64StringElementTraitTest.php renamed to tests/src/Base64ElementTraitTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,41 +11,41 @@
1111
use SimpleSAML\Test\XML\XMLDumper;
1212
use SimpleSAML\XML\AbstractElement;
1313
use SimpleSAML\XML\DOMDocumentFactory;
14-
use SimpleSAML\XML\Base64StringElementTrait;
14+
use SimpleSAML\XML\Base64ElementTrait;
1515

1616
use function dirname;
1717
use function strval;
1818

1919
/**
20-
* Class \SimpleSAML\XML\Base64StringElementTraitTest
20+
* Class \SimpleSAML\XML\Base64ElementTraitTest
2121
*
22-
* @covers \SimpleSAML\XML\Base64StringElementTrait
22+
* @covers \SimpleSAML\XML\Base64ElementTrait
2323
* @covers \SimpleSAML\XML\StringElementTrait
2424
* @covers \SimpleSAML\XML\AbstractElement
2525
* @covers \SimpleSAML\XML\AbstractSerializableElement
2626
*
2727
* @package simplesamlphp\xml-common
2828
*/
29-
final class Base64StringElementTraitTest extends TestCase
29+
final class Base64ElementTraitTest extends TestCase
3030
{
3131
use SerializableElementTestTrait;
3232

3333
/**
3434
*/
3535
public function setup(): void
3636
{
37-
$this->testedClass = Base64StringElement::class;
37+
$this->testedClass = Base64Element::class;
3838

3939
$this->xmlRepresentation = DOMDocumentFactory::fromFile(
40-
dirname(dirname(__FILE__)) . '/resources/xml/ssp_Base64StringElement.xml',
40+
dirname(dirname(__FILE__)) . '/resources/xml/ssp_Base64Element.xml',
4141
);
4242
}
4343

4444
/**
4545
*/
4646
public function testMarshalling(): void
4747
{
48-
$base64Element = new Base64StringElement('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=');
48+
$base64Element = new Base64Element('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=');
4949

5050
$this->assertEquals(
5151
XMLDumper::dumpDOMDocumentXMLWithBase64Content($this->xmlRepresentation),
@@ -58,7 +58,7 @@ public function testMarshalling(): void
5858
*/
5959
public function testUnmarshalling(): void
6060
{
61-
$base64Element = Base64StringElement::fromXML($this->xmlRepresentation->documentElement);
61+
$base64Element = Base64Element::fromXML($this->xmlRepresentation->documentElement);
6262

6363
$this->assertEquals('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=', $base64Element->getContent());
6464
}
@@ -72,7 +72,7 @@ public function testBase64Cases(string $xml): void
7272
{
7373
$xmlRepresentation = DOMDocumentFactory::fromString($xml);
7474

75-
$xmlElement = Base64StringElement::fromXML($xmlRepresentation->documentElement);
75+
$xmlElement = Base64Element::fromXML($xmlRepresentation->documentElement);
7676

7777
$this->assertStringContainsString($xmlElement->getRawContent(), $xml);
7878
}
@@ -82,18 +82,18 @@ public function provideBase64Cases(): array
8282
return [
8383
'inline' => [
8484
<<<XML
85-
<ssp:Base64StringElement xmlns:ssp="urn:x-simplesamlphp:namespace">/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=</ssp:Base64StringElement>
85+
<ssp:Base64Element xmlns:ssp="urn:x-simplesamlphp:namespace">/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=</ssp:Base64Element>
8686
XML
8787
],
8888
'multiline' => [
8989
<<<XML
90-
<ssp:Base64StringElement xmlns:ssp="urn:x-simplesamlphp:namespace">
90+
<ssp:Base64Element xmlns:ssp="urn:x-simplesamlphp:namespace">
9191
j14G9v6AnsOiEJYgkTg864DG3e/KLqoGpuybPGSGblVTn7ST6M/BsvP7YiVZjLqJEuEvWmf2mW4D
9292
Pb+pbArzzDcsLWEtNveMrw+FkWehDUQV9oe20iepo+W46wmj7zB/eWL+Z8MrGvlycoTndJU6CVwH
9393
TLsB+dq2FDa7JV4pAPjMY32JZTbiwKhzqw3nEi/eVrujJE4YRrlW28D+rXhITfoUAGGvsqPzcwGz
9494
p02lnMe2SmXADY1u9lbVjOhUrJpgvWfn9YuiCR+wjvaGMwIwzfJxChLJZOBV+1ad1CyNTiu6qAbl
9595
xZ4F8cWlMWJ7f0KkWvtw66HOf2VNR6Qan2Ra7Q==
96-
</ssp:Base64StringElement>
96+
</ssp:Base64Element>
9797
XML
9898
],
9999
];

0 commit comments

Comments
 (0)