From a763d8942031cdeb2128b89dfe94de6acdb1109d Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Mon, 20 Jan 2025 20:50:12 +0100 Subject: [PATCH] Refactor unit tests --- src/Type/AbstractValueType.php | 27 ++++++++- src/Type/AnyURIValue.php | 12 ++++ src/Type/Base64BinaryValue.php | 6 +- src/Type/BooleanValue.php | 4 +- src/Type/DateTimeValue.php | 5 +- src/Type/DateValue.php | 5 +- src/Type/DayValue.php | 5 +- src/Type/DecimalValue.php | 2 +- src/Type/DoubleValue.php | 2 +- src/Type/DurationValue.php | 5 +- src/Type/FloatValue.php | 2 +- src/Type/HexBinaryValue.php | 6 +- src/Type/LanguageValue.php | 2 +- src/Type/MonthValue.php | 5 +- src/Type/NormalizedStringValue.php | 4 +- src/Type/QNameValue.php | 46 ++++++++++++++++ src/Type/TimeValue.php | 14 ++++- src/Type/TokenValue.php | 5 +- src/Type/YearMonthValue.php | 5 +- src/Type/YearValue.php | 5 +- tests/Assert/AnyURITest.php | 4 +- tests/Assert/Base64BinaryTest.php | 20 +++++-- tests/Assert/BooleanTest.php | 17 +++++- tests/Assert/ByteTest.php | 19 +++++-- tests/Assert/DateTest.php | 17 +++++- tests/Assert/DateTimeTest.php | 17 +++++- tests/Assert/DayTest.php | 17 +++++- tests/Assert/DecimalTest.php | 19 +++++-- tests/Assert/DoubleTest.php | 21 +++++-- tests/Assert/DurationTest.php | 17 +++++- tests/Assert/EntitiesTest.php | 38 ++++++++----- tests/Assert/EntityTest.php | 64 ++++++++++++++++++++++ tests/Assert/FloatTest.php | 21 +++++-- tests/Assert/HexBinaryTest.php | 19 +++++-- tests/Assert/IDRefTest.php | 49 +++++++++-------- tests/Assert/IDRefsTest.php | 39 ++++++++----- tests/Assert/IDTest.php | 49 +++++++++-------- tests/Assert/IntTest.php | 19 +++++-- tests/Assert/IntegerTest.php | 19 +++++-- tests/Assert/LanguageTest.php | 21 +++++-- tests/Assert/LongTest.php | 19 +++++-- tests/Assert/MonthTest.php | 17 +++++- tests/Assert/NCNameTest.php | 50 +++++++++-------- tests/Assert/NMTokenTest.php | 36 +++++++----- tests/Assert/NMTokensTest.php | 37 ++++++++----- tests/Assert/NameTest.php | 39 +++++++------ tests/Assert/NegativeIntegerTest.php | 21 +++++-- tests/Assert/NonNegativeIntegerTest.php | 19 +++++-- tests/Assert/NonPositiveIntegerTest.php | 19 +++++-- tests/Assert/PositiveIntegerTest.php | 21 +++++-- tests/Assert/QNameTest.php | 48 +++++++++------- tests/Assert/ShortTest.php | 19 +++++-- tests/Assert/TimeTest.php | 17 +++++- tests/Assert/TokenTest.php | 20 +++---- tests/Assert/UnsignedByteTest.php | 21 +++++-- tests/Assert/UnsignedIntTest.php | 21 +++++-- tests/Assert/UnsignedLongTest.php | 21 +++++-- tests/Assert/UnsignedShortTest.php | 21 +++++-- tests/Assert/YearMonthTest.php | 19 +++++-- tests/Assert/YearTest.php | 23 +++++--- tests/Type/AnyURIValueTest.php | 21 +++---- tests/Type/Base64BinaryValueTest.php | 24 ++++++-- tests/Type/BooleanValueTest.php | 28 +++++++--- tests/Type/ByteValueTest.php | 29 ++++++---- tests/Type/DateTimeValueTest.php | 57 ++++++++++--------- tests/Type/DateValueTest.php | 30 ++++++---- tests/Type/DayValueTest.php | 30 ++++++---- tests/Type/DecimalValueTest.php | 29 ++++++---- tests/Type/DoubleValueTest.php | 32 ++++++----- tests/Type/DurationValueTest.php | 30 ++++++---- tests/Type/EntitiesValueTest.php | 45 +++++++++------ tests/Type/EntityValueTest.php | 34 +++++++----- tests/Type/FloatValueTest.php | 32 ++++++----- tests/Type/HexBinaryValueTest.php | 22 ++++++-- tests/Type/IDRefValueTest.php | 32 +++++++---- tests/Type/IDRefsValueTest.php | 47 ++++++++++------ tests/Type/IDValueTest.php | 32 +++++++---- tests/Type/IntValueTest.php | 29 ++++++---- tests/Type/IntegerValueTest.php | 27 ++++++--- tests/Type/LanguageValueTest.php | 31 +++++++---- tests/Type/LongValueTest.php | 29 ++++++---- tests/Type/MonthValueTest.php | 29 ++++++---- tests/Type/NCNameValueTest.php | 32 +++++++---- tests/Type/NMTokenValueTest.php | 31 +++++++---- tests/Type/NMTokensValueTest.php | 38 ++++++++----- tests/Type/NameValueTest.php | 30 ++++++---- tests/Type/NegativeIntegerValueTest.php | 26 ++++++--- tests/Type/NonNegativeIntegerValueTest.php | 28 +++++++--- tests/Type/NonPositiveIntegerValueTest.php | 27 ++++++--- tests/Type/NormalizedStringValueTest.php | 4 +- tests/Type/PositiveIntegerValueTest.php | 28 +++++++--- tests/Type/QNameValueTest.php | 47 ++++++++++++---- tests/Type/ShortValueTest.php | 29 ++++++---- tests/Type/StringValueTest.php | 4 +- tests/Type/TimeValueTest.php | 28 +++++++--- tests/Type/TokenValueTest.php | 20 ++++--- tests/Type/UnsignedByteValueTest.php | 28 +++++++--- tests/Type/UnsignedIntValueTest.php | 28 +++++++--- tests/Type/UnsignedLongValueTest.php | 28 +++++++--- tests/Type/UnsignedShortValueTest.php | 28 +++++++--- tests/Type/YearMonthValueTest.php | 30 ++++++---- tests/Type/YearValueTest.php | 31 +++++++---- 102 files changed, 1639 insertions(+), 786 deletions(-) create mode 100644 tests/Assert/EntityTest.php diff --git a/src/Type/AbstractValueType.php b/src/Type/AbstractValueType.php index 1b65e64f..c683b0a3 100644 --- a/src/Type/AbstractValueType.php +++ b/src/Type/AbstractValueType.php @@ -4,6 +4,9 @@ namespace SimpleSAML\XML\Type; +use function preg_replace; +use function trim; + /** * Abstract class to be implemented by all types * @@ -69,7 +72,7 @@ protected function sanitizeValue(string $value): string * @throws \Exception on failure * @return void */ - protected function validateValue(/** @scrutinizer ignore-unused */ string $value): void + protected function validateValue(/** @scrutinizer-ignore */string $value): void { /** * Perform no validation by default. @@ -78,6 +81,28 @@ protected function validateValue(/** @scrutinizer ignore-unused */ string $value } + /** + * Normalize whitespace in the value + * + * @return string + */ + protected static function normalizeWhitespace(string $value): string + { + return preg_replace('/\s/', ' ', $value); + } + + + /** + * Collapse whitespace + * + * @return string + */ + protected static function collapseWhitespace(string $value): string + { + return trim(preg_replace('/\s+/', ' ', $value)); + } + + /** * @param string $value * @return static diff --git a/src/Type/AnyURIValue.php b/src/Type/AnyURIValue.php index 6e7c2a70..e90a503c 100644 --- a/src/Type/AnyURIValue.php +++ b/src/Type/AnyURIValue.php @@ -12,6 +12,18 @@ */ class AnyURIValue extends AbstractValueType { + /** + * Sanitize the value. + * + * @param string $value The unsanitized value + * @return string + */ + protected function sanitizeValue(string $value): string + { + return static::collapseWhitespace(static::normalizeWhitespace($value)); + } + + /** * Validate the value. * diff --git a/src/Type/Base64BinaryValue.php b/src/Type/Base64BinaryValue.php index ccc296a5..20e58ff2 100644 --- a/src/Type/Base64BinaryValue.php +++ b/src/Type/Base64BinaryValue.php @@ -7,7 +7,7 @@ use SimpleSAML\XML\Assert\Assert; use SimpleSAML\XML\Exception\SchemaViolationException; -use function str_replace; +use preg_replace; /** * @package simplesaml/xml-common @@ -17,14 +17,12 @@ class Base64BinaryValue extends AbstractValueType /** * Sanitize the value. * - * Note: There are no processing rules for xs:base64 regarding whitespace. General consensus is to strip them - * * @param string $value The unsanitized value * @return string */ protected function sanitizeValue(string $value): string { - return str_replace(["\f", "\r", "\n", "\t", "\v", ' '], '', $value); + return preg_replace('/\s/', '', $value); } diff --git a/src/Type/BooleanValue.php b/src/Type/BooleanValue.php index 385832bd..dd40b6c1 100644 --- a/src/Type/BooleanValue.php +++ b/src/Type/BooleanValue.php @@ -7,8 +7,6 @@ use SimpleSAML\XML\Assert\Assert; use SimpleSAML\XML\Exception\SchemaViolationException; -use function str_replace; - /** * @package simplesaml/xml-common */ @@ -22,7 +20,7 @@ class BooleanValue extends AbstractValueType */ protected function sanitizeValue(string $value): string { - return str_replace(["\f", "\r", "\n", "\t", "\v", ' '], '', $value); + return static::collapseWhitespace(static::normalizeWhitespace($value)); } diff --git a/src/Type/DateTimeValue.php b/src/Type/DateTimeValue.php index a6b14e79..6d5569eb 100644 --- a/src/Type/DateTimeValue.php +++ b/src/Type/DateTimeValue.php @@ -8,9 +8,6 @@ use SimpleSAML\XML\Assert\Assert; use SimpleSAML\XML\Exception\SchemaViolationException; -use function preg_replace; -use function trim; - /** * @package simplesaml/xml-common */ @@ -27,7 +24,7 @@ class DateTimeValue extends AbstractValueType */ protected function sanitizeValue(string $value): string { - return trim(preg_replace('/\s+/', ' ', $value)); + return static::collapseWhitespace(static::normalizeWhitespace($value)); } diff --git a/src/Type/DateValue.php b/src/Type/DateValue.php index 3758f099..38fc68fc 100644 --- a/src/Type/DateValue.php +++ b/src/Type/DateValue.php @@ -7,9 +7,6 @@ use SimpleSAML\XML\Assert\Assert; use SimpleSAML\XML\Exception\SchemaViolationException; -use function preg_replace; -use function trim; - /** * @package simplesaml/xml-common */ @@ -23,7 +20,7 @@ class DateValue extends AbstractValueType */ protected function sanitizeValue(string $value): string { - return trim(preg_replace('/\s+/', ' ', $value)); + return static::collapseWhitespace(static::normalizeWhitespace($value)); } diff --git a/src/Type/DayValue.php b/src/Type/DayValue.php index 1b55a190..66ee7315 100644 --- a/src/Type/DayValue.php +++ b/src/Type/DayValue.php @@ -7,9 +7,6 @@ use SimpleSAML\XML\Assert\Assert; use SimpleSAML\XML\Exception\SchemaViolationException; -use function preg_replace; -use function trim; - /** * @package simplesaml/xml-common */ @@ -23,7 +20,7 @@ class DayValue extends AbstractValueType */ protected function sanitizeValue(string $value): string { - return trim(preg_replace('/\s+/', ' ', $value)); + return static::collapseWhitespace(static::normalizeWhitespace($value)); } diff --git a/src/Type/DecimalValue.php b/src/Type/DecimalValue.php index 1533efb2..276b9ab2 100644 --- a/src/Type/DecimalValue.php +++ b/src/Type/DecimalValue.php @@ -20,7 +20,7 @@ class DecimalValue extends AbstractValueType */ protected function sanitizeValue(string $value): string { - return str_replace(["\f", "\r", "\n", "\t", "\v", ' '], '', $value); + return static::collapseWhitespace(static::normalizeWhitespace($value)); } diff --git a/src/Type/DoubleValue.php b/src/Type/DoubleValue.php index 7399e7c6..381e4d18 100644 --- a/src/Type/DoubleValue.php +++ b/src/Type/DoubleValue.php @@ -20,7 +20,7 @@ class DoubleValue extends AbstractValueType */ protected function sanitizeValue(string $value): string { - return str_replace(["\f", "\r", "\n", "\t", "\v", ' '], '', $value); + return static::collapseWhitespace(static::normalizeWhitespace($value)); } diff --git a/src/Type/DurationValue.php b/src/Type/DurationValue.php index fa638d55..1ce8b510 100644 --- a/src/Type/DurationValue.php +++ b/src/Type/DurationValue.php @@ -7,9 +7,6 @@ use SimpleSAML\XML\Assert\Assert; use SimpleSAML\XML\Exception\SchemaViolationException; -use function preg_replace; -use function trim; - /** * @package simplesaml/xml-common */ @@ -23,7 +20,7 @@ class DurationValue extends AbstractValueType */ protected function sanitizeValue(string $value): string { - return trim(preg_replace('/\s+/', ' ', $value)); + return static::collapseWhitespace(static::normalizeWhitespace($value)); } diff --git a/src/Type/FloatValue.php b/src/Type/FloatValue.php index db117cc4..25e6d37e 100644 --- a/src/Type/FloatValue.php +++ b/src/Type/FloatValue.php @@ -20,7 +20,7 @@ class FloatValue extends AbstractValueType */ protected function sanitizeValue(string $value): string { - return str_replace(["\f", "\r", "\n", "\t", "\v", ' '], '', $value); + return static::collapseWhitespace(static::normalizeWhitespace($value)); } diff --git a/src/Type/HexBinaryValue.php b/src/Type/HexBinaryValue.php index c7d1f838..07be24d8 100644 --- a/src/Type/HexBinaryValue.php +++ b/src/Type/HexBinaryValue.php @@ -7,8 +7,6 @@ use SimpleSAML\XML\Assert\Assert; use SimpleSAML\XML\Exception\SchemaViolationException; -use function str_replace; - /** * @package simplesaml/xml-common */ @@ -17,14 +15,12 @@ class HexBinaryValue extends AbstractValueType /** * Sanitize the value. * - * Note: There are no processing rules for xs:hexBinary regarding whitespace. General consensus is to strip them - * * @param string $value The unsanitized value * @return string */ protected function sanitizeValue(string $value): string { - return str_replace(["\f", "\r", "\n", "\t", "\v", ' '], '', $value); + return static::collapseWhitespace(static::normalizeWhitespace($value)); } diff --git a/src/Type/LanguageValue.php b/src/Type/LanguageValue.php index 96b612a3..666ca2af 100644 --- a/src/Type/LanguageValue.php +++ b/src/Type/LanguageValue.php @@ -21,7 +21,7 @@ class LanguageValue extends TokenValue */ protected function validateValue(string $value): void { - // Note: content must already be sanitized before validating + // Note: value must already be sanitized before validating Assert::validLanguage($this->sanitizeValue($value), SchemaViolationException::class); } } diff --git a/src/Type/MonthValue.php b/src/Type/MonthValue.php index dfa9724d..bc6a1370 100644 --- a/src/Type/MonthValue.php +++ b/src/Type/MonthValue.php @@ -7,9 +7,6 @@ use SimpleSAML\XML\Assert\Assert; use SimpleSAML\XML\Exception\SchemaViolationException; -use function preg_replace; -use function trim; - /** * @package simplesaml/xml-common */ @@ -23,7 +20,7 @@ class MonthValue extends AbstractValueType */ protected function sanitizeValue(string $value): string { - return trim(preg_replace('/\s+/', ' ', $value)); + return static::collapseWhitespace(static::normalizeWhitespace($value)); } diff --git a/src/Type/NormalizedStringValue.php b/src/Type/NormalizedStringValue.php index 6659ab4f..a0a054c4 100644 --- a/src/Type/NormalizedStringValue.php +++ b/src/Type/NormalizedStringValue.php @@ -4,8 +4,6 @@ namespace SimpleSAML\XML\Type; -use function preg_replace; - /** * @package simplesaml/xml-common */ @@ -19,6 +17,6 @@ class NormalizedStringValue extends StringValue */ protected function sanitizeValue(string $value): string { - return preg_replace('/\s/', ' ', $value); + return static::normalizeWhitespace($value); } } diff --git a/src/Type/QNameValue.php b/src/Type/QNameValue.php index a4434bc0..6d3eb643 100644 --- a/src/Type/QNameValue.php +++ b/src/Type/QNameValue.php @@ -7,11 +7,25 @@ use SimpleSAML\XML\Assert\Assert; use SimpleSAML\XML\Exception\SchemaViolationException; +use function explode; + /** * @package simplesaml/xml-common */ class QNameValue extends AbstractValueType { + /** + * Sanitize the value. + * + * @param string $value The unsanitized value + * @return string + */ + protected function sanitizeValue(string $value): string + { + return static::collapseWhitespace(static::normalizeWhitespace($value)); + } + + /** * Validate the value. * @@ -24,4 +38,36 @@ protected function validateValue(string $value): void // Note: value must already be sanitized before validating Assert::validQName($this->sanitizeValue($value), SchemaViolationException::class); } + + + /** + * Get the namespace-prefix for this qualified name. + * + * @return \SimpleSAML\XML\Type\NCNameValue|null + */ + public function getNamespacePrefix(): ?NCNameValue + { + $qname = explode(':', $this->getValue(), 2); + if (count($qname) === 2) { + return NCNameValue::fromString($qname[0]); + } + + return null; + } + + + /** + * Get the local name for this qualified name. + * + * @return \SimpleSAML\XML\Type\NCNameValue + */ + public function getLocalName(): NCNameValue + { + $qname = explode(':', $this->getValue(), 2); + if (count($qname) === 2) { + return NCNameValue::fromString($qname[1]); + } + + return NCNameValue::fromString($qname[0]); + } } diff --git a/src/Type/TimeValue.php b/src/Type/TimeValue.php index fb46d02e..debb85d7 100644 --- a/src/Type/TimeValue.php +++ b/src/Type/TimeValue.php @@ -12,6 +12,18 @@ */ class TimeValue extends AbstractValueType { + /** + * Sanitize the value. + * + * @param string $value The unsanitized value + * @return string + */ + protected function sanitizeValue(string $value): string + { + return static::collapseWhitespace(static::normalizeWhitespace($value)); + } + + /** * Validate the value. * @@ -21,6 +33,6 @@ class TimeValue extends AbstractValueType */ protected function validateValue(string $value): void { - Assert::validTime($value, SchemaViolationException::class); + Assert::validTime($this->sanitizeValue($value), SchemaViolationException::class); } } diff --git a/src/Type/TokenValue.php b/src/Type/TokenValue.php index 53eb6023..cdfd664f 100644 --- a/src/Type/TokenValue.php +++ b/src/Type/TokenValue.php @@ -4,9 +4,6 @@ namespace SimpleSAML\XML\Type; -use function preg_replace; -use function trim; - /** * @package simplesaml/xml-common */ @@ -20,6 +17,6 @@ class TokenValue extends NormalizedStringValue */ protected function sanitizeValue(string $value): string { - return trim(preg_replace('/\s+/', ' ', parent::sanitizeValue($value))); + return static::collapseWhitespace(static::normalizeWhitespace($value)); } } diff --git a/src/Type/YearMonthValue.php b/src/Type/YearMonthValue.php index 6cde1031..f49063e7 100644 --- a/src/Type/YearMonthValue.php +++ b/src/Type/YearMonthValue.php @@ -7,9 +7,6 @@ use SimpleSAML\XML\Assert\Assert; use SimpleSAML\XML\Exception\SchemaViolationException; -use function preg_replace; -use function trim; - /** * @package simplesaml/xml-common */ @@ -23,7 +20,7 @@ class YearMonthValue extends AbstractValueType */ protected function sanitizeValue(string $value): string { - return trim(preg_replace('/\s+/', ' ', $value)); + return static::collapseWhitespace(static::normalizeWhitespace($value)); } diff --git a/src/Type/YearValue.php b/src/Type/YearValue.php index 702691db..06d2a412 100644 --- a/src/Type/YearValue.php +++ b/src/Type/YearValue.php @@ -7,9 +7,6 @@ use SimpleSAML\XML\Assert\Assert; use SimpleSAML\XML\Exception\SchemaViolationException; -use function preg_replace; -use function trim; - /** * @package simplesaml/xml-common */ @@ -23,7 +20,7 @@ class YearValue extends AbstractValueType */ protected function sanitizeValue(string $value): string { - return trim(preg_replace('/\s+/', ' ', $value)); + return static::collapseWhitespace(static::normalizeWhitespace($value)); } diff --git a/tests/Assert/AnyURITest.php b/tests/Assert/AnyURITest.php index 6f0a9cf2..6d892009 100644 --- a/tests/Assert/AnyURITest.php +++ b/tests/Assert/AnyURITest.php @@ -21,7 +21,7 @@ final class AnyURITest extends TestCase * @param boolean $shouldPass * @param string $uri */ - #[DataProvider('provideURI')] + #[DataProvider('provideValidURI')] public function testValidURI(bool $shouldPass, string $uri): void { try { @@ -36,7 +36,7 @@ public function testValidURI(bool $shouldPass, string $uri): void /** * @return array */ - public static function provideURI(): array + public static function provideValidURI(): array { return [ 'urn' => [true, 'urn:x-simplesamlphp:phpunit'], diff --git a/tests/Assert/Base64BinaryTest.php b/tests/Assert/Base64BinaryTest.php index 1b4eddd9..2ec999b4 100644 --- a/tests/Assert/Base64BinaryTest.php +++ b/tests/Assert/Base64BinaryTest.php @@ -21,7 +21,8 @@ final class Base64BinaryTest extends TestCase * @param boolean $shouldPass * @param string $base64 */ - #[DataProvider('provideBase64')] + #[DataProvider('provideInvalidBase64')] + #[DataProvider('provideValidBase64')] public function testValidBase64Binary(bool $shouldPass, string $base64): void { try { @@ -34,15 +35,26 @@ public function testValidBase64Binary(bool $shouldPass, string $base64): void /** - * @return array + * @return array */ - public static function provideBase64(): array + public static function provideValidBase64(): array { return [ - 'empty' => [false, ''], 'valid' => [true, 'U2ltcGxlU0FNTHBocA=='], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidBase64(): array + { + return [ + 'empty' => [false, ''], 'illegal characters' => [false, '&*$(#&^@!(^%$'], 'length not dividable by 4' => [false, 'U2ltcGxlU0FTHBocA=='], + 'whitespace' => [false, 'U2ltcGxl U0FNTHBocA=='], ]; } } diff --git a/tests/Assert/BooleanTest.php b/tests/Assert/BooleanTest.php index 8170761f..20ce1b7b 100644 --- a/tests/Assert/BooleanTest.php +++ b/tests/Assert/BooleanTest.php @@ -21,7 +21,8 @@ final class BooleanTest extends TestCase * @param boolean $shouldPass * @param string $boolean */ - #[DataProvider('provideBoolean')] + #[DataProvider('provideInvalidBoolean')] + #[DataProvider('provideValidBoolean')] public function testValidBoolean(bool $shouldPass, string $boolean): void { try { @@ -34,15 +35,25 @@ public function testValidBoolean(bool $shouldPass, string $boolean): void /** - * @return array + * @return array */ - public static function provideBoolean(): array + public static function provideValidBoolean(): array { return [ 'true' => [true, 'true'], 'false' => [true, 'false'], 'one' => [true, '1'], 'zero' => [true, '0'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidBoolean(): array + { + return [ 'vrai' => [false, 'vrai'], 'faux' => [false, 'faux'], ]; diff --git a/tests/Assert/ByteTest.php b/tests/Assert/ByteTest.php index 59654391..200220b0 100644 --- a/tests/Assert/ByteTest.php +++ b/tests/Assert/ByteTest.php @@ -21,7 +21,8 @@ final class ByteTest extends TestCase * @param boolean $shouldPass * @param string $byte */ - #[DataProvider('provideByte')] + #[DataProvider('provideInvalidByte')] + #[DataProvider('provideValidByte')] public function testValidByte(bool $shouldPass, string $byte): void { try { @@ -34,17 +35,27 @@ public function testValidByte(bool $shouldPass, string $byte): void /** - * @return array + * @return array */ - public static function provideByte(): array + public static function provideValidByte(): array { return [ - 'empty' => [false, ''], 'valid positive signed' => [true, '+127'], 'valid negative signed' => [true, '-128'], 'valid non-signed' => [true, '123'], 'valid leading zeros' => [true, '-0001'], 'valid zero' => [true, '0'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidByte(): array + { + return [ + 'empty' => [false, ''], 'invalid positive signed out-of-bounds' => [false, '+128'], 'invalid negative signed out-of-bounds' => [false, '-129'], 'invalid with space' => [false, '1 23'], diff --git a/tests/Assert/DateTest.php b/tests/Assert/DateTest.php index 72a5c62b..86abfd36 100644 --- a/tests/Assert/DateTest.php +++ b/tests/Assert/DateTest.php @@ -21,7 +21,8 @@ final class DateTest extends TestCase * @param boolean $shouldPass * @param string $date */ - #[DataProvider('provideDate')] + #[DataProvider('provideInvalidDate')] + #[DataProvider('provideValidDate')] public function testValidDate(bool $shouldPass, string $date): void { try { @@ -34,9 +35,9 @@ public function testValidDate(bool $shouldPass, string $date): void /** - * @return array + * @return array */ - public static function provideDate(): array + public static function provideValidDate(): array { return [ 'valid' => [true, '2001-10-26'], @@ -45,6 +46,16 @@ public static function provideDate(): array 'valid 00:00 timezone' => [true, '2001-10-26+00:00'], '2001 BC' => [true, '-2001-10-26'], '2000 BC' => [true, '-20000-04-01'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidDate(): array + { + return [ 'missing part' => [false, '2001-10'], 'day out of range' => [false, '2001-10-32'], 'month out of range' => [false, '2001-13-26+02:00'], diff --git a/tests/Assert/DateTimeTest.php b/tests/Assert/DateTimeTest.php index a206f470..f6bf8296 100644 --- a/tests/Assert/DateTimeTest.php +++ b/tests/Assert/DateTimeTest.php @@ -21,7 +21,8 @@ final class DateTimeTest extends TestCase * @param boolean $shouldPass * @param string $dateTime */ - #[DataProvider('provideDateTime')] + #[DataProvider('provideInvalidDateTime')] + #[DataProvider('provideValidDateTime')] public function testValidDateTime(bool $shouldPass, string $dateTime): void { try { @@ -34,9 +35,9 @@ public function testValidDateTime(bool $shouldPass, string $dateTime): void /** - * @return array + * @return array */ - public static function provideDateTime(): array + public static function provideValidDateTime(): array { return [ 'valid' => [true, '2001-10-26T21:32:52'], @@ -47,6 +48,16 @@ public static function provideDateTime(): array 'valid with subseconds' => [true, '2001-10-26T21:32:52.12679'], 'valid with more than four digit year' => [true, '-22001-10-26T21:32:52+02:00'], 'valid with sub-seconds' => [true, '2001-10-26T21:32:52.12679'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidDateTime(): array + { + return [ 'missing time' => [false, '2001-10-26'], 'missing second' => [false, '2001-10-26T21:32'], 'hour out of range' => [false, '2001-10-26T25:32:52+02:00'], diff --git a/tests/Assert/DayTest.php b/tests/Assert/DayTest.php index 9ebda675..07ecf484 100644 --- a/tests/Assert/DayTest.php +++ b/tests/Assert/DayTest.php @@ -21,7 +21,8 @@ final class DayTest extends TestCase * @param boolean $shouldPass * @param string $day */ - #[DataProvider('provideDay')] + #[DataProvider('provideInvalidDay')] + #[DataProvider('provideValidDay')] public function testValidDay(bool $shouldPass, string $day): void { try { @@ -34,9 +35,9 @@ public function testValidDay(bool $shouldPass, string $day): void /** - * @return array + * @return array */ - public static function provideDay(): array + public static function provideValidDay(): array { return [ 'valid' => [true, '---01'], @@ -45,6 +46,16 @@ public static function provideDay(): array 'valid 00:00 timezone' => [true, '---01+00:00'], 'day 15' => [true, '---15'], 'day 31' => [true, '---31'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidDay(): array + { + return [ 'invalid format' => [false, '--30-'], 'day out of range' => [false, '---35'], 'missing leading dashes' => [false, '15'], diff --git a/tests/Assert/DecimalTest.php b/tests/Assert/DecimalTest.php index f9b7d526..cd824673 100644 --- a/tests/Assert/DecimalTest.php +++ b/tests/Assert/DecimalTest.php @@ -21,7 +21,8 @@ final class DecimalTest extends TestCase * @param boolean $shouldPass * @param string $decimal */ - #[DataProvider('provideDecimal')] + #[DataProvider('provideInvalidDecimal')] + #[DataProvider('provideValidDecimal')] public function testValidDecimal(bool $shouldPass, string $decimal): void { try { @@ -34,17 +35,27 @@ public function testValidDecimal(bool $shouldPass, string $decimal): void /** - * @return array + * @return array */ - public static function provideDecimal(): array + public static function provideValidDecimal(): array { return [ - 'empty' => [false, ''], 'valid decimal' => [true, '123.456'], 'valid positive signed' => [true, '+123.456'], 'valid negative signed' => [true, '-123.456'], 'valid fractional only' => [true, '-.456'], 'valid without fraction' => [true, '-456'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidDecimal(): array + { + return [ + 'empty' => [false, ''], 'invalid with space' => [false, '1 234.456'], 'invalid scientific notation' => [false, '1234.456E+2'], 'invalid signed with space' => [false, '+ 1234.456'], diff --git a/tests/Assert/DoubleTest.php b/tests/Assert/DoubleTest.php index 89d80b6e..df76755a 100644 --- a/tests/Assert/DoubleTest.php +++ b/tests/Assert/DoubleTest.php @@ -21,7 +21,8 @@ final class DoubleTest extends TestCase * @param boolean $shouldPass * @param string $double */ - #[DataProvider('provideDouble')] + #[DataProvider('provideInvalidDouble')] + #[DataProvider('provideValidDouble')] public function testValidDouble(bool $shouldPass, string $double): void { try { @@ -34,21 +35,31 @@ public function testValidDouble(bool $shouldPass, string $double): void /** - * @return array + * @return array */ - public static function provideDouble(): array + public static function provideValidDouble(): array { return [ - 'empty' => [false, ''], 'valid positive signed' => [true, '+123.456'], 'valid negative signed' => [true, '-123.456'], 'valid non-signed' => [true, '123.456'], 'valid leading zeros' => [true, '-0123.456'], 'valid zero' => [true, '0.0'], 'valid NaN' => [true, 'NaN'], - 'case-sensitive NaN' => [false, 'NAN'], 'valid negative FIN' => [true, '-FIN'], 'valid FIN' => [true, 'FIN'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidDouble(): array + { + return [ + 'empty' => [false, ''], + 'case-sensitive NaN' => [false, 'NAN'], 'invalid +FIN' => [false, '+FIN'], 'invalid with space' => [false, '1 23.0'], 'invalid without fractional' => [false, '123'], diff --git a/tests/Assert/DurationTest.php b/tests/Assert/DurationTest.php index c2549b01..9c2c874f 100644 --- a/tests/Assert/DurationTest.php +++ b/tests/Assert/DurationTest.php @@ -21,7 +21,8 @@ final class DurationTest extends TestCase * @param boolean $shouldPass * @param string $duration */ - #[DataProvider('provideDuration')] + #[DataProvider('provideInvalidDuration')] + #[DataProvider('provideValidDuration')] public function testValidDuration(bool $shouldPass, string $duration): void { try { @@ -34,9 +35,9 @@ public function testValidDuration(bool $shouldPass, string $duration): void /** - * @return array + * @return array */ - public static function provideDuration(): array + public static function provideValidDuration(): array { return [ 'valid long seconds' => [true, 'PT1004199059S'], @@ -45,6 +46,16 @@ public static function provideDuration(): array 'valid one day and two seconds' => [true, 'P1DT2S'], 'valid minus one year' => [true, '-P1Y'], 'valid complex sub-second' => [true, 'P1Y2M3DT5H20M30.123S'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidDuration(): array + { + return [ 'invalid missing P' => [false, '1Y'], 'invalid missing T' => [false, 'P1S'], 'invalid all parts must be positive' => [false, 'P-1Y'], diff --git a/tests/Assert/EntitiesTest.php b/tests/Assert/EntitiesTest.php index cbf3c265..3a87e5bd 100644 --- a/tests/Assert/EntitiesTest.php +++ b/tests/Assert/EntitiesTest.php @@ -21,7 +21,8 @@ final class EntitiesTest extends TestCase * @param boolean $shouldPass * @param string $entities */ - #[DataProvider('provideEntities')] + #[DataProvider('provideInvalidEntities')] + #[DataProvider('provideValidEntities')] public function testValidEntities(bool $shouldPass, string $entities): void { try { @@ -34,23 +35,30 @@ public function testValidEntities(bool $shouldPass, string $entities): void /** - * @return array + * @return array */ - public static function provideEntities(): array + public static function provideValidEntities(): array { return [ - [true, 'Snoopy'], - [true, 'CMS'], - [true, 'fööbár'], - [false, '-1950-10-04'], - [false, '0836217462 0836217463'], - [true, 'foo bar'], - // Quotes are forbidden - [false, 'foo "bar" baz'], - // Commas are forbidden - [false, 'foo,bar'], - // Trailing newlines are forbidden - [false, "foobar\n"], + 'valid' => [true, 'Snoopy foobar'], + 'diacritical' => [true, 'Snööpy fööbár'], + 'start with underscore' => [true, '_1950-10-04 foobar'], + 'space' => [true, 'foo bar'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidEntities(): array + { + return [ + 'start with colon' => [false, ':foobar :CMS'], + 'invalid first char' => [false, '0836217462 1378943'], + 'empty string' => [false, ''], + 'colon' => [false, 'foo:bar'], + 'comma' => [false, 'foo,bar'], ]; } } diff --git a/tests/Assert/EntityTest.php b/tests/Assert/EntityTest.php new file mode 100644 index 00000000..aeb5d817 --- /dev/null +++ b/tests/Assert/EntityTest.php @@ -0,0 +1,64 @@ +assertTrue($shouldPass); + } catch (AssertionFailedException $e) { + $this->assertFalse($shouldPass); + } + } + + + /** + * @return array + */ + public static function provideValidEntity(): array + { + return [ + 'valid' => [true, 'Snoopy'], + 'diacritical' => [true, 'Snööpy'], + 'start with underscore' => [true, '_1950-10-04'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidEntity(): array + { + return [ + 'start with colon' => [false, ':foobar'], + 'invalid first char' => [false, '0836217462'], + 'empty string' => [false, ''], + 'colon' => [false, 'foo:bar'], + 'comma' => [false, 'foo,bar'], + 'space' => [false, 'foo bar'], + ]; + } +} diff --git a/tests/Assert/FloatTest.php b/tests/Assert/FloatTest.php index 6bca72e3..70a7138d 100644 --- a/tests/Assert/FloatTest.php +++ b/tests/Assert/FloatTest.php @@ -21,7 +21,8 @@ final class FloatTest extends TestCase * @param boolean $shouldPass * @param string $float */ - #[DataProvider('provideFloat')] + #[DataProvider('provideInvalidFloat')] + #[DataProvider('provideValidFloat')] public function testValidFloat(bool $shouldPass, string $float): void { try { @@ -34,21 +35,31 @@ public function testValidFloat(bool $shouldPass, string $float): void /** - * @return array + * @return array */ - public static function provideFloat(): array + public static function provideValidFloat(): array { return [ - 'empty' => [false, ''], 'valid positive signed' => [true, '+123.456'], 'valid negative signed' => [true, '-123.456'], 'valid non-signed' => [true, '123.456'], 'valid leading zeros' => [true, '-0123.456'], 'valid zero' => [true, '0.0'], 'valid NaN' => [true, 'NaN'], - 'case-sensitive NaN' => [false, 'NAN'], 'valid negative FIN' => [true, '-FIN'], 'valid FIN' => [true, 'FIN'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidFloat(): array + { + return [ + 'empty' => [false, ''], + 'case-sensitive NaN' => [false, 'NAN'], 'invalid +FIN' => [false, '+FIN'], 'invalid with space' => [false, '1 23.0'], 'invalid without fractional' => [false, '123'], diff --git a/tests/Assert/HexBinaryTest.php b/tests/Assert/HexBinaryTest.php index fccab18e..45467809 100644 --- a/tests/Assert/HexBinaryTest.php +++ b/tests/Assert/HexBinaryTest.php @@ -21,7 +21,8 @@ final class HexBinaryTest extends TestCase * @param boolean $shouldPass * @param string $name */ - #[DataProvider('provideHexBinary')] + #[DataProvider('provideInvalidHexBinary')] + #[DataProvider('provideValidHexBinary')] public function testHexBinary(bool $shouldPass, string $name): void { try { @@ -34,14 +35,24 @@ public function testHexBinary(bool $shouldPass, string $name): void /** - * @return array + * @return array */ - public static function provideHexBinary(): array + public static function provideValidHexBinary(): array + { + return [ + 'valid' => [true, '3f3c6d78206c657673726f693d6e3122302e20226e656f636964676e223d54552d4622383e3f'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidHexBinary(): array { return [ 'empty' => [false, ''], 'base64' => [false, 'U2ltcGxlU0FNTHBocA=='], - 'valid' => [true, '3f3c6d78206c657673726f693d6e3122302e20226e656f636964676e223d54552d4622383e3f'], 'invalid' => [false, '3f3r'], 'bogus' => [false, '&*$(#&^@!(^%$'], 'length not dividable by 4' => [false, '3f3'], diff --git a/tests/Assert/IDRefTest.php b/tests/Assert/IDRefTest.php index 04729883..7c281321 100644 --- a/tests/Assert/IDRefTest.php +++ b/tests/Assert/IDRefTest.php @@ -21,7 +21,8 @@ final class IDRefTest extends TestCase * @param boolean $shouldPass * @param string $idref */ - #[DataProvider('provideIDRef')] + #[DataProvider('provideInvalidIDRef')] + #[DataProvider('provideValidIDRef')] public function testValidIDRef(bool $shouldPass, string $idref): void { try { @@ -34,32 +35,32 @@ public function testValidIDRef(bool $shouldPass, string $idref): void /** - * @return array + * @return array */ - public static function provideIDRef(): array + public static function provideValidIDRef(): array { return [ - [true, 'Test'], - // May start with an underscore - [true, '_Test'], - // May contain dashes - [true, '_1950-10-04_10-00'], - // May contain dots - [true, 'Te.st'], - // May contain diacriticals - [true, 'fööbár'], - // Prefixed v4 UUID - [true, '_5425e58e-e799-4884-92cc-ca64ecede32f'], - // An empty value is not valid, unless xsi:nil is used - [false, ''], - // Wildcards are not allowed - [false, 'Te*st'], - // May not start with a digit - [false, '1Test'], - // May not contain a colon - [false, 'Te:st'], - // Trailing newlines are forbidden - [false, "Test\n"], + 'valid' => [true, 'Test'], + 'valid starts with underscore' => [true, '_Test'], + 'valid contains dashes' => [true, '_1950-10-04_10-00'], + 'valid contains dots' => [true, 'Te.st'], + 'valid contains diacriticals' => [true, 'fööbár'], + 'valid prefixed v4 UUID' => [true, '_5425e58e-e799-4884-92cc-ca64ecede32f'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidIDRef(): array + { + return [ + 'invalid empty string' => [false, ''], + 'invalid contains wildcard' => [false, 'Te*st'], + 'invalid starts with digit' => [false, '1Test'], + 'invalid contains colon' => [false, 'Te:st'], + 'trailing newline' => [false, "Test\n"], ]; } } diff --git a/tests/Assert/IDRefsTest.php b/tests/Assert/IDRefsTest.php index 3eedaca0..bc382ffd 100644 --- a/tests/Assert/IDRefsTest.php +++ b/tests/Assert/IDRefsTest.php @@ -21,7 +21,8 @@ final class IDRefsTest extends TestCase * @param boolean $shouldPass * @param string $idrefs */ - #[DataProvider('provideIDRefs')] + #[DataProvider('provideInvalidIDRefs')] + #[DataProvider('provideValidIDRefs')] public function testValidIDRefs(bool $shouldPass, string $idrefs): void { try { @@ -34,23 +35,31 @@ public function testValidIDRefs(bool $shouldPass, string $idrefs): void /** - * @return array + * @return array */ - public static function provideIDRefs(): array + public static function provideValidIDRefs(): array { return [ - [true, 'Snoopy'], - [true, 'CMS'], - [true, 'fööbár'], - [false, '-1950-10-04'], - [false, '0836217462 0836217463'], - [true, 'foo bar'], - // Quotes are forbidden - [false, 'foo "bar" baz'], - // Commas are forbidden - [false, 'foo,bar'], - // Trailing newlines are forbidden - [false, "foobar\n"], + 'valid' => [true, 'Snoopy foobar'], + 'diacritical' => [true, 'Snööpy fööbár'], + 'start with underscore' => [true, '_1950-10-04 foobar'], + 'space' => [true, 'foo bar'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidIDRefs(): array + { + return [ + 'start with colon' => [false, 'foobar :CMS'], + 'start with dash' => [false, '-1950-10-04 foobar'], + 'invalid first char' => [false, '0836217462 1378943'], + 'empty string' => [false, ''], + 'colon' => [false, 'foo:bar'], + 'comma' => [false, 'foo,bar'], ]; } } diff --git a/tests/Assert/IDTest.php b/tests/Assert/IDTest.php index b75c8756..3139d266 100644 --- a/tests/Assert/IDTest.php +++ b/tests/Assert/IDTest.php @@ -21,7 +21,8 @@ final class IDTest extends TestCase * @param boolean $shouldPass * @param string $id */ - #[DataProvider('provideID')] + #[DataProvider('provideInvalidID')] + #[DataProvider('provideValidID')] public function testValidID(bool $shouldPass, string $id): void { try { @@ -34,32 +35,32 @@ public function testValidID(bool $shouldPass, string $id): void /** - * @return array + * @return array */ - public static function provideID(): array + public static function provideValidID(): array { return [ - [true, 'Test'], - // May start with an underscore - [true, '_Test'], - // May contain dashes - [true, '_1950-10-04_10-00'], - // May contain dots - [true, 'Te.st'], - // May contain diacriticals - [true, 'fööbár'], - // Prefixed v4 UUID - [true, '_5425e58e-e799-4884-92cc-ca64ecede32f'], - // An empty value is not valid, unless xsi:nil is used - [false, ''], - // Wildcards are not allowed - [false, 'Te*st'], - // May not start with a digit - [false, '1Test'], - // May not contain a colon - [false, 'Te:st'], - // Trailing newlines are forbidden - [false, "Test\n"], + 'valid' => [true, 'Test'], + 'valid starts with underscore' => [true, '_Test'], + 'valid contains dashes' => [true, '_1950-10-04_10-00'], + 'valid contains dots' => [true, 'Te.st'], + 'valid contains diacriticals' => [true, 'fööbár'], + 'valid prefixed v4 UUID' => [true, '_5425e58e-e799-4884-92cc-ca64ecede32f'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidID(): array + { + return [ + 'invalid empty string' => [false, ''], + 'invalid contains wildcard' => [false, 'Te*st'], + 'invalid starts with digit' => [false, '1Test'], + 'invalid contains colon' => [false, 'Te:st'], + 'trailing newline' => [false, "Test\n"], ]; } } diff --git a/tests/Assert/IntTest.php b/tests/Assert/IntTest.php index a865ca3a..c626cd4f 100644 --- a/tests/Assert/IntTest.php +++ b/tests/Assert/IntTest.php @@ -21,7 +21,8 @@ final class IntTest extends TestCase * @param boolean $shouldPass * @param string $int */ - #[DataProvider('provideInt')] + #[DataProvider('provideInvalidInt')] + #[DataProvider('provideValidInt')] public function testValidInt(bool $shouldPass, string $int): void { try { @@ -34,17 +35,27 @@ public function testValidInt(bool $shouldPass, string $int): void /** - * @return array + * @return array */ - public static function provideInt(): array + public static function provideValidInt(): array { return [ - 'empty' => [false, ''], 'valid positive signed' => [true, '+2147483647'], 'valid negative signed' => [true, '-2147483648'], 'valid non-signed' => [true, '123'], 'valid leading zeros' => [true, '-0001'], 'valid zero' => [true, '0'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidInt(): array + { + return [ + 'empty' => [false, ''], 'invalid positive signed out-of-bounds' => [false, '+2147483648'], 'invalid negative signed out-of-bounds' => [false, '-2147483649'], 'invalid with space' => [false, '1 234'], diff --git a/tests/Assert/IntegerTest.php b/tests/Assert/IntegerTest.php index ce40fea1..c28eb30e 100644 --- a/tests/Assert/IntegerTest.php +++ b/tests/Assert/IntegerTest.php @@ -21,7 +21,8 @@ final class IntegerTest extends TestCase * @param boolean $shouldPass * @param string $integer */ - #[DataProvider('provideInteger')] + #[DataProvider('provideInvalidInteger')] + #[DataProvider('provideValidInteger')] public function testValidInteger(bool $shouldPass, string $integer): void { try { @@ -34,15 +35,25 @@ public function testValidInteger(bool $shouldPass, string $integer): void /** - * @return array + * @return array */ - public static function provideInteger(): array + public static function provideValidInteger(): array { return [ - 'empty' => [false, ''], 'valid integer' => [true, '123456'], 'valid positive signed' => [true, '+00000012'], 'valid negative signed' => [true, '-1'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidInteger(): array + { + return [ + 'empty' => [false, ''], 'invalid with space' => [false, '1 234'], 'invalid with fractional' => [false, '1234.'], 'invalid with thousands-delimiter' => [false, '+1,234'], diff --git a/tests/Assert/LanguageTest.php b/tests/Assert/LanguageTest.php index ff04f238..ee94125d 100644 --- a/tests/Assert/LanguageTest.php +++ b/tests/Assert/LanguageTest.php @@ -21,7 +21,8 @@ final class LanguageTest extends TestCase * @param boolean $shouldPass * @param string $language */ - #[DataProvider('provideLanguage')] + #[DataProvider('provideInvalidLanguage')] + #[DataProvider('provideValidLanguage')] public function testValidLanguage(bool $shouldPass, string $language): void { try { @@ -34,18 +35,28 @@ public function testValidLanguage(bool $shouldPass, string $language): void /** - * @return array + * @return array */ - public static function provideLanguage(): array + public static function provideValidLanguage(): array { return [ - 'empty string' => [false, ''], 'one part' => [true, 'es'], 'two parts' => [true, 'en-US'], 'many parts' => [true, 'es-this-goes-on-forever'], - 'too long' => [false, 'toolongLanguageuage'], 'x-case' => [true, 'x-klingon'], 'i-case' => [true, 'i-sami-no'], ]; } + + + /** + * @return array + */ + public static function provideInvalidLanguage(): array + { + return [ + 'empty string' => [false, ''], + 'too long' => [false, 'toolongLanguageuage'], + ]; + } } diff --git a/tests/Assert/LongTest.php b/tests/Assert/LongTest.php index f9e509f8..76096ac2 100644 --- a/tests/Assert/LongTest.php +++ b/tests/Assert/LongTest.php @@ -21,7 +21,8 @@ final class LongTest extends TestCase * @param boolean $shouldPass * @param string $long */ - #[DataProvider('provideLong')] + #[DataProvider('provideInvalidLong')] + #[DataProvider('provideValidLong')] public function testValidLong(bool $shouldPass, string $long): void { try { @@ -34,17 +35,27 @@ public function testValidLong(bool $shouldPass, string $long): void /** - * @return array + * @return array */ - public static function provideLong(): array + public static function provideValidLong(): array { return [ - 'empty' => [false, ''], 'valid positive signed' => [true, '+9223372036854775807'], 'valid negative signed' => [true, '-9223372036854775808'], 'valid non-signed' => [true, '9223372036854775807'], 'valid leading zeros' => [true, '-0001'], 'valid zero' => [true, '0'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidLong(): array + { + return [ + 'empty' => [false, ''], 'invalid positive signed out-of-bounds' => [false, '+9223372036854775808'], 'invalid negative signed out-of-bounds' => [false, '-9223372036854775809'], 'invalid with space' => [false, '1 234'], diff --git a/tests/Assert/MonthTest.php b/tests/Assert/MonthTest.php index 125945f9..2e841e51 100644 --- a/tests/Assert/MonthTest.php +++ b/tests/Assert/MonthTest.php @@ -21,7 +21,8 @@ final class MonthTest extends TestCase * @param boolean $shouldPass * @param string $month */ - #[DataProvider('provideMonth')] + #[DataProvider('provideInvalidMonth')] + #[DataProvider('provideValidMonth')] public function testValidMonth(bool $shouldPass, string $month): void { try { @@ -34,9 +35,9 @@ public function testValidMonth(bool $shouldPass, string $month): void /** - * @return array + * @return array */ - public static function provideMonth(): array + public static function provideValidMonth(): array { return [ 'valid' => [true, '--05'], @@ -44,6 +45,16 @@ public static function provideMonth(): array 'valid Zulu timezone' => [true, '--11Z'], 'valid 00:00 timezone' => [true, '--11+00:00'], 'month 02' => [true, '--02'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidMonth(): array + { + return [ 'invalid format' => [false, '-01-'], 'month out of range' => [false, '--13'], 'both digits must be provided' => [false, '--1'], diff --git a/tests/Assert/NCNameTest.php b/tests/Assert/NCNameTest.php index 9c3ed2f2..6a72cc65 100644 --- a/tests/Assert/NCNameTest.php +++ b/tests/Assert/NCNameTest.php @@ -21,7 +21,8 @@ final class NCNameTest extends TestCase * @param boolean $shouldPass * @param string $ncName */ - #[DataProvider('provideNCName')] + #[DataProvider('provideInvalidNCName')] + #[DataProvider('provideValidNCName')] public function testValidNCName(bool $shouldPass, string $ncName): void { try { @@ -34,32 +35,33 @@ public function testValidNCName(bool $shouldPass, string $ncName): void /** - * @return array + * @return array */ - public static function provideNCName(): array + public static function provideValidNCName(): array { return [ - [true, 'Test'], - // May start with an underscore - [true, '_Test'], - // May contain dashes - [true, '_1950-10-04_10-00'], - // May contain dots - [true, 'Te.st'], - // May contain diacriticals - [true, 'fööbár'], - // Prefixed v4 UUID - [true, '_5425e58e-e799-4884-92cc-ca64ecede32f'], - // An empty value is not valid, unless xsi:nil is used - [false, ''], - // Wildcards are not allowed - [false, 'Te*st'], - // May not start with a digit - [false, '1Test'], - // May not contain a colon - [false, 'Te:st'], - // Trailing newlines are forbidden - [false, "Test\n"], + 'valid' => [true, 'Test'], + 'valid starts with underscore' => [true, '_Test'], + 'valid contains dashes' => [true, '_1950-10-04_10-00'], + 'valid contains dots' => [true, 'Te.st'], + 'valid contains diacriticals' => [true, 'fööbár'], + 'valid prefixed v4 UUID' => [true, '_5425e58e-e799-4884-92cc-ca64ecede32f'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidNCName(): array + { + return [ + 'invalid empty string' => [false, ''], + 'invalid contains wildcard' => [false, 'Te*st'], + 'invalid starts with dash' => [false, '-Test'], + 'invalid starts with digit' => [false, '1Test'], + 'invalid contains colon' => [false, 'Te:st'], + 'trailing newline' => [false, "Test\n"], ]; } } diff --git a/tests/Assert/NMTokenTest.php b/tests/Assert/NMTokenTest.php index 73a14022..d5873019 100644 --- a/tests/Assert/NMTokenTest.php +++ b/tests/Assert/NMTokenTest.php @@ -21,7 +21,8 @@ final class NMTokenTest extends TestCase * @param boolean $shouldPass * @param string $nmtoken */ - #[DataProvider('provideNMToken')] + #[DataProvider('provideInvalidNMToken')] + #[DataProvider('provideValidNMToken')] public function testValidToken(bool $shouldPass, string $nmtoken): void { try { @@ -34,22 +35,29 @@ public function testValidToken(bool $shouldPass, string $nmtoken): void /** - * @return array + * @return array */ - public static function provideNMToken(): array + public static function provideValidNMToken(): array { return [ - [true, 'Snoopy'], - [true, 'CMS'], - [true, 'fööbár'], - [true, '1950-10-04'], - [true, '0836217462'], - // Spaces are forbidden - [false, 'foo bar'], - // Commas are forbidden - [false, 'foo,bar'], - // Trailing newlines are forbidden - [false, "foobar\n"], + 'valid' => [true, 'Snoopy'], + 'diacritical' => [true, 'fööbár'], + 'start with colon' => [true, ':CMS'], + 'start with dash' => [true, '-1950-10-04'], + 'numeric first char' => [true, '0836217462'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidNMToken(): array + { + return [ + 'space' => [false, 'foo bar'], + 'comma' => [false, 'foo,bar'], + 'trailing newline' => [false, "foobar\n"], ]; } } diff --git a/tests/Assert/NMTokensTest.php b/tests/Assert/NMTokensTest.php index ddf562e4..ecdeee85 100644 --- a/tests/Assert/NMTokensTest.php +++ b/tests/Assert/NMTokensTest.php @@ -21,7 +21,8 @@ final class NMTokensTest extends TestCase * @param boolean $shouldPass * @param string $nmtokens */ - #[DataProvider('provideNMTokens')] + #[DataProvider('provideInvalidNMTokens')] + #[DataProvider('provideValidNMTokens')] public function testValidTokens(bool $shouldPass, string $nmtokens): void { try { @@ -34,23 +35,29 @@ public function testValidTokens(bool $shouldPass, string $nmtokens): void /** - * @return array + * @return array */ - public static function provideNMTokens(): array + public static function provideValidNMTokens(): array { return [ - [true, 'Snoopy'], - [true, 'CMS'], - [true, 'fööbár'], - [true, '1950-10-04'], - [true, '0836217462 0836217463'], - [true, 'foo bar'], - // Quotes are forbidden - [false, 'foo "bar" baz'], - // Commas are forbidden - [false, 'foo,bar'], - // Trailing whitespace is forbidden - [false, "foobar\n"], + 'valid' => [true, 'Snoopy foobar'], + 'diacritical' => [true, 'Snoopy fööbár'], + 'start with colon' => [true, ':CMS :ABC'], + 'start with dash' => [true, '-1950-10-04 -1984-11-07'], + 'numeric first char' => [true, '0836217462'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidNMTokens(): array + { + return [ + 'comma' => [false, 'foo,bar'], + 'quotes' => [false, 'foo "bar" baz'], + 'trailing newline' => [false, "foobar\n"], ]; } } diff --git a/tests/Assert/NameTest.php b/tests/Assert/NameTest.php index 307c0442..e0e2b329 100644 --- a/tests/Assert/NameTest.php +++ b/tests/Assert/NameTest.php @@ -21,7 +21,8 @@ final class NameTest extends TestCase * @param boolean $shouldPass * @param string $name */ - #[DataProvider('provideName')] + #[DataProvider('provideInvalidName')] + #[DataProvider('provideValidName')] public function testValidToken(bool $shouldPass, string $name): void { try { @@ -34,25 +35,29 @@ public function testValidToken(bool $shouldPass, string $name): void /** - * @return array + * @return array */ - public static function provideName(): array + public static function provideValidName(): array { return [ - [true, 'Snoopy'], - [true, ':CMS'], - [true, 'fööbár'], - [true, '-1950-10-04'], - // The empty string is not valid - [false, ''], - // Must start with a letter, a dash or a colon - [false, '0836217462'], - // Spaces are forbidden - [false, 'foo bar'], - // Commas are forbidden - [false, 'foo,bar'], - // Trailing newlines are forbidden - [false, "foobar\n"], + 'valid' => [true, 'Snoopy'], + 'diacritical' => [true, 'fööbár'], + 'start with colon' => [true, ':CMS'], + 'start with dash' => [true, '-1950-10-04'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidName(): array + { + return [ + 'invalid first char' => [false, '0836217462'], + 'empty string' => [false, ''], + 'space' => [false, 'foo bar'], + 'comma' => [false, 'foo,bar'], ]; } } diff --git a/tests/Assert/NegativeIntegerTest.php b/tests/Assert/NegativeIntegerTest.php index 86ae7425..94e59f06 100644 --- a/tests/Assert/NegativeIntegerTest.php +++ b/tests/Assert/NegativeIntegerTest.php @@ -21,7 +21,8 @@ final class NegativeIntegerTest extends TestCase * @param boolean $shouldPass * @param string $negativeInteger */ - #[DataProvider('provideNegativeInteger')] + #[DataProvider('provideInvalidNegativeInteger')] + #[DataProvider('provideValidNegativeInteger')] public function testValidNegativeInteger(bool $shouldPass, string $negativeInteger): void { try { @@ -34,15 +35,25 @@ public function testValidNegativeInteger(bool $shouldPass, string $negativeInteg /** - * @return array + * @return array */ - public static function provideNegativeInteger(): array + public static function provideValidNegativeInteger(): array { return [ - 'empty' => [false, ''], 'valid non-positive integer' => [true, '-123456'], - 'invalid zero' => [false, '0'], 'valid negative leading zeros' => [true, '-0000000000000000000005'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidNegativeInteger(): array + { + return [ + 'empty' => [false, ''], + 'invalid zero' => [false, '0'], 'invalid with fractional' => [false, '-1.'], 'invalid positive' => [false, '1234'], 'invalid with thousands-delimiter' => [false, '-1,234'], diff --git a/tests/Assert/NonNegativeIntegerTest.php b/tests/Assert/NonNegativeIntegerTest.php index 3e4941c0..808cf1af 100644 --- a/tests/Assert/NonNegativeIntegerTest.php +++ b/tests/Assert/NonNegativeIntegerTest.php @@ -21,7 +21,8 @@ final class NonNegativeIntegerTest extends TestCase * @param boolean $shouldPass * @param string $nonNegativeInteger */ - #[DataProvider('provideNonNegativeInteger')] + #[DataProvider('provideInvalidNonNegativeInteger')] + #[DataProvider('provideValidNonNegativeInteger')] public function testValidNonNegativeInteger(bool $shouldPass, string $nonNegativeInteger): void { try { @@ -34,16 +35,26 @@ public function testValidNonNegativeInteger(bool $shouldPass, string $nonNegativ /** - * @return array + * @return array */ - public static function provideNonNegativeInteger(): array + public static function provideValidNonNegativeInteger(): array { return [ - 'empty' => [false, ''], 'valid positive integer' => [true, '123456'], 'valid signed positive integer' => [true, '+123456'], 'valid zero' => [true, '0'], 'valid negative leading zeros' => [true, '0000000000000000000005'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidNonNegativeInteger(): array + { + return [ + 'empty' => [false, ''], 'invalid with fractional' => [false, '1.'], 'invalid negative' => [false, '-1234'], 'invalid with thousands-delimiter' => [false, '1,234'], diff --git a/tests/Assert/NonPositiveIntegerTest.php b/tests/Assert/NonPositiveIntegerTest.php index f7cd8e18..5303e9fe 100644 --- a/tests/Assert/NonPositiveIntegerTest.php +++ b/tests/Assert/NonPositiveIntegerTest.php @@ -21,7 +21,8 @@ final class NonPositiveIntegerTest extends TestCase * @param boolean $shouldPass * @param string $nonPositiveInteger */ - #[DataProvider('provideNonPositiveInteger')] + #[DataProvider('provideInvalidNonPositiveInteger')] + #[DataProvider('provideValidNonPositiveInteger')] public function testValidNonPositiveInteger(bool $shouldPass, string $nonPositiveInteger): void { try { @@ -34,15 +35,25 @@ public function testValidNonPositiveInteger(bool $shouldPass, string $nonPositiv /** - * @return array + * @return array */ - public static function provideNonPositiveInteger(): array + public static function provideValidNonPositiveInteger(): array { return [ - 'empty' => [false, ''], 'valid non-positive integer' => [true, '-123456'], 'valid zero' => [true, '0'], 'valid negative leading zeros' => [true, '-0000000000000000000005'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidNonPositiveInteger(): array + { + return [ + 'empty' => [false, ''], 'invalid with fractional' => [false, '-1.'], 'invalid positive' => [false, '1234'], 'invalid with thousands-delimiter' => [false, '-1,234'], diff --git a/tests/Assert/PositiveIntegerTest.php b/tests/Assert/PositiveIntegerTest.php index 95ba627e..189e5c22 100644 --- a/tests/Assert/PositiveIntegerTest.php +++ b/tests/Assert/PositiveIntegerTest.php @@ -21,7 +21,8 @@ final class PositiveIntegerTest extends TestCase * @param boolean $shouldPass * @param string $positiveInteger */ - #[DataProvider('providePositiveInteger')] + #[DataProvider('provideInvalidPositiveInteger')] + #[DataProvider('provideValidPositiveInteger')] public function testValidPositiveInteger(bool $shouldPass, string $positiveInteger): void { try { @@ -34,17 +35,27 @@ public function testValidPositiveInteger(bool $shouldPass, string $positiveInteg /** - * @return array + * @return array */ - public static function providePositiveInteger(): array + public static function provideValidPositiveInteger(): array { return [ - 'empty' => [false, ''], 'valid positive integer' => [true, '123456'], 'valid signed positive integer' => [true, '+123456'], 'valid single digit' => [true, '3'], - 'invalid zero' => [false, '0'], 'valid negative leading zeros' => [true, '0000000000000000000005'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidPositiveInteger(): array + { + return [ + 'empty' => [false, ''], + 'invalid zero' => [false, '0'], 'invalid with fractional' => [false, '1.'], 'invalid negative' => [false, '-1234'], 'invalid with thousands-delimiter' => [false, '1,234'], diff --git a/tests/Assert/QNameTest.php b/tests/Assert/QNameTest.php index 316a7aae..e8ec8c44 100644 --- a/tests/Assert/QNameTest.php +++ b/tests/Assert/QNameTest.php @@ -21,7 +21,8 @@ final class QNameTest extends TestCase * @param boolean $shouldPass * @param string $name */ - #[DataProvider('provideQName')] + #[DataProvider('provideInvalidQName')] + #[DataProvider('provideValidQName')] public function testValidQName(bool $shouldPass, string $name): void { try { @@ -34,31 +35,36 @@ public function testValidQName(bool $shouldPass, string $name): void /** - * @return array + * @return array */ - public static function provideQName(): array + public static function provideValidQName(): array { return [ - [true, 'some:Test'], + 'valid' => [true, 'some:Test'], // both parts can contain a dash - [true, 'som-e:Test'], - [true, 'so-me:T-est'], - // Neither part can start with a dash - [false, 'some:-Test'], - [false, '-some:-Test'], - [true, 'Test'], - // Cannot start with a colon - [false, ':test'], - // Cannot contain multiple colons - [false, 'test:test:test'], - // Cannot start with a number - [false, '1Test'], - // Cannot contain a wildcard character - [false, 'Te*st'], - // Prefixed newlines are forbidden - [false, "\nsome:Test"], + '1st part containing dash' => [true, 'som-e:Test'], + '2nd part containing dash' => [true, 'some:T-est'], + 'both parts containing dash' => [true, 'so-me:T-est'], + // A single NCName is also a valid QName + 'no colon' => [true, 'Test'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidQName(): array + { + return [ + 'start 2nd part with dash' => [false, 'some:-Test'], + 'start both parts with dash' => [false, '-some:-Test'], + 'start with colon' => [false, ':test'], + 'multiple colons' => [false, 'test:test:test'], + 'start with digit' => [false, '1Test'], + 'wildcard' => [false, 'Te*st'], // Trailing newlines are forbidden - [false, "some:Test\n"], + 'trailing newline' => [false, "some:Test\n"], ]; } } diff --git a/tests/Assert/ShortTest.php b/tests/Assert/ShortTest.php index 792bfb5a..2025f0fd 100644 --- a/tests/Assert/ShortTest.php +++ b/tests/Assert/ShortTest.php @@ -21,7 +21,8 @@ final class ShortTest extends TestCase * @param boolean $shouldPass * @param string $short */ - #[DataProvider('provideShort')] + #[DataProvider('provideInvalidShort')] + #[DataProvider('provideValidShort')] public function testValidShort(bool $shouldPass, string $short): void { try { @@ -34,17 +35,27 @@ public function testValidShort(bool $shouldPass, string $short): void /** - * @return array + * @return array */ - public static function provideShort(): array + public static function provideValidShort(): array { return [ - 'empty' => [false, ''], 'valid positive signed' => [true, '+32767'], 'valid negative signed' => [true, '-32768'], 'valid non-signed' => [true, '123'], 'valid leading zeros' => [true, '-0001'], 'valid zero' => [true, '0'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidShort(): array + { + return [ + 'empty' => [false, ''], 'invalid positive signed out-of-bounds' => [false, '+32768'], 'invalid negative signed out-of-bounds' => [false, '-32769'], 'invalid with space' => [false, '1 234'], diff --git a/tests/Assert/TimeTest.php b/tests/Assert/TimeTest.php index 29ffc182..d712f877 100644 --- a/tests/Assert/TimeTest.php +++ b/tests/Assert/TimeTest.php @@ -21,7 +21,8 @@ final class TimeTest extends TestCase * @param boolean $shouldPass * @param string $time */ - #[DataProvider('provideTime')] + #[DataProvider('provideInvalidTime')] + #[DataProvider('provideValidTime')] public function testValidTime(bool $shouldPass, string $time): void { try { @@ -34,9 +35,9 @@ public function testValidTime(bool $shouldPass, string $time): void /** - * @return array + * @return array */ - public static function provideTime(): array + public static function provideValidTime(): array { return [ 'valid' => [true, '21:32:52'], @@ -44,6 +45,16 @@ public static function provideTime(): array 'valid time with Zulu timezone' => [true, '19:32:52Z'], 'valid time with 00:00 timezone' => [true, '19:32:52+00:00'], 'valid time with sub-seconds' => [true, '21:32:52.12679'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidTime(): array + { + return [ 'invalid negative hour' => [false, '-10:00:00'], 'invalid hour out of range' => [false, '25:25:10'], 'invalid invalid format' => [false, '1:20:10'], diff --git a/tests/Assert/TokenTest.php b/tests/Assert/TokenTest.php index 7804c01e..3efa263c 100644 --- a/tests/Assert/TokenTest.php +++ b/tests/Assert/TokenTest.php @@ -34,20 +34,20 @@ public function testValidToken(bool $shouldPass, string $token): void /** - * @return array + * @return array */ public static function provideToken(): array { return [ - [true, 'Snoopy'], - [true, ':CMS'], - [true, 'fööbár'], - [true, '-1950-10-04'], - [true, ''], - [true, '0836217462'], - [true, 'foo bar'], - [true, 'foo,bar'], - [true, "foobar\n"], + 'valid' => [true, 'Snoopy'], + 'starting with a colon' => [true, ':CMS'], + 'diakriticals' => [true, 'fööbár'], + 'starting with a dash' => [true, '-1950-10-04'], + 'empty' => [true, ''], + 'starting with a number' => [true, '0836217462'], + 'space' => [true, 'foo bar'], + 'comma' => [true, 'foo,bar'], + 'whitespace collapse' => [true, " foobar \n "], ]; } } diff --git a/tests/Assert/UnsignedByteTest.php b/tests/Assert/UnsignedByteTest.php index 646fc3a4..a8ee1aca 100644 --- a/tests/Assert/UnsignedByteTest.php +++ b/tests/Assert/UnsignedByteTest.php @@ -21,7 +21,8 @@ final class UnsignedByteTest extends TestCase * @param boolean $shouldPass * @param string $unsignedByte */ - #[DataProvider('provideUnsignedByte')] + #[DataProvider('provideInvalidUnsignedByte')] + #[DataProvider('provideValidUnsignedByte')] public function testValidUnsignedByte(bool $shouldPass, string $unsignedByte): void { try { @@ -34,17 +35,27 @@ public function testValidUnsignedByte(bool $shouldPass, string $unsignedByte): v /** - * @return array + * @return array */ - public static function provideUnsignedByte(): array + public static function provideValidUnsignedByte(): array { return [ - 'empty' => [false, ''], 'valid positive Byte' => [true, '255'], - 'invalid positive out-of-bounds' => [false, '256'], 'valid signed positive Byte' => [true, '+255'], 'valid zero' => [true, '0'], 'valid negative leading zeros' => [true, '0000000000000000000005'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidUnsignedByte(): array + { + return [ + 'empty' => [false, ''], + 'invalid positive out-of-bounds' => [false, '256'], 'invalid with fractional' => [false, '1.'], 'invalid with space' => [false, '12 3'], 'invalid negative' => [false, '-1'], diff --git a/tests/Assert/UnsignedIntTest.php b/tests/Assert/UnsignedIntTest.php index cdd5b7d8..305fea1b 100644 --- a/tests/Assert/UnsignedIntTest.php +++ b/tests/Assert/UnsignedIntTest.php @@ -21,7 +21,8 @@ final class UnsignedIntTest extends TestCase * @param boolean $shouldPass * @param string $unsignedInt */ - #[DataProvider('provideUnsignedInt')] + #[DataProvider('provideInvalidUnsignedInt')] + #[DataProvider('provideValidUnsignedInt')] public function testValidUnsignedInt(bool $shouldPass, string $unsignedInt): void { try { @@ -34,17 +35,27 @@ public function testValidUnsignedInt(bool $shouldPass, string $unsignedInt): voi /** - * @return array + * @return array */ - public static function provideUnsignedInt(): array + public static function provideValidUnsignedInt(): array { return [ - 'empty' => [false, ''], 'valid positive integer' => [true, '4294967295'], - 'invalid positive out-of-bounds' => [false, '4294967296'], 'valid signed positive integer' => [true, '+4294967295'], 'valid zero' => [true, '0'], 'valid negative leading zeros' => [true, '0000000000000000000005'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidUnsignedInt(): array + { + return [ + 'empty' => [false, ''], + 'invalid positive out-of-bounds' => [false, '4294967296'], 'invalid with fractional' => [false, '1.'], 'invalid with space' => [false, '12 34'], 'invalid negative' => [false, '-1'], diff --git a/tests/Assert/UnsignedLongTest.php b/tests/Assert/UnsignedLongTest.php index 688af91b..51680580 100644 --- a/tests/Assert/UnsignedLongTest.php +++ b/tests/Assert/UnsignedLongTest.php @@ -21,7 +21,8 @@ final class UnsignedLongTest extends TestCase * @param boolean $shouldPass * @param string $unsignedLong */ - #[DataProvider('provideUnsignedLong')] + #[DataProvider('provideInvalidUnsignedLong')] + #[DataProvider('provideValidUnsignedLong')] public function testValidUnsignedLong(bool $shouldPass, string $unsignedLong): void { try { @@ -34,17 +35,27 @@ public function testValidUnsignedLong(bool $shouldPass, string $unsignedLong): v /** - * @return array + * @return array */ - public static function provideUnsignedLong(): array + public static function provideValidUnsignedLong(): array { return [ - 'empty' => [false, ''], 'valid positive integer' => [true, '18446744073709551615'], - 'invalid positive out-of-bounds' => [false, '18446744073709551616'], 'valid signed positive integer' => [true, '+18446744073709551615'], 'valid zero' => [true, '0'], 'valid negative leading zeros' => [true, '0000000000000000000005'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidUnsignedLong(): array + { + return [ + 'empty' => [false, ''], + 'invalid positive out-of-bounds' => [false, '18446744073709551616'], 'invalid with fractional' => [false, '1.'], 'invalid with space' => [false, '12 34'], 'invalid negative' => [false, '-1'], diff --git a/tests/Assert/UnsignedShortTest.php b/tests/Assert/UnsignedShortTest.php index b7f0deef..19f4baf2 100644 --- a/tests/Assert/UnsignedShortTest.php +++ b/tests/Assert/UnsignedShortTest.php @@ -21,7 +21,8 @@ final class UnsignedShortTest extends TestCase * @param boolean $shouldPass * @param string $unsignedShort */ - #[DataProvider('provideUnsignedShort')] + #[DataProvider('provideInvalidUnsignedShort')] + #[DataProvider('provideValidUnsignedShort')] public function testValidUnsignedShort(bool $shouldPass, string $unsignedShort): void { try { @@ -34,17 +35,27 @@ public function testValidUnsignedShort(bool $shouldPass, string $unsignedShort): /** - * @return array + * @return array */ - public static function provideUnsignedShort(): array + public static function provideValidUnsignedShort(): array { return [ - 'empty' => [false, ''], 'valid positive short' => [true, '65535'], - 'invalid positive out-of-bounds' => [false, '65536'], 'valid signed positive short' => [true, '+65535'], 'valid zero' => [true, '0'], 'valid negative leading zeros' => [true, '0000000000000000000005'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidUnsignedShort(): array + { + return [ + 'empty' => [false, ''], + 'invalid positive out-of-bounds' => [false, '65536'], 'invalid with fractional' => [false, '1.'], 'invalid with space' => [false, '12 34'], 'invalid negative' => [false, '-1'], diff --git a/tests/Assert/YearMonthTest.php b/tests/Assert/YearMonthTest.php index e5fde28e..7218bff9 100644 --- a/tests/Assert/YearMonthTest.php +++ b/tests/Assert/YearMonthTest.php @@ -21,7 +21,8 @@ final class YearMonthTest extends TestCase * @param boolean $shouldPass * @param string $yearMonth */ - #[DataProvider('provideYearMonth')] + #[DataProvider('provideInvalidYearMonth')] + #[DataProvider('provideValidYearMonth')] public function testValidYearMonth(bool $shouldPass, string $yearMonth): void { try { @@ -34,18 +35,28 @@ public function testValidYearMonth(bool $shouldPass, string $yearMonth): void /** - * @return array + * @return array */ - public static function provideYearMonth(): array + public static function provideValidYearMonth(): array { return [ 'valid' => [true, '2001-10'], - 'space' => [false, '200 01-10'], 'valid numeric timezone' => [true, '2001-10+02:00'], 'valid Zulu timezone' => [true, '2001-10Z'], 'valid 00:00 timezone' => [true, '2001-10+00:00'], '2001 BC' => [true, '-2001-10'], '20000 BC' => [true, '-20000-04'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidYearMonth(): array + { + return [ + 'space' => [false, '200 01-10'], 'missing part' => [false, '2001'], 'month out of range' => [false, '2001-13'], ]; diff --git a/tests/Assert/YearTest.php b/tests/Assert/YearTest.php index 65f35262..ce4a6bd5 100644 --- a/tests/Assert/YearTest.php +++ b/tests/Assert/YearTest.php @@ -21,7 +21,8 @@ final class YearTest extends TestCase * @param boolean $shouldPass * @param string $year */ - #[DataProvider('provideYear')] + #[DataProvider('provideInvalidYear')] + #[DataProvider('provideValidYear')] public function testValidYear(bool $shouldPass, string $year): void { try { @@ -34,19 +35,27 @@ public function testValidYear(bool $shouldPass, string $year): void /** - * @return array + * @return array */ - public static function provideYear(): array + public static function provideValidYear(): array { return [ - 'empty' => [false, ''], 'valid' => [true, '2001'], - 'whitespace' => [false, ' 2001 '], 'valid numeric timezone' => [true, '2001+02:00'], 'valid Zulu timezone' => [true, '2001Z'], 'valid 00:00 timezone' => [true, '2001+00:00'], - '2001 BC' => [true, '-2001'], - '20000 BC' => [true, '-20000'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidYear(): array + { + return [ + 'empty' => [false, ''], + 'whitespace' => [false, ' 2001 '], ]; } } diff --git a/tests/Type/AnyURIValueTest.php b/tests/Type/AnyURIValueTest.php index f5ac0d75..c92081e9 100644 --- a/tests/Type/AnyURIValueTest.php +++ b/tests/Type/AnyURIValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\AnyURITest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\AnyURIValue; @@ -21,7 +22,9 @@ final class AnyURIValueTest extends TestCase * @param boolean $shouldPass * @param string $uri */ - #[DataProvider('provideURI')] + #[DataProvider('provideValidURI')] + #[DataProviderExternal(AnyURITest::class, 'provideValidURI')] + #[DependsOnClass(AnyURITest::class)] public function testAnyURI(bool $shouldPass, string $uri): void { try { @@ -34,20 +37,12 @@ public function testAnyURI(bool $shouldPass, string $uri): void /** - * @return array + * @return array */ - public static function provideURI(): array + public static function provideValidURI(): array { return [ - 'urn' => [true, 'urn:x-simplesamlphp:phpunit'], - 'same-doc' => [true, '#_53d830ab1be17291a546c95c7f1cdf8d3d23c959e6'], - 'url' => [true, 'https://www.simplesamlphp.org'], - 'diacritical' => [true, 'https://aä.com'], - 'spn' => [true, 'spn:a4cf592f-a64c-46ff-a788-b260f474525b'], - 'typos' => [true, 'https//www.uni.l/en/'], - 'spaces' => [true, 'this is silly'], - 'empty' => [true, ''], - 'azure-common' => [true, 'https://sts.windows.net/{tenantid}/'], + 'trailing newline' => [true, "https://sts.windows.net/{tenantid}/\n"], ]; } } diff --git a/tests/Type/Base64BinaryValueTest.php b/tests/Type/Base64BinaryValueTest.php index 22ad7b79..5d898ab2 100644 --- a/tests/Type/Base64BinaryValueTest.php +++ b/tests/Type/Base64BinaryValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\Base64BinaryTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\Base64BinaryValue; @@ -21,7 +22,10 @@ final class Base64BinaryValueTest extends TestCase * @param boolean $shouldPass * @param string $base64 */ - #[DataProvider('provideBase64')] + #[DataProvider('provideInvalidBase64')] + #[DataProvider('provideValidBase64')] + #[DataProviderExternal(Base64BinaryTest::class, 'provideValidBase64')] + #[DependsOnClass(Base64BinaryTest::class)] public function testBase64Binary(bool $shouldPass, string $base64): void { try { @@ -34,13 +38,23 @@ public function testBase64Binary(bool $shouldPass, string $base64): void /** - * @return array + * @return array */ - public static function provideBase64(): array + public static function provideValidBase64(): array + { + return [ + 'whitespace ignored' => [true, "U2ltcGxl\n U0FNTHBocA=="], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidBase64(): array { return [ 'empty' => [false, ''], - 'valid' => [true, 'U2ltcGxlU0FNTHBocA=='], 'illegal characters' => [false, '&*$(#&^@!(^%$'], 'length not dividable by 4' => [false, 'U2ltcGxlU0FTHBocA=='], ]; diff --git a/tests/Type/BooleanValueTest.php b/tests/Type/BooleanValueTest.php index 68d317ff..d1d358b4 100644 --- a/tests/Type/BooleanValueTest.php +++ b/tests/Type/BooleanValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\BooleanTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\BooleanValue; @@ -21,7 +22,10 @@ final class BooleanValueTest extends TestCase * @param boolean $shouldPass * @param string $boolean */ - #[DataProvider('provideBoolean')] + #[DataProvider('provideInvalidBoolean')] + #[DataProvider('provideValidBoolean')] + #[DataProviderExternal(BooleanTest::class, 'provideValidBoolean')] + #[DependsOnClass(BooleanTest::class)] public function testBoolean(bool $shouldPass, string $boolean): void { try { @@ -34,16 +38,22 @@ public function testBoolean(bool $shouldPass, string $boolean): void /** - * @return array + * @return array */ - public static function provideBoolean(): array + public static function provideValidBoolean(): array + { + return [ + 'whitespace collapse' => [true, " true \n"], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidBoolean(): array { return [ - 'true' => [true, 'true'], - 'false' => [true, 'false'], - 'one' => [true, '1'], - 'zero' => [true, '0'], - 'whitespace collapse' => [true, ' tr ue '], 'vrai' => [false, 'vrai'], 'faux' => [false, 'faux'], ]; diff --git a/tests/Type/ByteValueTest.php b/tests/Type/ByteValueTest.php index 572c3ae9..ccd04132 100644 --- a/tests/Type/ByteValueTest.php +++ b/tests/Type/ByteValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\ByteTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\ByteValue; @@ -21,7 +22,10 @@ final class ByteValueTest extends TestCase * @param boolean $shouldPass * @param string $byte */ - #[DataProvider('provideByte')] + #[DataProvider('provideInvalidByte')] + #[DataProvider('provideValidByte')] + #[DataProviderExternal(ByteTest::class, 'provideValidByte')] + #[DependsOnClass(ByteTest::class)] public function testByte(bool $shouldPass, string $byte): void { try { @@ -34,20 +38,25 @@ public function testByte(bool $shouldPass, string $byte): void /** - * @return array + * @return array */ - public static function provideByte(): array + public static function provideValidByte(): array + { + return [ + 'valid with whitespace collapse' => [true, "\t 123 \n"], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidByte(): array { return [ 'empty' => [false, ''], - 'valid positive signed' => [true, '+127'], - 'valid negative signed' => [true, '-128'], - 'valid non-signed' => [true, '123'], - 'valid leading zeros' => [true, '-0001'], - 'valid zero' => [true, '0'], 'invalid positive signed out-of-bounds' => [false, '+128'], 'invalid negative signed out-of-bounds' => [false, '-129'], - 'valid with whitespace collapse' => [true, " 1 23 \n"], 'invalid with fractional' => [false, '123.'], ]; } diff --git a/tests/Type/DateTimeValueTest.php b/tests/Type/DateTimeValueTest.php index 50fb0684..f674f251 100644 --- a/tests/Type/DateTimeValueTest.php +++ b/tests/Type/DateTimeValueTest.php @@ -5,8 +5,9 @@ namespace SimpleSAML\Test\XML\Type; use DateTimeImmutable; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\DateTimeTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\DateTimeValue; @@ -22,7 +23,10 @@ final class DateTimeValueTest extends TestCase * @param boolean $shouldPass * @param string $dateTime */ - #[DataProvider('provideDateTime')] + #[DataProvider('provideInvalidDateTime')] + #[DataProvider('provideValidDateTime')] + #[DataProviderExternal(DateTimeTest::class, 'provideValidDateTime')] + #[DependsOnClass(DateTimeTest::class)] public function testDateTime(bool $shouldPass, string $dateTime): void { try { @@ -35,39 +39,42 @@ public function testDateTime(bool $shouldPass, string $dateTime): void /** - * @return array + * Test the fromDateTime function */ - public static function provideDateTime(): array + #[DependsOnClass(DateTimeTest::class)] + public function testFromDateTime(): void + { + $dt = new DateTimeImmutable('@946684800'); + + $dateTimeValue = DateTimeValue::fromDateTime($dt); + $this->assertEquals('2000-01-01T00:00:00+00:00', $dateTimeValue->getValue()); + } + + + /** + * @return array + */ + public static function provideValidDateTime(): array { return [ - 'valid' => [true, '2001-10-26T21:32:52'], - 'valid with numeric difference' => [true, '2001-10-26T21:32:52+02:00'], - 'valid with Zulu' => [true, '2001-10-26T19:32:52Z'], - 'valid with 00:00 difference' => [true, '2001-10-26T19:32:52+00:00'], - 'valid with negative value' => [true, '-2001-10-26T21:32:52'], - 'valid with subseconds' => [true, '2001-10-26T21:32:52.12679'], - 'valid with more than four digit year' => [true, '-22001-10-26T21:32:52+02:00'], - 'valid with sub-seconds' => [true, '2001-10-26T21:32:52.12679'], - 'empty' => [false, ''], 'whitespace collapse' => [true, ' 2001-10-26T21:32:52 '], - 'missing time' => [false, '2001-10-26'], - 'missing second' => [false, '2001-10-26T21:32'], - 'hour out of range' => [false, '2001-10-26T25:32:52+02:00'], - 'year 0000' => [false, '0000-10-26T25:32:52+02:00'], - 'prefixed zero' => [false, '02001-10-26T25:32:52+02:00'], - 'wrong format' => [false, '01-10-26T21:32'], ]; } /** - * Test the fromDateTime function + * @return array */ - public function testFromDateTime(): void + public static function provideInvalidDateTime(): array { - $dt = new DateTimeImmutable('@946684800'); - - $dateTimeValue = DateTimeValue::fromDateTime($dt); - $this->assertEquals('2000-01-01T00:00:00+00:00', $dateTimeValue->getValue()); + return [ + 'empty' => [false, ''], + 'missing time' => [false, '2001-10-26'], + 'missing second' => [false, '2001-10-26T21:32'], + 'hour out of range' => [false, '2001-10-26T25:32:52+02:00'], + 'year 0000' => [false, '0000-10-26T25:32:52+02:00'], + 'prefixed zero' => [false, '02001-10-26T25:32:52+02:00'], + 'wrong format' => [false, '01-10-26T21:32'], + ]; } } diff --git a/tests/Type/DateValueTest.php b/tests/Type/DateValueTest.php index 58fa7bad..5bfff41d 100644 --- a/tests/Type/DateValueTest.php +++ b/tests/Type/DateValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\DateTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\DateValue; @@ -21,7 +22,10 @@ final class DateValueTest extends TestCase * @param boolean $shouldPass * @param string $date */ - #[DataProvider('provideDate')] + #[DataProvider('provideInvalidDate')] + #[DataProvider('provideValidDate')] + #[DataProviderExternal(DateTest::class, 'provideValidDate')] + #[DependsOnClass(DateTest::class)] public function testDate(bool $shouldPass, string $date): void { try { @@ -34,19 +38,23 @@ public function testDate(bool $shouldPass, string $date): void /** - * @return array + * @return array */ - public static function provideDate(): array + public static function provideValidDate(): array + { + return [ + 'whitespace collapse' => [true, " 2001-10-26 \n"], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidDate(): array { return [ - 'valid' => [true, '2001-10-26'], - 'valid numeric timezone' => [true, '2001-10-26+02:00'], - 'valid Zulu timezone' => [true, '2001-10-26Z'], - 'valid 00:00 timezone' => [true, '2001-10-26+00:00'], - '2001 BC' => [true, '-2001-10-26'], - '2000 BC' => [true, '-20000-04-01'], 'empty' => [false, ''], - 'whitespace collapse' => [true, ' 2001-10-26 '], 'missing part' => [false, '2001-10'], 'day out of range' => [false, '2001-10-32'], 'month out of range' => [false, '2001-13-26+02:00'], diff --git a/tests/Type/DayValueTest.php b/tests/Type/DayValueTest.php index 5ad667b7..783836eb 100644 --- a/tests/Type/DayValueTest.php +++ b/tests/Type/DayValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\DayTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\DayValue; @@ -21,7 +22,10 @@ final class DayValueTest extends TestCase * @param boolean $shouldPass * @param string $day */ - #[DataProvider('provideDay')] + #[DataProvider('provideInvalidDay')] + #[DataProvider('provideValidDay')] + #[DataProviderExternal(DayTest::class, 'provideValidDay')] + #[DependsOnClass(DayTest::class)] public function testDay(bool $shouldPass, string $day): void { try { @@ -34,19 +38,23 @@ public function testDay(bool $shouldPass, string $day): void /** - * @return array + * @return array */ - public static function provideDay(): array + public static function provideValidDay(): array { return [ - 'empty' => [false, ''], 'whitespace collapse' => [true, ' ---03 '], - 'valid' => [true, '---01'], - 'valid numeric timezone' => [true, '---01+02:00'], - 'valid Zulu timezone' => [true, '---01Z'], - 'valid 00:00 timezone' => [true, '---01+00:00'], - 'day 15' => [true, '---15'], - 'day 31' => [true, '---31'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidDay(): array + { + return [ + 'empty' => [false, ''], 'invalid format' => [false, '--30-'], 'day out of range' => [false, '---35'], 'missing leading dashes' => [false, '15'], diff --git a/tests/Type/DecimalValueTest.php b/tests/Type/DecimalValueTest.php index d326ae94..df1576bb 100644 --- a/tests/Type/DecimalValueTest.php +++ b/tests/Type/DecimalValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\DecimalTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\DecimalValue; @@ -21,7 +22,10 @@ final class DecimalValueTest extends TestCase * @param boolean $shouldPass * @param string $decimal */ - #[DataProvider('provideDecimal')] + #[DataProvider('provideInvalidDecimal')] + #[DataProvider('provideValidDecimal')] + #[DataProviderExternal(DecimalTest::class, 'provideValidDecimal')] + #[DependsOnClass(DecimalTest::class)] public function testDecimal(bool $shouldPass, string $decimal): void { try { @@ -34,18 +38,23 @@ public function testDecimal(bool $shouldPass, string $decimal): void /** - * @return array + * @return array */ - public static function provideDecimal(): array + public static function provideValidDecimal(): array + { + return [ + 'valid with whitespace collapse' => [true, "\v 1234.456 \t "], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidDecimal(): array { return [ 'empty' => [false, ''], - 'valid decimal' => [true, '123.456'], - 'valid positive signed' => [true, '+123.456'], - 'valid negative signed' => [true, '-123.456'], - 'valid fractional only' => [true, '-.456'], - 'valid without fraction' => [true, '-456'], - 'valid with whitespace collapse' => [true, ' 1 234.456 '], 'invalid scientific notation' => [false, '1234.456E+2'], 'invalid with thousands-delimiter' => [false, '+1,234.456'], ]; diff --git a/tests/Type/DoubleValueTest.php b/tests/Type/DoubleValueTest.php index f620a015..2e9fdbde 100644 --- a/tests/Type/DoubleValueTest.php +++ b/tests/Type/DoubleValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\DoubleTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\DoubleValue; @@ -21,7 +22,10 @@ final class DoubleValueTest extends TestCase * @param boolean $shouldPass * @param string $double */ - #[DataProvider('provideDouble')] + #[DataProvider('provideInvalidDouble')] + #[DataProvider('provideValidDouble')] + #[DataProviderExternal(DoubleTest::class, 'provideValidDouble')] + #[DependsOnClass(DoubleTest::class)] public function testDouble(bool $shouldPass, string $double): void { try { @@ -34,23 +38,25 @@ public function testDouble(bool $shouldPass, string $double): void /** - * @return array + * @return array */ - public static function provideDouble(): array + public static function provideValidDouble(): array + { + return [ + 'valid with whitespace collapse' => [true, "\v 1234.456 \n"], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidDouble(): array { return [ 'empty' => [false, ''], - 'valid positive signed' => [true, '+123.456'], - 'valid negative signed' => [true, '-123.456'], - 'valid non-signed' => [true, '123.456'], - 'valid leading zeros' => [true, '-0123.456'], - 'valid zero' => [true, '0.0'], - 'valid NaN' => [true, 'NaN'], 'case-sensitive NaN' => [false, 'NAN'], - 'valid negative FIN' => [true, '-FIN'], - 'valid FIN' => [true, 'FIN'], 'invalid +FIN' => [false, '+FIN'], - 'valid with whitespace collapse' => [true, ' 1 234.456 '], 'invalid without fractional' => [false, '123'], ]; } diff --git a/tests/Type/DurationValueTest.php b/tests/Type/DurationValueTest.php index c8668168..76dfad7f 100644 --- a/tests/Type/DurationValueTest.php +++ b/tests/Type/DurationValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\DurationTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\DurationValue; @@ -21,7 +22,10 @@ final class DurationValueTest extends TestCase * @param boolean $shouldPass * @param string $duration */ - #[DataProvider('provideDuration')] + #[DataProvider('provideInvalidDuration')] + #[DataProvider('provideValidDuration')] + #[DataProviderExternal(DurationTest::class, 'provideValidDuration')] + #[DependsOnClass(DurationTest::class)] public function testDuration(bool $shouldPass, string $duration): void { try { @@ -34,19 +38,23 @@ public function testDuration(bool $shouldPass, string $duration): void /** - * @return array + * @return array */ - public static function provideDuration(): array + public static function provideValidDuration(): array + { + return [ + 'whitespace collapse' => [true, " PT130S \n"], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidDuration(): array { return [ 'empty' => [false, ''], - 'whitespace collapse' => [true, ' PT130S '], - 'valid long seconds' => [true, 'PT1004199059S'], - 'valid short seconds' => [true, 'PT130S'], - 'valid minutes and seconds' => [true, 'PT2M10S'], - 'valid one day and two seconds' => [true, 'P1DT2S'], - 'valid minus one year' => [true, '-P1Y'], - 'valid complex sub-second' => [true, 'P1Y2M3DT5H20M30.123S'], 'invalid missing P' => [false, '1Y'], 'invalid missing T' => [false, 'P1S'], 'invalid all parts must be positive' => [false, 'P-1Y'], diff --git a/tests/Type/EntitiesValueTest.php b/tests/Type/EntitiesValueTest.php index 4f9ddfae..4dc3fca1 100644 --- a/tests/Type/EntitiesValueTest.php +++ b/tests/Type/EntitiesValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\EntitiesTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\EntitiesValue; @@ -21,7 +22,10 @@ final class EntitiesValueTest extends TestCase * @param boolean $shouldPass * @param string $entities */ - #[DataProvider('provideEntities')] + #[DataProvider('provideInvalidEntities')] + #[DataProvider('provideValidEntities')] + #[DataProviderExternal(EntitiesTest::class, 'provideValidEntities')] + #[DependsOnClass(EntitiesTest::class)] public function testIDRefs(bool $shouldPass, string $entities): void { try { @@ -34,20 +38,22 @@ public function testIDRefs(bool $shouldPass, string $entities): void /** - * @return array + * Test the toArray function */ - public static function provideEntities(): array + #[DependsOnClass(EntitiesTest::class)] + public function testToArray(): void + { + $entities = EntitiesValue::fromString("foo \nbar baz"); + $this->assertEquals(['foo', 'bar', 'baz'], $entities->toArray()); + } + + + /** + * @return array + */ + public static function provideValidEntities(): array { return [ - 'valid' => [true, 'Snoopy foobar'], - 'diacritical' => [true, 'Snööpy fööbár'], - 'start with colon' => [false, 'foobar :CMS'], - 'start with underscore' => [true, '_1950-10-04 foobar'], - 'invalid first char' => [false, '0836217462 1378943'], - 'empty string' => [false, ''], - 'space' => [true, 'foo bar'], - 'colon' => [false, 'foo:bar'], - 'comma' => [false, 'foo,bar'], 'whitespace collapse' => [true, "foobar\n"], 'normalization' => [true, ' foobar '], ]; @@ -55,11 +61,16 @@ public static function provideEntities(): array /** - * Test the toArray function + * @return array */ - public function testToArray(): void + public static function provideInvalidEntities(): array { - $entities = EntitiesValue::fromString("foo \nbar baz"); - $this->assertEquals(['foo', 'bar', 'baz'], $entities->toArray()); + return [ + 'start with colon' => [false, 'foobar :CMS'], + 'invalid first char' => [false, '0836217462 1378943'], + 'empty string' => [false, ''], + 'colon' => [false, 'foo:bar'], + 'comma' => [false, 'foo,bar'], + ]; } } diff --git a/tests/Type/EntityValueTest.php b/tests/Type/EntityValueTest.php index 9dc87a75..1dda3214 100644 --- a/tests/Type/EntityValueTest.php +++ b/tests/Type/EntityValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\EntityTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\EntityValue; @@ -21,8 +22,11 @@ final class EntityValueTest extends TestCase * @param boolean $shouldPass * @param string $entity */ - #[DataProvider('provideEntity')] - public function testIDRef(bool $shouldPass, string $entity): void + #[DataProvider('provideInvalidEntity')] + #[DataProvider('provideValidEntity')] + #[DataProviderExternal(EntityTest::class, 'provideValidEntity')] + #[DependsOnClass(EntityTest::class)] + public function testEntity(bool $shouldPass, string $entity): void { try { EntityValue::fromString($entity); @@ -34,23 +38,27 @@ public function testIDRef(bool $shouldPass, string $entity): void /** - * @return array + * @return array */ - public static function provideEntity(): array + public static function provideValidEntity(): array + { + return [ + 'whitespace collapse' => [true, "foobar\n"], + 'normalization' => [true, ' foobar '], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidEntity(): array { return [ - 'valid' => [true, 'Test'], - 'valid starts with underscore' => [true, '_Test'], - 'valid contains dashes' => [true, '_1950-10-04_10-00'], - 'valid contains dots' => [true, 'Te.st'], - 'valid contains diacriticals' => [true, 'fööbár'], - 'valid prefixed v4 UUID' => [true, '_5425e58e-e799-4884-92cc-ca64ecede32f'], 'invalid empty string' => [false, ''], 'invalid contains wildcard' => [false, 'Te*st'], 'invalid starts with digit' => [false, '1Test'], 'invalid contains colon' => [false, 'Te:st'], - 'whitespace collapse' => [true, "foobar\n"], - 'normalization' => [true, ' foobar '], ]; } } diff --git a/tests/Type/FloatValueTest.php b/tests/Type/FloatValueTest.php index f672a154..eed8dab1 100644 --- a/tests/Type/FloatValueTest.php +++ b/tests/Type/FloatValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\FloatTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\FloatValue; @@ -21,7 +22,10 @@ final class FloatValueTest extends TestCase * @param boolean $shouldPass * @param string $float */ - #[DataProvider('provideFloat')] + #[DataProvider('provideInvalidFloat')] + #[DataProvider('provideValidFloat')] + #[DataProviderExternal(FloatTest::class, 'provideValidFloat')] + #[DependsOnClass(FloatTest::class)] public function testFloat(bool $shouldPass, string $float): void { try { @@ -34,23 +38,25 @@ public function testFloat(bool $shouldPass, string $float): void /** - * @return array + * @return array */ - public static function provideFloat(): array + public static function provideValidFloat(): array + { + return [ + 'valid with whitespace collapse' => [true, " \n1234.456 \n "], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidFloat(): array { return [ 'empty' => [false, ''], - 'valid positive signed' => [true, '+123.456'], - 'valid negative signed' => [true, '-123.456'], - 'valid non-signed' => [true, '123.456'], - 'valid leading zeros' => [true, '-0123.456'], - 'valid zero' => [true, '0.0'], - 'valid NaN' => [true, 'NaN'], 'case-sensitive NaN' => [false, 'NAN'], - 'valid negative FIN' => [true, '-FIN'], - 'valid FIN' => [true, 'FIN'], 'invalid +FIN' => [false, '+FIN'], - 'valid with whitespace collapse' => [true, ' 1 234.456 '], 'invalid without fractional' => [false, '123'], ]; } diff --git a/tests/Type/HexBinaryValueTest.php b/tests/Type/HexBinaryValueTest.php index 97622a04..a4ee9ed3 100644 --- a/tests/Type/HexBinaryValueTest.php +++ b/tests/Type/HexBinaryValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\HexBinaryTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\HexBinaryValue; @@ -21,7 +22,10 @@ final class HexBinaryValueTest extends TestCase * @param boolean $shouldPass * @param string $hexbin */ - #[DataProvider('provideHexBinary')] + #[DataProvider('provideInvalidHexBinary')] + #[DataProvider('provideValidHexBinary')] + #[DataProviderExternal(HexBinaryTest::class, 'provideValidHexBinary')] + #[DependsOnClass(HexBinaryTest::class)] public function testHexBinary(bool $shouldPass, string $hexbin): void { try { @@ -34,14 +38,22 @@ public function testHexBinary(bool $shouldPass, string $hexbin): void /** - * @return array + * @return array */ - public static function provideHexBinary(): array + public static function provideValidHexBinary(): array + { + return []; + } + + + /** + * @return array + */ + public static function provideInvalidHexBinary(): array { return [ 'empty' => [false, ''], 'base64' => [false, 'U2ltcGxlU0FNTHBocA=='], - 'valid' => [true, '3f3c6d78206c657673726f693d6e3122302e20226e656f636964676e223d54552d4622383e3f'], 'invalid' => [false, '3f3r'], 'bogus' => [false, '&*$(#&^@!(^%$'], 'length not dividable by 4' => [false, '3f3'], diff --git a/tests/Type/IDRefValueTest.php b/tests/Type/IDRefValueTest.php index e2abca6a..0dae0a0c 100644 --- a/tests/Type/IDRefValueTest.php +++ b/tests/Type/IDRefValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\IDRefTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\IDRefValue; @@ -21,7 +22,10 @@ final class IDRefValueTest extends TestCase * @param boolean $shouldPass * @param string $idref */ - #[DataProvider('provideIDRef')] + #[DataProvider('provideInvalidIDRef')] + #[DataProvider('provideValidIDRef')] + #[DataProviderExternal(IDRefTest::class, 'provideValidIDRef')] + #[DependsOnClass(IDRefTest::class)] public function testIDRef(bool $shouldPass, string $idref): void { try { @@ -34,23 +38,27 @@ public function testIDRef(bool $shouldPass, string $idref): void /** - * @return array + * @return array */ - public static function provideIDRef(): array + public static function provideValidIDRef(): array + { + return [ + 'whitespace collapse' => [true, "foobar\n"], + 'normalization' => [true, ' foobar '], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidIDRef(): array { return [ - 'valid' => [true, 'Test'], - 'valid starts with underscore' => [true, '_Test'], - 'valid contains dashes' => [true, '_1950-10-04_10-00'], - 'valid contains dots' => [true, 'Te.st'], - 'valid contains diacriticals' => [true, 'fööbár'], - 'valid prefixed v4 UUID' => [true, '_5425e58e-e799-4884-92cc-ca64ecede32f'], 'invalid empty string' => [false, ''], 'invalid contains wildcard' => [false, 'Te*st'], 'invalid starts with digit' => [false, '1Test'], 'invalid contains colon' => [false, 'Te:st'], - 'whitespace collapse' => [true, "foobar\n"], - 'normalization' => [true, ' foobar '], ]; } } diff --git a/tests/Type/IDRefsValueTest.php b/tests/Type/IDRefsValueTest.php index 64ce0f0c..b0552169 100644 --- a/tests/Type/IDRefsValueTest.php +++ b/tests/Type/IDRefsValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\IDRefsTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\IDRefsValue; @@ -21,7 +22,10 @@ final class IDRefsValueTest extends TestCase * @param boolean $shouldPass * @param string $idrefs */ - #[DataProvider('provideIDRefs')] + #[DataProvider('provideInvalidIDRefs')] + #[DataProvider('provideValidIDRefs')] + #[DataProviderExternal(IDRefsTest::class, 'provideValidIDRefs')] + #[DependsOnClass(IDRefsTest::class)] public function testIDRefs(bool $shouldPass, string $idrefs): void { try { @@ -34,21 +38,22 @@ public function testIDRefs(bool $shouldPass, string $idrefs): void /** - * @return array + * Test the toArray function + */ + #[DependsOnClass(IDRefsTest::class)] + public function testToArray(): void + { + $idrefs = IDRefsValue::fromString("foo \nbar baz"); + $this->assertEquals(['foo', 'bar', 'baz'], $idrefs->toArray()); + } + + + /** + * @return array */ - public static function provideIDRefs(): array + public static function provideValidIDRefs(): array { return [ - 'valid' => [true, 'Snoopy foobar'], - 'diacritical' => [true, 'Snööpy fööbár'], - 'start with colon' => [false, 'foobar :CMS'], - 'start with dash' => [false, '-1950-10-04 foobar'], - 'start with underscore' => [true, '_1950-10-04 foobar'], - 'invalid first char' => [false, '0836217462 1378943'], - 'empty string' => [false, ''], - 'space' => [true, 'foo bar'], - 'colon' => [false, 'foo:bar'], - 'comma' => [false, 'foo,bar'], 'whitespace collapse' => [true, "foobar\n"], 'normalization' => [true, ' foobar '], ]; @@ -56,11 +61,17 @@ public static function provideIDRefs(): array /** - * Test the toArray function + * @return array */ - public function testToArray(): void + public static function provideInvalidIDRefs(): array { - $idrefs = IDRefsValue::fromString("foo \nbar baz"); - $this->assertEquals(['foo', 'bar', 'baz'], $idrefs->toArray()); + return [ + 'start with colon' => [false, 'foobar :CMS'], + 'start with dash' => [false, '-1950-10-04 foobar'], + 'invalid first char' => [false, '0836217462 1378943'], + 'empty string' => [false, ''], + 'colon' => [false, 'foo:bar'], + 'comma' => [false, 'foo,bar'], + ]; } } diff --git a/tests/Type/IDValueTest.php b/tests/Type/IDValueTest.php index 098ae6ea..36259901 100644 --- a/tests/Type/IDValueTest.php +++ b/tests/Type/IDValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\IDTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\IDValue; @@ -21,7 +22,10 @@ final class IDValueTest extends TestCase * @param boolean $shouldPass * @param string $id */ - #[DataProvider('provideID')] + #[DataProvider('provideInvalidID')] + #[DataProvider('provideValidID')] + #[DataProviderExternal(IDTest::class, 'provideValidID')] + #[DependsOnClass(IDTest::class)] public function testID(bool $shouldPass, string $id): void { try { @@ -34,23 +38,27 @@ public function testID(bool $shouldPass, string $id): void /** - * @return array + * @return array */ - public static function provideID(): array + public static function provideValidID(): array + { + return [ + 'whitespace collapse' => [true, "foobar\n"], + 'normalization' => [true, ' foobar '], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidID(): array { return [ - 'valid' => [true, 'Test'], - 'valid starts with underscore' => [true, '_Test'], - 'valid contains dashes' => [true, '_1950-10-04_10-00'], - 'valid contains dots' => [true, 'Te.st'], - 'valid contains diacriticals' => [true, 'fööbár'], - 'valid prefixed v4 UUID' => [true, '_5425e58e-e799-4884-92cc-ca64ecede32f'], 'invalid empty string' => [false, ''], 'invalid contains wildcard' => [false, 'Te*st'], 'invalid starts with digit' => [false, '1Test'], 'invalid contains colon' => [false, 'Te:st'], - 'whitespace collapse' => [true, "foobar\n"], - 'normalization' => [true, ' foobar '], ]; } } diff --git a/tests/Type/IntValueTest.php b/tests/Type/IntValueTest.php index 23b0ebff..0153aae7 100644 --- a/tests/Type/IntValueTest.php +++ b/tests/Type/IntValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\IntTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\IntValue; @@ -21,7 +22,10 @@ final class IntValueTest extends TestCase * @param boolean $shouldPass * @param string $int */ - #[DataProvider('provideInt')] + #[DataProvider('provideInvalidInt')] + #[DataProvider('provideValidInt')] + #[DataProviderExternal(IntTest::class, 'provideValidInt')] + #[DependsOnClass(IntTest::class)] public function testInt(bool $shouldPass, string $int): void { try { @@ -34,20 +38,25 @@ public function testInt(bool $shouldPass, string $int): void /** - * @return array + * @return array */ - public static function provideInt(): array + public static function provideValidInt(): array + { + return [ + 'valid with whitespace collapse' => [true, "\v 1234 \n"], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidInt(): array { return [ 'empty' => [false, ''], - 'valid positive signed' => [true, '+2147483647'], - 'valid negative signed' => [true, '-2147483648'], - 'valid non-signed' => [true, '123'], - 'valid leading zeros' => [true, '-0001'], - 'valid zero' => [true, '0'], 'invalid positive signed out-of-bounds' => [false, '+2147483648'], 'invalid negative signed out-of-bounds' => [false, '-2147483649'], - 'valid with whitespace collapse' => [true, " 1 234 \n"], 'invalid with fractional' => [false, '1234.'], 'invalid with thousands-delimiter' => [false, '+1,234'], ]; diff --git a/tests/Type/IntegerValueTest.php b/tests/Type/IntegerValueTest.php index 54860c1c..8a867da9 100644 --- a/tests/Type/IntegerValueTest.php +++ b/tests/Type/IntegerValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\IntegerTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\IntegerValue; @@ -21,7 +22,10 @@ final class IntegerValueTest extends TestCase * @param boolean $shouldPass * @param string $integer */ - #[DataProvider('provideInteger')] + #[DataProvider('provideInvalidInteger')] + #[DataProvider('provideValidInteger')] + #[DataProviderExternal(IntegerTest::class, 'provideValidInteger')] + #[DependsOnClass(IntegerTest::class)] public function testInteger(bool $shouldPass, string $integer): void { try { @@ -34,16 +38,23 @@ public function testInteger(bool $shouldPass, string $integer): void /** - * @return array + * @return array */ - public static function provideInteger(): array + public static function providevalidInteger(): array + { + return [ + 'valid with whitespace collapse' => [true, " \n1234\r "], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidInteger(): array { return [ 'empty' => [false, ''], - 'valid integer' => [true, '123456'], - 'valid positive signed' => [true, '+00000012'], - 'valid negative signed' => [true, '-1'], - 'valid with whitespace collapse' => [true, ' 1 234 '], 'invalid with fractional' => [false, '1234.'], 'invalid with thousands-delimiter' => [false, '+1,234'], ]; diff --git a/tests/Type/LanguageValueTest.php b/tests/Type/LanguageValueTest.php index 79254ace..35fcdc06 100644 --- a/tests/Type/LanguageValueTest.php +++ b/tests/Type/LanguageValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\LanguageTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\LanguageValue; @@ -21,7 +22,10 @@ final class LanguageValueTest extends TestCase * @param boolean $shouldPass * @param string $language */ - #[DataProvider('provideLanguage')] + #[DataProvider('provideInvalidLanguage')] + #[DataProvider('provideValidLanguage')] + #[DataProviderExternal(LanguageTest::class, 'provideValidLanguage')] + #[DependsOnClass(LanguageTest::class)] public function testLanguage(bool $shouldPass, string $language): void { try { @@ -34,19 +38,24 @@ public function testLanguage(bool $shouldPass, string $language): void /** - * @return array + * @return array */ - public static function provideLanguage(): array + public static function provideValidLanguage(): array { return [ - 'empty string' => [false, ''], - 'one part' => [true, 'es'], - 'two parts' => [true, 'en-US'], - 'many parts' => [true, 'es-this-goes-on-forever'], - 'too long' => [false, 'toolongLanguageuage'], - 'x-case' => [true, 'x-klingon'], - 'i-case' => [true, 'i-sami-no'], 'normalization' => [true, ' en-US '], ]; } + + + /** + * @return array + */ + public static function provideInvalidLanguage(): array + { + return [ + 'empty string' => [false, ''], + 'too long' => [false, 'toolongLanguage'], + ]; + } } diff --git a/tests/Type/LongValueTest.php b/tests/Type/LongValueTest.php index 8b4ff9b5..45e6626d 100644 --- a/tests/Type/LongValueTest.php +++ b/tests/Type/LongValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\LongTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\LongValue; @@ -21,7 +22,10 @@ final class LongValueTest extends TestCase * @param boolean $shouldPass * @param string $long */ - #[DataProvider('provideLong')] + #[DataProvider('provideInvalidLong')] + #[DataProvider('provideValidLong')] + #[DataProviderExternal(LongTest::class, 'provideValidLong')] + #[DependsOnClass(LongTest::class)] public function testLong(bool $shouldPass, string $long): void { try { @@ -34,18 +38,23 @@ public function testLong(bool $shouldPass, string $long): void /** - * @return array + * @return array */ - public static function provideLong(): array + public static function provideValidLong(): array + { + return [ + 'valid with whitespace collapse' => [true, " 1234 \n "], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidLong(): array { return [ 'empty' => [false, ''], - 'valid positive signed' => [true, '+9223372036854775807'], - 'valid negative signed' => [true, '-9223372036854775808'], - 'valid non-signed' => [true, '9223372036854775807'], - 'valid leading zeros' => [true, '-0001'], - 'valid zero' => [true, '0'], - 'valid with whitespace collapse' => [true, " 1 234 \n"], 'invalid positive signed out-of-bounds' => [false, '+9223372036854775808'], 'invalid negative signed out-of-bounds' => [false, '-9223372036854775809'], 'invalid with fractional' => [false, '1234.'], diff --git a/tests/Type/MonthValueTest.php b/tests/Type/MonthValueTest.php index a73a1e93..67a0a24b 100644 --- a/tests/Type/MonthValueTest.php +++ b/tests/Type/MonthValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\MonthTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\MonthValue; @@ -21,7 +22,10 @@ final class MonthValueTest extends TestCase * @param boolean $shouldPass * @param string $month */ - #[DataProvider('provideMonth')] + #[DataProvider('provideInvalidMonth')] + #[DataProvider('provideValidMonth')] + #[DataProviderExternal(MonthTest::class, 'provideValidMonth')] + #[DependsOnClass(MonthTest::class)] public function testMonth(bool $shouldPass, string $month): void { try { @@ -34,18 +38,23 @@ public function testMonth(bool $shouldPass, string $month): void /** - * @return array + * @return array */ - public static function provideMonth(): array + public static function provideValidMonth(): array { return [ - 'empty' => [false, ''], 'whitespace collapse' => [true, ' --05 '], - 'valid' => [true, '--05'], - 'valid numeric timezone' => [true, '--11+02:00'], - 'valid Zulu timezone' => [true, '--11Z'], - 'valid 00:00 timezone' => [true, '--11+00:00'], - 'month 02' => [true, '--02'], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidMonth(): array + { + return [ + 'empty' => [false, ''], 'invalid format' => [false, '-01-'], 'month out of range' => [false, '--13'], 'both digits must be provided' => [false, '--1'], diff --git a/tests/Type/NCNameValueTest.php b/tests/Type/NCNameValueTest.php index 4eeb932c..db59ff61 100644 --- a/tests/Type/NCNameValueTest.php +++ b/tests/Type/NCNameValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\NCNameTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\NCNameValue; @@ -21,7 +22,10 @@ final class NCNameValueTest extends TestCase * @param boolean $shouldPass * @param string $ncname */ - #[DataProvider('provideNCName')] + #[DataProvider('provideInvalidNCName')] + #[DataProvider('provideValidNCName')] + #[DataProviderExternal(NCNameTest::class, 'provideValidNCName')] + #[DependsOnClass(NCNameTest::class)] public function testNCName(bool $shouldPass, string $ncname): void { try { @@ -34,24 +38,28 @@ public function testNCName(bool $shouldPass, string $ncname): void /** - * @return array + * @return array */ - public static function provideNCName(): array + public static function providevalidNCName(): array + { + return [ + 'whitespace collapse' => [true, "foobar\n"], + 'normalization' => [true, ' foobar '], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidNCName(): array { return [ - 'valid' => [true, 'Test'], - 'valid starts with underscore' => [true, '_Test'], - 'valid contains dashes' => [true, '_1950-10-04_10-00'], - 'valid contains dots' => [true, 'Te.st'], - 'valid contains diacriticals' => [true, 'fööbár'], - 'valid prefixed v4 UUID' => [true, '_5425e58e-e799-4884-92cc-ca64ecede32f'], 'invalid empty string' => [false, ''], 'invalid contains wildcard' => [false, 'Te*st'], 'invalid starts with dash' => [false, '-Test'], 'invalid starts with digit' => [false, '1Test'], 'invalid contains colon' => [false, 'Te:st'], - 'whitespace collapse' => [true, "foobar\n"], - 'normalization' => [true, ' foobar '], ]; } } diff --git a/tests/Type/NMTokenValueTest.php b/tests/Type/NMTokenValueTest.php index d12f029f..8095a2df 100644 --- a/tests/Type/NMTokenValueTest.php +++ b/tests/Type/NMTokenValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\NMTokenTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\NMTokenValue; @@ -21,7 +22,10 @@ final class NMTokenValueTest extends TestCase * @param boolean $shouldPass * @param string $nmtoken */ - #[DataProvider('provideNMToken')] + #[DataProvider('provideInvalidNMToken')] + #[DataProvider('provideValidNMToken')] + #[DataProviderExternal(NMTokenTest::class, 'provideValidNMToken')] + #[DependsOnClass(NMTokenTest::class)] public function testNMToken(bool $shouldPass, string $nmtoken): void { try { @@ -34,20 +38,25 @@ public function testNMToken(bool $shouldPass, string $nmtoken): void /** - * @return array + * @return array */ - public static function provideNMToken(): array + public static function provideValidNMToken(): array { return [ - 'valid' => [true, 'Snoopy'], - 'diacritical' => [true, 'fööbár'], - 'start with colon' => [true, ':CMS'], - 'start with dash' => [true, '-1950-10-04'], - 'numeric first char' => [true, '0836217462'], - 'space' => [false, 'foo bar'], - 'comma' => [false, 'foo,bar'], 'whitespace collapse' => [true, "foobar\n"], 'normalization' => [true, ' foobar '], ]; } + + + /** + * @return array + */ + public static function provideInvalidNMToken(): array + { + return [ + 'space' => [false, 'foo bar'], + 'comma' => [false, 'foo,bar'], + ]; + } } diff --git a/tests/Type/NMTokensValueTest.php b/tests/Type/NMTokensValueTest.php index ebfbd1fd..e0169b61 100644 --- a/tests/Type/NMTokensValueTest.php +++ b/tests/Type/NMTokensValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\NMTokensTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\NMTokensValue; @@ -21,7 +22,10 @@ final class NMTokensValueTest extends TestCase * @param boolean $shouldPass * @param string $nmtokens */ - #[DataProvider('provideNMTokens')] + #[DataProvider('provideInvalidNMTokens')] + #[DataProvider('provideValidNMTokens')] + #[DataProviderExternal(NMTokensTest::class, 'provideValidNMTokens')] + #[DependsOnClass(NMTokensTest::class)] public function testNMtokens(bool $shouldPass, string $nmtokens): void { try { @@ -34,17 +38,22 @@ public function testNMtokens(bool $shouldPass, string $nmtokens): void /** - * @return array + * Test the toArray function + */ + #[DependsOnClass(NMTokensTest::class)] + public function testToArray(): void + { + $nmtokens = NMTokensValue::fromString("foo \nbar baz"); + $this->assertEquals(['foo', 'bar', 'baz'], $nmtokens->toArray()); + } + + + /** + * @return array */ - public static function provideNMTokens(): array + public static function provideValidNMTokens(): array { return [ - 'valid' => [true, 'Snoopy foobar'], - 'diacritical' => [true, 'Snoopy fööbár'], - 'start with colon' => [true, ':CMS :ABC'], - 'start with dash' => [true, '-1950-10-04 -1984-11-07'], - 'numeric first char' => [true, '0836217462'], - 'comma' => [false, 'foo,bar'], 'whitespace collapse' => [true, "foobar\n"], 'normalization' => [true, ' foobar nmtoken '], ]; @@ -52,11 +61,12 @@ public static function provideNMTokens(): array /** - * Test the toArray function + * @return array */ - public function testToArray(): void + public static function provideInvalidNMTokens(): array { - $nmtokens = NMTokensValue::fromString("foo \nbar baz"); - $this->assertEquals(['foo', 'bar', 'baz'], $nmtokens->toArray()); + return [ + 'comma' => [false, 'foo,bar'], + ]; } } diff --git a/tests/Type/NameValueTest.php b/tests/Type/NameValueTest.php index 8d8a0fe7..7d8d0c9f 100644 --- a/tests/Type/NameValueTest.php +++ b/tests/Type/NameValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\NameTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\NameValue; @@ -21,7 +22,10 @@ final class NameValueTest extends TestCase * @param boolean $shouldPass * @param string $name */ - #[DataProvider('provideName')] + #[DataProvider('provideInvalidName')] + #[DataProvider('provideValidName')] + #[DataProviderExternal(NameTest::class, 'provideValidName')] + #[DependsOnClass(NameTest::class)] public function testName(bool $shouldPass, string $name): void { try { @@ -34,21 +38,27 @@ public function testName(bool $shouldPass, string $name): void /** - * @return array + * @return array */ - public static function provideName(): array + public static function provideValidName(): array + { + return [ + 'whitespace collapse' => [true, "foobar\n"], + 'normalization' => [true, ' foobar '], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidName(): array { return [ - 'valid' => [true, 'Snoopy'], - 'diacritical' => [true, 'fööbár'], - 'start with colon' => [true, ':CMS'], - 'start with dash' => [true, '-1950-10-04'], 'invalid first char' => [false, '0836217462'], 'empty string' => [false, ''], 'space' => [false, 'foo bar'], 'comma' => [false, 'foo,bar'], - 'whitespace collapse' => [true, "foobar\n"], - 'normalization' => [true, ' foobar '], ]; } } diff --git a/tests/Type/NegativeIntegerValueTest.php b/tests/Type/NegativeIntegerValueTest.php index cce8f280..9f735934 100644 --- a/tests/Type/NegativeIntegerValueTest.php +++ b/tests/Type/NegativeIntegerValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\NegativeIntegerTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\NegativeIntegerValue; @@ -21,7 +22,10 @@ final class NegativeIntegerValueTest extends TestCase * @param boolean $shouldPass * @param string $negativeInteger */ - #[DataProvider('provideNegativeInteger')] + #[DataProvider('provideInvalidNegativeInteger')] + #[DataProvider('provideValidNegativeInteger')] + #[DataProviderExternal(NegativeIntegerTest::class, 'provideValidNegativeInteger')] + #[DependsOnClass(NegativeIntegerTest::class)] public function testNegativeInteger(bool $shouldPass, string $negativeInteger): void { try { @@ -34,16 +38,24 @@ public function testNegativeInteger(bool $shouldPass, string $negativeInteger): /** - * @return array + * @return array */ - public static function provideNegativeInteger(): array + public static function provideValidNegativeInteger(): array + { + return [ + 'valid with whitespace collapse' => [true, "\t -1234 \n "], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidNegativeInteger(): array { return [ 'empty' => [false, ''], - 'valid non-positive integer' => [true, '-123456'], 'invalid zero' => [false, '0'], - 'valid negative leading zeros' => [true, '-0000000000000000000005'], - 'valid with whitespace collapse' => [true, " -1 234 \n"], 'invalid with fractional' => [false, '-1.'], 'invalid positive' => [false, '1234'], 'invalid with thousands-delimiter' => [false, '-1,234'], diff --git a/tests/Type/NonNegativeIntegerValueTest.php b/tests/Type/NonNegativeIntegerValueTest.php index 31881271..c482aa87 100644 --- a/tests/Type/NonNegativeIntegerValueTest.php +++ b/tests/Type/NonNegativeIntegerValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\NonNegativeIntegerTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\NonNegativeIntegerValue; @@ -21,7 +22,10 @@ final class NonNegativeIntegerValueTest extends TestCase * @param boolean $shouldPass * @param string $nonNegativeInteger */ - #[DataProvider('provideNonNegativeInteger')] + #[DataProvider('provideInvalidNonNegativeInteger')] + #[DataProvider('provideValidNonNegativeInteger')] + #[DataProviderExternal(NonNegativeIntegerTest::class, 'provideValidNonNegativeInteger')] + #[DependsOnClass(NonNegativeIntegerTest::class)] public function testNonNegativeInteger(bool $shouldPass, string $nonNegativeInteger): void { try { @@ -34,17 +38,23 @@ public function testNonNegativeInteger(bool $shouldPass, string $nonNegativeInte /** - * @return array + * @return array */ - public static function provideNonNegativeInteger(): array + public static function provideValidNonNegativeInteger(): array + { + return [ + 'valid with whitespace collapse' => [true, " 1234 \n "], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidNonNegativeInteger(): array { return [ 'empty' => [false, ''], - 'valid positive integer' => [true, '123456'], - 'valid signed positive integer' => [true, '+123456'], - 'valid zero' => [true, '0'], - 'valid negative leading zeros' => [true, '0000000000000000000005'], - 'valid with whitespace collapse' => [true, " 1 234 \n"], 'invalid with fractional' => [false, '1.'], 'invalid negative' => [false, '-1234'], 'invalid with thousands-delimiter' => [false, '1,234'], diff --git a/tests/Type/NonPositiveIntegerValueTest.php b/tests/Type/NonPositiveIntegerValueTest.php index 8fc321fd..6436c94a 100644 --- a/tests/Type/NonPositiveIntegerValueTest.php +++ b/tests/Type/NonPositiveIntegerValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\NonPositiveIntegerTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\NonPositiveIntegerValue; @@ -21,7 +22,10 @@ final class NonPositiveIntegerValueTest extends TestCase * @param boolean $shouldPass * @param string $nonPositiveInteger */ - #[DataProvider('provideNonPositiveInteger')] + #[DataProvider('provideInvalidNonPositiveInteger')] + #[DataProvider('provideValidNonPositiveInteger')] + #[DataProviderExternal(NonPositiveIntegerTest::class, 'provideValidNonPositiveInteger')] + #[DependsOnClass(NonPositiveIntegerTest::class)] public function testNonPositiveInteger(bool $shouldPass, string $nonPositiveInteger): void { try { @@ -34,16 +38,23 @@ public function testNonPositiveInteger(bool $shouldPass, string $nonPositiveInte /** - * @return array + * @return array */ - public static function provideNonPositiveInteger(): array + public static function provideValidNonPositiveInteger(): array + { + return [ + 'valid with whitespace collapse' => [true, " -1234 \n "], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidNonPositiveInteger(): array { return [ 'empty' => [false, ''], - 'valid non-positive integer' => [true, '-123456'], - 'valid zero' => [true, '0'], - 'valid negative leading zeros' => [true, '-0000000000000000000005'], - 'valid with whitespace collapse' => [true, " -1 234 \n"], 'invalid with fractional' => [false, '-1.'], 'invalid positive' => [false, '1234'], 'invalid with thousands-delimiter' => [false, '-1,234'], diff --git a/tests/Type/NormalizedStringValueTest.php b/tests/Type/NormalizedStringValueTest.php index 822c3224..cbfe3334 100644 --- a/tests/Type/NormalizedStringValueTest.php +++ b/tests/Type/NormalizedStringValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\NormalizedStringTest; use SimpleSAML\XML\Type\NormalizedStringValue; /** @@ -21,6 +22,7 @@ final class NormalizedStringValueTest extends TestCase * @param string $normalizedStringValue */ #[DataProvider('provideNormalizedString')] + #[DependsOnClass(NormalizedStringTest::class)] public function testNormalizedString(string $str, string $normalizedStringValue): void { $value = NormalizedStringValue::fromString($str); diff --git a/tests/Type/PositiveIntegerValueTest.php b/tests/Type/PositiveIntegerValueTest.php index 96160e71..47dafd65 100644 --- a/tests/Type/PositiveIntegerValueTest.php +++ b/tests/Type/PositiveIntegerValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\PositiveIntegerTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\PositiveIntegerValue; @@ -21,7 +22,10 @@ final class PositiveIntegerValueTest extends TestCase * @param boolean $shouldPass * @param string $positiveInteger */ - #[DataProvider('providePositiveInteger')] + #[DataProvider('provideInvalidPositiveInteger')] + #[DataProvider('provideValidPositiveInteger')] + #[DataProviderExternal(PositiveIntegerTest::class, 'provideValidPositiveInteger')] + #[DependsOnClass(PositiveIntegerTest::class)] public function testPositiveInteger(bool $shouldPass, string $positiveInteger): void { try { @@ -34,18 +38,24 @@ public function testPositiveInteger(bool $shouldPass, string $positiveInteger): /** - * @return array + * @return array */ - public static function providePositiveInteger(): array + public static function provideValidPositiveInteger(): array + { + return [ + 'valid with whitespace collapse' => [true, " 1234 \n "], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidPositiveInteger(): array { return [ 'empty' => [false, ''], - 'valid positive integer' => [true, '123456'], - 'valid signed positive integer' => [true, '+123456'], 'invalid zero' => [false, '0'], - 'valid negative leading zeros' => [true, '0000000000000000000005'], - 'valid single digit' => [true, '3'], - 'valid with whitespace collapse' => [true, " 1 234 \n"], 'invalid with fractional' => [false, '1.'], 'invalid negative' => [false, '-1234'], 'invalid with thousands-delimiter' => [false, '1,234'], diff --git a/tests/Type/QNameValueTest.php b/tests/Type/QNameValueTest.php index 56dba86f..ca7efcd0 100644 --- a/tests/Type/QNameValueTest.php +++ b/tests/Type/QNameValueTest.php @@ -4,11 +4,14 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\QNameTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\QNameValue; +use function strval; + /** * Class \SimpleSAML\Test\XML\Type\QNameValueTest * @@ -21,7 +24,10 @@ final class QNameValueTest extends TestCase * @param boolean $shouldPass * @param string $qname */ - #[DataProvider('provideQName')] + #[DataProvider('provideInvalidQName')] + #[DataProvider('provideValidQName')] + #[DataProviderExternal(QNameTest::class, 'provideValidQName')] + #[DependsOnClass(QNameTest::class)] public function testQName(bool $shouldPass, string $qname): void { try { @@ -34,23 +40,44 @@ public function testQName(bool $shouldPass, string $qname): void /** - * @return array */ - public static function provideQName(): array + #[DependsOnClass(QNameTest::class)] + public function testHelpers(): void + { + $qn = QNameValue::fromString('some:Test'); + $this->assertEquals(strval($qn->getNamespacePrefix()), 'some'); + $this->assertEquals(strval($qn->getLocalName()), 'Test'); + + $qn = QNameValue::fromString('Test'); + $this->assertNull($qn->getNamespacePrefix()); + $this->assertEquals(strval($qn->getLocalName()), 'Test'); + } + + + /** + * @return array + */ + public static function provideValidQName(): array + { + return [ + 'prefixed newline' => [true, "\nsome:Test"], + 'trailing newline' => [true, "some:Test\n"], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidQName(): array { return [ - 'valid' => [true, 'some:Test'], - 'first part containing dash' => [true, 'som-e:Test'], - 'both parts containing dash' => [true, 'so-me:T-est'], 'start 2nd part with dash' => [false, 'some:-Test'], 'start both parts with dash' => [false, '-some:-Test'], - 'no colon' => [true, 'Test'], 'start with colon' => [false, ':test'], 'multiple colons' => [false, 'test:test:test'], 'start with digit' => [false, '1Test'], 'wildcard' => [false, 'Te*st'], - 'prefixed newline' => [false, "\nsome:Test"], - 'trailing newline' => [false, "some:Test\n"], ]; } } diff --git a/tests/Type/ShortValueTest.php b/tests/Type/ShortValueTest.php index 785ee325..379479f8 100644 --- a/tests/Type/ShortValueTest.php +++ b/tests/Type/ShortValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\ShortTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\ShortValue; @@ -21,7 +22,10 @@ final class ShortValueTest extends TestCase * @param boolean $shouldPass * @param string $short */ - #[DataProvider('provideShort')] + #[DataProvider('provideInvalidShort')] + #[DataProvider('provideValidShort')] + #[DataProviderExternal(ShortTest::class, 'provideValidShort')] + #[DependsOnClass(ShortTest::class)] public function testShort(bool $shouldPass, string $short): void { try { @@ -34,20 +38,25 @@ public function testShort(bool $shouldPass, string $short): void /** - * @return array + * @return array */ - public static function provideShort(): array + public static function provideValidShort(): array + { + return [ + 'valid with whitespace collapse' => [true, " 1234 \n "], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidShort(): array { return [ 'empty' => [false, ''], - 'valid positive signed' => [true, '+32767'], - 'valid negative signed' => [true, '-32768'], - 'valid non-signed' => [true, '123'], - 'valid leading zeros' => [true, '-0001'], - 'valid zero' => [true, '0'], 'invalid positive signed out-of-bounds' => [false, '+32768'], 'invalid negative signed out-of-bounds' => [false, '-32769'], - 'valid with whitespace collapse' => [true, " 1 234 \n"], 'invalid with fractional' => [false, '1234.'], 'invalid with thousands-delimiter' => [false, '+1,234'], ]; diff --git a/tests/Type/StringValueTest.php b/tests/Type/StringValueTest.php index 77084686..4215eb7d 100644 --- a/tests/Type/StringValueTest.php +++ b/tests/Type/StringValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\StringTest; use SimpleSAML\XML\Type\StringValue; /** @@ -21,6 +22,7 @@ final class StringValueTest extends TestCase * @param string $stringValue */ #[DataProvider('provideString')] + #[DependsOnClass(StringTest::class)] public function testString(string $str, string $stringValue): void { $value = StringValue::fromString($str); diff --git a/tests/Type/TimeValueTest.php b/tests/Type/TimeValueTest.php index 1b39adfe..f8a5c65f 100644 --- a/tests/Type/TimeValueTest.php +++ b/tests/Type/TimeValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\TimeTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\TimeValue; @@ -21,7 +22,10 @@ final class TimeValueTest extends TestCase * @param boolean $shouldPass * @param string $time */ - #[DataProvider('provideTime')] + #[DataProvider('provideInvalidTime')] + #[DataProvider('provideValidTime')] + #[DataProviderExternal(TimeTest::class, 'provideValidTime')] + #[DependsOnClass(TimeTest::class)] public function testTime(bool $shouldPass, string $time): void { try { @@ -34,16 +38,22 @@ public function testTime(bool $shouldPass, string $time): void /** - * @return array + * @return array */ - public static function provideTime(): array + public static function provideValidTime(): array + { + return [ + 'whitespace collapse' => [true, "\n 21:32:52.12679\t "], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidTime(): array { return [ - 'valid' => [true, '21:32:52'], - 'valid time with numerical timezone' => [true, '21:32:52+02:00'], - 'valid time with Zulu timezone' => [true, '19:32:52Z'], - 'valid time with 00:00 timezone' => [true, '19:32:52+00:00'], - 'valid time with sub-seconds' => [true, '21:32:52.12679'], 'invalid negative hour' => [false, '-10:00:00'], 'invalid hour out of range' => [false, '25:25:10'], 'invalid invalid format' => [false, '1:20:10'], diff --git a/tests/Type/TokenValueTest.php b/tests/Type/TokenValueTest.php index aea4d8dd..919084eb 100644 --- a/tests/Type/TokenValueTest.php +++ b/tests/Type/TokenValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\TokenTest; use SimpleSAML\XML\Type\TokenValue; /** @@ -17,22 +18,23 @@ final class TokenValueTest extends TestCase { /** - * @param string $str - * @param string $normalizedString + * @param string $token + * @param string $normalizedToken */ - #[DataProvider('provideString')] - public function testToken(string $str, string $normalizedString): void + #[DataProvider('provideToken')] + #[DependsOnClass(TokenTest::class)] + public function testToken(string $token, string $normalizedToken): void { - $value = TokenValue::fromString($str); - $this->assertEquals($normalizedString, $value->getValue()); - $this->assertEquals($str, $value->getRawValue()); + $value = TokenValue::fromString($token); + $this->assertEquals($normalizedToken, $value->getValue()); + $this->assertEquals($token, $value->getRawValue()); } /** * @return array */ - public static function provideString(): array + public static function provideToken(): array { return [ 'empty string' => ['', ''], diff --git a/tests/Type/UnsignedByteValueTest.php b/tests/Type/UnsignedByteValueTest.php index deaf506c..e5587eb1 100644 --- a/tests/Type/UnsignedByteValueTest.php +++ b/tests/Type/UnsignedByteValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\UnsignedByteTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\UnsignedByteValue; @@ -21,7 +22,10 @@ final class UnsignedByteValueTest extends TestCase * @param boolean $shouldPass * @param string $unsignedByte */ - #[DataProvider('provideUnsignedByte')] + #[DataProvider('provideInvalidUnsignedByte')] + #[DataProvider('provideValidUnsignedByte')] + #[DataProviderExternal(UnsignedByteTest::class, 'provideValidUnsignedByte')] + #[DependsOnClass(UnsignedByteTest::class)] public function testUnsignedByte(bool $shouldPass, string $unsignedByte): void { try { @@ -34,19 +38,25 @@ public function testUnsignedByte(bool $shouldPass, string $unsignedByte): void /** - * @return array + * @return array */ - public static function provideUnsignedByte(): array + public static function provideValidUnsignedByte(): array + { + return [ + 'valid with whitespace collapse' => [true, " 124 \n "], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidUnsignedByte(): array { return [ 'empty' => [false, ''], - 'valid positive Byte' => [true, '255'], 'invalid positive out-of-bounds' => [false, '256'], - 'valid signed positive Byte' => [true, '+255'], - 'valid zero' => [true, '0'], - 'valid negative leading zeros' => [true, '0000000000000000000005'], 'invalid with fractional' => [false, '1.'], - 'valid with whitespace collapse' => [true, " 1 24 \n"], 'invalid negative' => [false, '-1'], 'invalid with thousands-delimiter' => [false, '1,23'], ]; diff --git a/tests/Type/UnsignedIntValueTest.php b/tests/Type/UnsignedIntValueTest.php index 0ac42031..fd7992d8 100644 --- a/tests/Type/UnsignedIntValueTest.php +++ b/tests/Type/UnsignedIntValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\UnsignedIntTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\UnsignedIntValue; @@ -21,7 +22,10 @@ final class UnsignedIntValueTest extends TestCase * @param boolean $shouldPass * @param string $unsignedInt */ - #[DataProvider('provideUnsignedInt')] + #[DataProvider('provideInvalidUnsignedInt')] + #[DataProvider('provideValidUnsignedInt')] + #[DataProviderExternal(UnsignedIntTest::class, 'provideValidUnsignedInt')] + #[DependsOnClass(UnsignedIntTest::class)] public function testUnsignedInt(bool $shouldPass, string $unsignedInt): void { try { @@ -34,19 +38,25 @@ public function testUnsignedInt(bool $shouldPass, string $unsignedInt): void /** - * @return array + * @return array */ - public static function provideUnsignedInt(): array + public static function provideValidUnsignedInt(): array + { + return [ + 'valid with whitespace collapse' => [true, " 1234 \n "], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidUnsignedInt(): array { return [ 'empty' => [false, ''], - 'valid positive integer' => [true, '4294967295'], 'invalid positive out-of-bounds' => [false, '4294967296'], - 'valid signed positive integer' => [true, '+4294967295'], - 'valid zero' => [true, '0'], - 'valid negative leading zeros' => [true, '0000000000000000000005'], 'invalid with fractional' => [false, '1.'], - 'valid with whitespace collapse' => [true, " 1 234 \n"], 'invalid negative' => [false, '-1'], 'invalid with thousands-delimiter' => [false, '1,234'], ]; diff --git a/tests/Type/UnsignedLongValueTest.php b/tests/Type/UnsignedLongValueTest.php index 22c5528a..e505ceeb 100644 --- a/tests/Type/UnsignedLongValueTest.php +++ b/tests/Type/UnsignedLongValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\UnsignedLongTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\UnsignedLongValue; @@ -21,7 +22,10 @@ final class UnsignedLongValueTest extends TestCase * @param boolean $shouldPass * @param string $unsignedLong */ - #[DataProvider('provideUnsignedLong')] + #[DataProvider('provideInvalidUnsignedLong')] + #[DataProvider('provideValidUnsignedLong')] + #[DataProviderExternal(UnsignedLongTest::class, 'provideValidUnsignedLong')] + #[DependsOnClass(UnsignedLongTest::class)] public function testUnsignedLong(bool $shouldPass, string $unsignedLong): void { try { @@ -34,19 +38,25 @@ public function testUnsignedLong(bool $shouldPass, string $unsignedLong): void /** - * @return array + * @return array */ - public static function provideUnsignedLong(): array + public static function provideValidUnsignedLong(): array + { + return [ + 'valid with whitespace collapse' => [true, " 1234 \t "], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidUnsignedLong(): array { return [ 'empty' => [false, ''], - 'valid positive integer' => [true, '18446744073709551615'], 'invalid positive out-of-bounds' => [false, '18446744073709551616'], - 'valid signed positive integer' => [true, '+18446744073709551615'], - 'valid zero' => [true, '0'], - 'valid negative leading zeros' => [true, '0000000000000000000005'], 'invalid with fractional' => [false, '1.'], - 'valid with whitespace collapse' => [true, " 1 234 \n"], 'invalid negative' => [false, '-1'], 'invalid with thousands-delimiter' => [false, '1,234'], ]; diff --git a/tests/Type/UnsignedShortValueTest.php b/tests/Type/UnsignedShortValueTest.php index 32b5fa7e..e13fca99 100644 --- a/tests/Type/UnsignedShortValueTest.php +++ b/tests/Type/UnsignedShortValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\UnsignedShortTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\UnsignedShortValue; @@ -21,7 +22,10 @@ final class UnsignedShortValueTest extends TestCase * @param boolean $shouldPass * @param string $unsignedShort */ - #[DataProvider('provideUnsignedShort')] + #[DataProvider('provideInvalidUnsignedShort')] + #[DataProvider('provideValidUnsignedShort')] + #[DataProviderExternal(UnsignedShortTest::class, 'provideValidUnsignedShort')] + #[DependsOnClass(UnsignedShortTest::class)] public function testUnsignedShort(bool $shouldPass, string $unsignedShort): void { try { @@ -34,19 +38,25 @@ public function testUnsignedShort(bool $shouldPass, string $unsignedShort): void /** - * @return array + * @return array */ - public static function provideUnsignedShort(): array + public static function provideValidUnsignedShort(): array + { + return [ + 'valid with whitespace collapse' => [true, " 1234 \f "], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidUnsignedShort(): array { return [ 'empty' => [false, ''], - 'valid positive short' => [true, '65535'], 'invalid positive out-of-bounds' => [false, '65536'], - 'valid signed positive short' => [true, '+65535'], - 'valid zero' => [true, '0'], - 'valid negative leading zeros' => [true, '0000000000000000000005'], 'invalid with fractional' => [false, '1.'], - 'valid with whitespace collapse' => [true, " 1 234 \n"], 'invalid negative' => [false, '-1'], 'invalid with thousands-delimiter' => [false, '1,234'], ]; diff --git a/tests/Type/YearMonthValueTest.php b/tests/Type/YearMonthValueTest.php index 4fe4f04a..a4a5070d 100644 --- a/tests/Type/YearMonthValueTest.php +++ b/tests/Type/YearMonthValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\YearMonthTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\YearMonthValue; @@ -21,7 +22,10 @@ final class YearMonthValueTest extends TestCase * @param boolean $shouldPass * @param string $yearMonth */ - #[DataProvider('provideYearMonth')] + #[DataProvider('provideInvalidYearMonth')] + #[DataProvider('provideValidYearMonth')] + #[DataProviderExternal(YearMonthTest::class, 'provideValidYearMonth')] + #[DependsOnClass(YearMonthTest::class)] public function testYearMonth(bool $shouldPass, string $yearMonth): void { try { @@ -34,19 +38,23 @@ public function testYearMonth(bool $shouldPass, string $yearMonth): void /** - * @return array + * @return array */ - public static function provideYearMonth(): array + public static function provideValidYearMonth(): array + { + return [ + 'whitespace collapse' => [true, " 2001-10 \n "], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidYearMonth(): array { return [ 'empty' => [false, ''], - 'whitespace collapse' => [true, ' 2001-10 '], - 'valid' => [true, '2001-10'], - 'valid numeric timezone' => [true, '2001-10+02:00'], - 'valid Zulu timezone' => [true, '2001-10Z'], - 'valid 00:00 timezone' => [true, '2001-10+00:00'], - '2001 BC' => [true, '-2001-10'], - '20000 BC' => [true, '-20000-04'], 'missing part' => [false, '2001'], 'month out of range' => [false, '2001-13'], ]; diff --git a/tests/Type/YearValueTest.php b/tests/Type/YearValueTest.php index 363488cb..7202c060 100644 --- a/tests/Type/YearValueTest.php +++ b/tests/Type/YearValueTest.php @@ -4,8 +4,9 @@ namespace SimpleSAML\Test\XML\Type; -use PHPUnit\Framework\Attributes\{CoversClass, DataProvider}; +use PHPUnit\Framework\Attributes\{CoversClass, DataProvider, DataProviderExternal, DependsOnClass}; use PHPUnit\Framework\TestCase; +use SimpleSAML\Test\XML\Assert\YearTest; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\Type\YearValue; @@ -21,7 +22,10 @@ final class YearValueTest extends TestCase * @param boolean $shouldPass * @param string $year */ - #[DataProvider('provideYear')] + #[DataProvider('provideInvalidYear')] + #[DataProvider('provideValidYear')] + #[DataProviderExternal(YearTest::class, 'provideValidYear')] + #[DependsOnClass(YearTest::class)] public function testYear(bool $shouldPass, string $year): void { try { @@ -34,19 +38,24 @@ public function testYear(bool $shouldPass, string $year): void /** - * @return array + * @return array */ - public static function provideYear(): array + public static function provideValidYear(): array + { + return [ + 'whitespace collapse' => [true, " 2001 \n "], + ]; + } + + + /** + * @return array + */ + public static function provideInvalidYear(): array { return [ 'empty' => [false, ''], - 'valid' => [true, '2001'], - 'valid numeric timezone' => [true, '2001+02:00'], - 'valid Zulu timezone' => [true, '2001Z'], - 'whitespace collapse' => [true, ' 2001Z '], - 'valid 00:00 timezone' => [true, '2001+00:00'], - '2001 BC' => [true, '-2001'], - '20000 BC' => [true, '-20000'], + 'no a year' => [false, 'foobar'], ]; } }