@@ -1644,6 +1644,18 @@ public function testNamedArgumentsConstructorInterfaceWithDefaultValue(): void
1644
1644
self ::assertSame (1234 , $ result [0 ]->getBar ());
1645
1645
}
1646
1646
1647
+ public function testNamedArgumentsConstructorInterfaceWithExtraArguments (): void
1648
+ {
1649
+ $ docParser = $ this ->createTestParser ();
1650
+
1651
+ $ this ->expectException (AnnotationException::class);
1652
+ $ this ->expectExceptionMessageMatches (
1653
+ '/does not have a property named "invalid"\s.*\sAvailable named arguments: foo, bar/ '
1654
+ );
1655
+
1656
+ $ docParser ->parse ('/** @NamedAnnotation(foo="baz", invalid="uh oh") */ ' );
1657
+ }
1658
+
1647
1659
public function testNamedArgumentsConstructorAnnotation (): void
1648
1660
{
1649
1661
$ result = $ this
@@ -1692,6 +1704,18 @@ public function testNamedArgumentsConstructorAnnotationWithDefaultProperty(): vo
1692
1704
self ::assertSame (1234 , $ result [0 ]->getBar ());
1693
1705
}
1694
1706
1707
+ public function testNamedArgumentsConstructorAnnotationWithExtraArguments (): void
1708
+ {
1709
+ $ docParser = $ this ->createTestParser ();
1710
+
1711
+ $ this ->expectException (AnnotationException::class);
1712
+ $ this ->expectExceptionMessageMatches (
1713
+ '/does not have a property named "invalid"\s.*\sAvailable named arguments: foo, bar/ '
1714
+ );
1715
+
1716
+ $ docParser ->parse ('/** @AnotherNamedAnnotation(foo="baz", invalid="uh oh") */ ' );
1717
+ }
1718
+
1695
1719
public function testNamedArgumentsConstructorAnnotationWithDefaultPropertyAsArray (): void
1696
1720
{
1697
1721
$ result = $ this
@@ -1744,6 +1768,115 @@ public function testNamedArgumentsConstructorAnnotationWithWrongArgumentType():
1744
1768
}
1745
1769
}
1746
1770
1771
+ public function testAnnotationWithConstructorWithVariadicParamAndExtraNamedArguments (): void
1772
+ {
1773
+ $ parser = $ this ->createTestParser ();
1774
+ $ docblock = <<<'DOCBLOCK'
1775
+ /**
1776
+ * @SomeAnnotationWithConstructorWithVariadicParam(name = "Some data", foo = "Foo", bar = "Bar")
1777
+ */
1778
+ DOCBLOCK;
1779
+
1780
+ $ this ->expectException (AnnotationException::class);
1781
+ $ this ->expectExceptionMessageMatches (
1782
+ '/does not have a property named "foo"\s.*\sAvailable named arguments: name/ '
1783
+ );
1784
+
1785
+ $ parser ->parse ($ docblock );
1786
+ }
1787
+
1788
+ public function testAnnotationWithConstructorWithVariadicParamAndExtraNamedArgumentsShuffled (): void
1789
+ {
1790
+ $ parser = $ this ->createTestParser ();
1791
+ $ docblock = <<<'DOCBLOCK'
1792
+ /**
1793
+ * @SomeAnnotationWithConstructorWithVariadicParam(foo = "Foo", name = "Some data", bar = "Bar")
1794
+ */
1795
+ DOCBLOCK;
1796
+
1797
+ $ this ->expectException (AnnotationException::class);
1798
+ $ this ->expectExceptionMessageMatches (
1799
+ '/does not have a property named "foo"\s.*\sAvailable named arguments: name/ '
1800
+ );
1801
+
1802
+ $ parser ->parse ($ docblock );
1803
+ }
1804
+
1805
+ public function testAnnotationWithConstructorWithVariadicParamAndCombinedNamedAndPositionalArguments (): void
1806
+ {
1807
+ $ parser = $ this ->createTestParser ();
1808
+ $ docblock = <<<'DOCBLOCK'
1809
+ /**
1810
+ * @SomeAnnotationWithConstructorWithVariadicParam("Some data", "Foo", bar = "Bar")
1811
+ */
1812
+ DOCBLOCK;
1813
+
1814
+ $ this ->expectException (AnnotationException::class);
1815
+ $ this ->expectExceptionMessageMatches (
1816
+ '/does not have a property named "bar"\s.*\sAvailable named arguments: name/ '
1817
+ );
1818
+
1819
+ $ parser ->parse ($ docblock );
1820
+ }
1821
+
1822
+ public function testAnnotationWithConstructorWithVariadicParamPassOneNamedArgument (): void
1823
+ {
1824
+ $ parser = $ this ->createTestParser ();
1825
+ $ docblock = <<<'DOCBLOCK'
1826
+ /**
1827
+ * @SomeAnnotationWithConstructorWithVariadicParam(name = "Some data", data = "Foo")
1828
+ */
1829
+ DOCBLOCK;
1830
+
1831
+ $ this ->expectException (AnnotationException::class);
1832
+ $ this ->expectExceptionMessageMatches (
1833
+ '/does not have a property named "data"\s.*\sAvailable named arguments: name/ '
1834
+ );
1835
+
1836
+ $ parser ->parse ($ docblock );
1837
+ }
1838
+
1839
+ public function testAnnotationWithConstructorWithVariadicParamPassPositionalArguments (): void
1840
+ {
1841
+ $ parser = $ this ->createTestParser ();
1842
+ $ docblock = <<<'DOCBLOCK'
1843
+ /**
1844
+ * @SomeAnnotationWithConstructorWithVariadicParam("Some data", "Foo", "Bar")
1845
+ */
1846
+ DOCBLOCK;
1847
+
1848
+ $ result = $ parser ->parse ($ docblock );
1849
+ self ::assertCount (1 , $ result );
1850
+ $ annot = $ result [0 ];
1851
+
1852
+ self ::assertInstanceOf (SomeAnnotationWithConstructorWithVariadicParam::class, $ annot );
1853
+
1854
+ self ::assertSame ('Some data ' , $ annot ->name );
1855
+ // Positional extra arguments will be ignored
1856
+ self ::assertSame ([], $ annot ->data );
1857
+ }
1858
+
1859
+ public function testAnnotationWithConstructorWithVariadicParamNoArgs (): void
1860
+ {
1861
+ $ parser = $ this ->createTestParser ();
1862
+
1863
+ // Without variadic arguments
1864
+ $ docblock = <<<'DOCBLOCK'
1865
+ /**
1866
+ * @SomeAnnotationWithConstructorWithVariadicParam("Some data")
1867
+ */
1868
+ DOCBLOCK;
1869
+
1870
+ $ result = $ parser ->parse ($ docblock );
1871
+ self ::assertCount (1 , $ result );
1872
+ $ annot = $ result [0 ];
1873
+
1874
+ self ::assertInstanceOf (SomeAnnotationWithConstructorWithVariadicParam::class, $ annot );
1875
+
1876
+ self ::assertSame ('Some data ' , $ annot ->name );
1877
+ self ::assertSame ([], $ annot ->data );
1878
+ }
1879
+
1747
1880
/**
1748
1881
* Override for BC with PHPUnit <8
1749
1882
*/
@@ -1850,6 +1983,25 @@ public function getBar(): int
1850
1983
}
1851
1984
}
1852
1985
1986
+ /**
1987
+ * @Annotation
1988
+ * @NamedArgumentConstructor
1989
+ */
1990
+ class SomeAnnotationWithConstructorWithVariadicParam
1991
+ {
1992
+ public function __construct (string $ name , string ...$ data )
1993
+ {
1994
+ $ this ->name = $ name ;
1995
+ $ this ->data = $ data ;
1996
+ }
1997
+
1998
+ /** @var string[] */
1999
+ public $ data ;
2000
+
2001
+ /** @var string */
2002
+ public $ name ;
2003
+ }
2004
+
1853
2005
/** @Annotation */
1854
2006
class SettingsAnnotation
1855
2007
{
0 commit comments