-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
124 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\XML; | ||
|
||
use DOMElement; | ||
use SimpleSAML\Assert\Assert; | ||
use SimpleSAML\XML\Exception\InvalidDOMElementException; | ||
use SimpleSAML\XML\Exception\SchemaViolationException; | ||
|
||
/** | ||
* Trait grouping common functionality for simple elements with just some textContent | ||
* | ||
* @package simplesamlphp/xml-common | ||
*/ | ||
trait IntegerElementTrait | ||
{ | ||
use StringElementTrait; | ||
|
||
|
||
/** | ||
* Validate the content of the element. | ||
* | ||
* @param int $content The value to go in the XML textContent | ||
* @throws \Exception on failure | ||
* @return void | ||
*/ | ||
protected function validateContent(/** @scrutinizer ignore-unused */ string $content): void | ||
{ | ||
/** | ||
* Perform no validation by default. | ||
* Override this method on the implementing class to perform content validation. | ||
*/ | ||
Assert::numeric($content, SchemaViolationException::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\Test\XML; | ||
|
||
use SimpleSAML\XML\AbstractElement; | ||
use SimpleSAML\XML\IntegerElementTrait; | ||
|
||
/** | ||
* Empty shell class for testing Integer elements. | ||
* | ||
* @package simplesaml/xml-common | ||
*/ | ||
final class IntegerElement extends AbstractElement | ||
{ | ||
use IntegerElementTrait; | ||
|
||
/** @var string */ | ||
public const NS = 'urn:x-simplesamlphp:namespace'; | ||
|
||
/** @var string */ | ||
public const NS_PREFIX = 'ssp'; | ||
|
||
|
||
/** | ||
* @param string $content | ||
*/ | ||
public function __construct(string $content) | ||
{ | ||
$this->setContent($content); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\Test\XML; | ||
|
||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\TestCase; | ||
use SimpleSAML\Test\XML\IntegerElement; | ||
use SimpleSAML\XML\AbstractElement; | ||
use SimpleSAML\XML\DOMDocumentFactory; | ||
use SimpleSAML\XML\IntegerElementTrait; | ||
use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; | ||
|
||
use function dirname; | ||
use function strval; | ||
|
||
/** | ||
* Class \SimpleSAML\XML\IntegerElementTraitTest | ||
* | ||
* @package simplesamlphp\xml-common | ||
*/ | ||
#[CoversClass(SerializableElementTestTrait::class)] | ||
#[CoversClass(IntegerElementTrait::class)] | ||
#[CoversClass(AbstractElement::class)] | ||
final class IntegerElementTraitTest extends TestCase | ||
{ | ||
use SerializableElementTestTrait; | ||
|
||
|
||
/** | ||
*/ | ||
public static function setUpBeforeClass(): void | ||
{ | ||
self::$testedClass = IntegerElement::class; | ||
|
||
self::$xmlRepresentation = DOMDocumentFactory::fromFile( | ||
dirname(__FILE__, 2) . '/resources/xml/ssp_IntegerElement.xml', | ||
); | ||
} | ||
|
||
/** | ||
*/ | ||
public function testMarshalling(): void | ||
{ | ||
$integerElement = new IntegerElement('-001'); | ||
|
||
$this->assertEquals( | ||
self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), | ||
strval($integerElement), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<ssp:IntegerElement xmlns:ssp="urn:x-simplesamlphp:namespace">-001</ssp:IntegerElement> |