Skip to content

Commit 2cfdf07

Browse files
committed
Create assertion and type-class for xs:string
1 parent 2a98f36 commit 2cfdf07

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

src/Assert/StringTrait.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\XML\Assert;
6+
7+
use InvalidArgumentException;
8+
9+
/**
10+
* @package simplesamlphp/xml-common
11+
*/
12+
trait StringTrait
13+
{
14+
/**
15+
* @param string $value
16+
* @param string $message
17+
*/
18+
protected static function validString(string $value, string $message = ''): void
19+
{
20+
}
21+
}

src/Type/StringValue.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\XML\Type;
6+
7+
/**
8+
* @package simplesaml/xml-common
9+
*/
10+
class StringValue extends AbstractValueType
11+
{
12+
}

tests/Type/StringValueTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\Test\XML\Type;
6+
7+
use PHPUnit\Framework\Attributes\CoversClass;
8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
use PHPUnit\Framework\TestCase;
10+
use SimpleSAML\XML\Type\StringValue;
11+
12+
/**
13+
* Class \SimpleSAML\Test\Type\StringValueValueTest
14+
*
15+
* @package simplesamlphp/xml-common
16+
*/
17+
#[CoversClass(StringValue::class)]
18+
final class StringValueTest extends TestCase
19+
{
20+
/**
21+
* @param string $str
22+
* @param string $stringValue
23+
*/
24+
#[DataProvider('provideString')]
25+
public function testString(string $str, string $stringValue): void
26+
{
27+
$value = StringValue::fromString($str);
28+
$this->assertEquals($stringValue, $value->getValue());
29+
$this->assertEquals($str, $value->getRawValue());
30+
}
31+
32+
33+
/**
34+
* @return array<string, array{0: string, 1: string}>
35+
*/
36+
public static function provideString(): array
37+
{
38+
return [
39+
'empty string' => ['', ''],
40+
'no trim' => ['Snoopy ', 'Snoopy '],
41+
'no replace whitespace' => ["Snoopy\trulez", "Snoopy\trulez"],
42+
'no collapse' => ["Snoopy\t\n\rrulez", "Snoopy\t\n\rrulez"],
43+
];
44+
}
45+
}

0 commit comments

Comments
 (0)