@@ -1649,6 +1649,18 @@ public function testNamedArgumentsConstructorAnnotationWithDefaultProperty(): vo
1649
1649
self ::assertSame (1234 , $ result [0 ]->getBar ());
1650
1650
}
1651
1651
1652
+ public function testNamedArgumentsConstructorAnnotationWithExtraArguments (): void
1653
+ {
1654
+ $ docParser = $ this ->createTestParser ();
1655
+
1656
+ $ this ->expectException (AnnotationException::class);
1657
+ $ this ->expectExceptionMessageMatches (
1658
+ '/does not have a property named "invalid"\s.*\sAvailable named arguments: foo, bar/ '
1659
+ );
1660
+
1661
+ $ docParser ->parse ('/** @AnotherNamedAnnotation(foo="baz", invalid="uh oh") */ ' );
1662
+ }
1663
+
1652
1664
public function testNamedArgumentsConstructorAnnotationWithDefaultPropertyAsArray (): void
1653
1665
{
1654
1666
$ result = $ this
@@ -1701,6 +1713,115 @@ public function testNamedArgumentsConstructorAnnotationWithWrongArgumentType():
1701
1713
}
1702
1714
}
1703
1715
1716
+ public function testAnnotationWithConstructorWithVariadicParamAndExtraNamedArguments (): void
1717
+ {
1718
+ $ parser = $ this ->createTestParser ();
1719
+ $ docblock = <<<'DOCBLOCK'
1720
+ /**
1721
+ * @SomeAnnotationWithConstructorWithVariadicParam(name = "Some data", foo = "Foo", bar = "Bar")
1722
+ */
1723
+ DOCBLOCK;
1724
+
1725
+ $ this ->expectException (AnnotationException::class);
1726
+ $ this ->expectExceptionMessageMatches (
1727
+ '/does not have a property named "foo"\s.*\sAvailable named arguments: name/ '
1728
+ );
1729
+
1730
+ $ parser ->parse ($ docblock );
1731
+ }
1732
+
1733
+ public function testAnnotationWithConstructorWithVariadicParamAndExtraNamedArgumentsShuffled (): void
1734
+ {
1735
+ $ parser = $ this ->createTestParser ();
1736
+ $ docblock = <<<'DOCBLOCK'
1737
+ /**
1738
+ * @SomeAnnotationWithConstructorWithVariadicParam(foo = "Foo", name = "Some data", bar = "Bar")
1739
+ */
1740
+ DOCBLOCK;
1741
+
1742
+ $ this ->expectException (AnnotationException::class);
1743
+ $ this ->expectExceptionMessageMatches (
1744
+ '/does not have a property named "foo"\s.*\sAvailable named arguments: name/ '
1745
+ );
1746
+
1747
+ $ parser ->parse ($ docblock );
1748
+ }
1749
+
1750
+ public function testAnnotationWithConstructorWithVariadicParamAndCombinedNamedAndPositionalArguments (): void
1751
+ {
1752
+ $ parser = $ this ->createTestParser ();
1753
+ $ docblock = <<<'DOCBLOCK'
1754
+ /**
1755
+ * @SomeAnnotationWithConstructorWithVariadicParam("Some data", "Foo", bar = "Bar")
1756
+ */
1757
+ DOCBLOCK;
1758
+
1759
+ $ this ->expectException (AnnotationException::class);
1760
+ $ this ->expectExceptionMessageMatches (
1761
+ '/does not have a property named "bar"\s.*\sAvailable named arguments: name/ '
1762
+ );
1763
+
1764
+ $ parser ->parse ($ docblock );
1765
+ }
1766
+
1767
+ public function testAnnotationWithConstructorWithVariadicParamPassOneNamedArgument (): void
1768
+ {
1769
+ $ parser = $ this ->createTestParser ();
1770
+ $ docblock = <<<'DOCBLOCK'
1771
+ /**
1772
+ * @SomeAnnotationWithConstructorWithVariadicParam(name = "Some data", data = "Foo")
1773
+ */
1774
+ DOCBLOCK;
1775
+
1776
+ $ this ->expectException (AnnotationException::class);
1777
+ $ this ->expectExceptionMessageMatches (
1778
+ '/does not have a property named "data"\s.*\sAvailable named arguments: name/ '
1779
+ );
1780
+
1781
+ $ parser ->parse ($ docblock );
1782
+ }
1783
+
1784
+ public function testAnnotationWithConstructorWithVariadicParamPassPositionalArguments (): void
1785
+ {
1786
+ $ parser = $ this ->createTestParser ();
1787
+ $ docblock = <<<'DOCBLOCK'
1788
+ /**
1789
+ * @SomeAnnotationWithConstructorWithVariadicParam("Some data", "Foo", "Bar")
1790
+ */
1791
+ DOCBLOCK;
1792
+
1793
+ $ result = $ parser ->parse ($ docblock );
1794
+ self ::assertCount (1 , $ result );
1795
+ $ annot = $ result [0 ];
1796
+
1797
+ self ::assertInstanceOf (SomeAnnotationWithConstructorWithVariadicParam::class, $ annot );
1798
+
1799
+ self ::assertSame ('Some data ' , $ annot ->name );
1800
+ // Positional extra arguments will be ignored
1801
+ self ::assertSame ([], $ annot ->data );
1802
+ }
1803
+
1804
+ public function testAnnotationWithConstructorWithVariadicParamNoArgs (): void
1805
+ {
1806
+ $ parser = $ this ->createTestParser ();
1807
+
1808
+ // Without variadic arguments
1809
+ $ docblock = <<<'DOCBLOCK'
1810
+ /**
1811
+ * @SomeAnnotationWithConstructorWithVariadicParam("Some data")
1812
+ */
1813
+ DOCBLOCK;
1814
+
1815
+ $ result = $ parser ->parse ($ docblock );
1816
+ self ::assertCount (1 , $ result );
1817
+ $ annot = $ result [0 ];
1818
+
1819
+ self ::assertInstanceOf (SomeAnnotationWithConstructorWithVariadicParam::class, $ annot );
1820
+
1821
+ self ::assertSame ('Some data ' , $ annot ->name );
1822
+ self ::assertSame ([], $ annot ->data );
1823
+ }
1824
+
1704
1825
/**
1705
1826
* Override for BC with PHPUnit <8
1706
1827
*/
@@ -1782,6 +1903,25 @@ public function getBar(): int
1782
1903
}
1783
1904
}
1784
1905
1906
+ /**
1907
+ * @Annotation
1908
+ * @NamedArgumentConstructor
1909
+ */
1910
+ class SomeAnnotationWithConstructorWithVariadicParam
1911
+ {
1912
+ public function __construct (string $ name , string ...$ data )
1913
+ {
1914
+ $ this ->name = $ name ;
1915
+ $ this ->data = $ data ;
1916
+ }
1917
+
1918
+ /** @var string[] */
1919
+ public $ data ;
1920
+
1921
+ /** @var string */
1922
+ public $ name ;
1923
+ }
1924
+
1785
1925
/** @Annotation */
1786
1926
class SettingsAnnotation
1787
1927
{
0 commit comments