Skip to content

Commit 084cf96

Browse files
committed
Add UB tests
1 parent 71a7818 commit 084cf96

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

tests/Exception/Definition/InvalidTemplateArgumentTest.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ final class InvalidTemplateArgumentTest extends DefinitionExceptionTestCase
1919
public function testInvalidArgumentGiven(): void
2020
{
2121
$this->expectException(InvalidTemplateArgumentException::class);
22-
$this->expectExceptionMessage('Passed template argument #1 of type int<T> must be of type string, but T given');
22+
$this->expectExceptionMessage('Passed template argument #2 of type int<T, U> must be of type string, but U given');
2323

24-
$type = self::parse('int<T>');
24+
$type = self::parse('int<T, U>');
2525

2626
assert($type instanceof NamedTypeNode);
2727

28-
$argument = $type->arguments?->first();
28+
$argument = $type->arguments?->last();
2929
assert($argument instanceof TemplateArgumentNode);
3030

3131
throw InvalidTemplateArgumentException::becauseTemplateArgumentMustBe(
@@ -34,4 +34,23 @@ public function testInvalidArgumentGiven(): void
3434
type: $type,
3535
);
3636
}
37+
38+
#[TestDox('[undefined behaviour] all works if pass an non-node\'s argument')]
39+
public function testOfNonOwnArgument(): void
40+
{
41+
$this->expectException(InvalidTemplateArgumentException::class);
42+
$this->expectExceptionMessage('Passed template argument #0 of type another-type must be of type string, but T given');
43+
44+
$type = self::parse('int<T>');
45+
assert($type instanceof NamedTypeNode);
46+
47+
$argument = $type->arguments?->first();
48+
assert($argument instanceof TemplateArgumentNode);
49+
50+
throw InvalidTemplateArgumentException::becauseTemplateArgumentMustBe(
51+
argument: $argument,
52+
expected: new NamedTypeNode('string'),
53+
type: self::parse('another-type'),
54+
);
55+
}
3756
}

tests/Exception/Definition/TemplateArgumentHintsNotSupportedTest.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public function testManyArgumentsPassedWithGenericType(): void
2222
$this->expectExceptionMessage('Template argument #1 (T) of "int<out T>" does not support any hints, but "out" were passed');
2323

2424
$type = self::parse('int<out T>');
25-
2625
assert($type instanceof NamedTypeNode);
2726

2827
$argument = $type->arguments?->first();
@@ -34,14 +33,31 @@ public function testManyArgumentsPassedWithGenericType(): void
3433
);
3534
}
3635

36+
#[TestDox('[undefined behaviour] all works if pass an non-node\'s argument')]
37+
public function testOfNonOwnArgument(): void
38+
{
39+
$this->expectException(TemplateArgumentHintsNotSupportedException::class);
40+
$this->expectExceptionMessage('Template argument #1 (T) of "another-type<out T>" does not support any hints, but "in" were passed');
41+
42+
$type = self::parse('int<in T>');
43+
assert($type instanceof NamedTypeNode);
44+
45+
$argument = $type->arguments?->first();
46+
assert($argument instanceof TemplateArgumentNode);
47+
48+
throw TemplateArgumentHintsNotSupportedException::becauseTooManyHints(
49+
argument: $argument,
50+
type: self::parse('another-type<out T>'),
51+
);
52+
}
53+
3754
#[TestDox('[not applicable] expected int (0 arguments), passed int (0 arguments)')]
3855
public function testManyArgumentsPassedWithBasicType(): void
3956
{
4057
$this->skipIfAssertionsDisabled();
4158
$this->expectExceptionMessage('Incorrect exception usage');
4259

4360
$type = self::parse('int<T>');
44-
4561
assert($type instanceof NamedTypeNode);
4662

4763
$argument = $type->arguments?->first();

0 commit comments

Comments
 (0)