@@ -616,6 +616,178 @@ public function testPHP8DuplicateTypeInUnionWhitespaceAndComment()
616616 }//end testPHP8DuplicateTypeInUnionWhitespaceAndComment()
617617
618618
619+ /**
620+ * Verify recognition of PHP8 constructor property promotion without type declaration, with defaults.
621+ *
622+ * @return void
623+ */
624+ public function testPHP8ConstructorPropertyPromotionNoTypes ()
625+ {
626+ $ expected = [];
627+ $ expected [0 ] = [
628+ 'name ' => '$x ' ,
629+ 'content ' => 'public $x = 0.0 ' ,
630+ 'default ' => '0.0 ' ,
631+ 'pass_by_reference ' => false ,
632+ 'variable_length ' => false ,
633+ 'type_hint ' => '' ,
634+ 'nullable_type ' => false ,
635+ 'property_visibility ' => 'public ' ,
636+ ];
637+ $ expected [1 ] = [
638+ 'name ' => '$y ' ,
639+ 'content ' => 'protected $y = \'\'' ,
640+ 'default ' => "'' " ,
641+ 'pass_by_reference ' => false ,
642+ 'variable_length ' => false ,
643+ 'type_hint ' => '' ,
644+ 'nullable_type ' => false ,
645+ 'property_visibility ' => 'protected ' ,
646+ ];
647+ $ expected [2 ] = [
648+ 'name ' => '$z ' ,
649+ 'content ' => 'private $z = null ' ,
650+ 'default ' => 'null ' ,
651+ 'pass_by_reference ' => false ,
652+ 'variable_length ' => false ,
653+ 'type_hint ' => '' ,
654+ 'nullable_type ' => false ,
655+ 'property_visibility ' => 'private ' ,
656+ ];
657+
658+ $ this ->getMethodParametersTestHelper ('/* ' .__FUNCTION__ .' */ ' , $ expected );
659+
660+ }//end testPHP8ConstructorPropertyPromotionNoTypes()
661+
662+
663+ /**
664+ * Verify recognition of PHP8 constructor property promotion with type declarations.
665+ *
666+ * @return void
667+ */
668+ public function testPHP8ConstructorPropertyPromotionWithTypes ()
669+ {
670+ $ expected = [];
671+ $ expected [0 ] = [
672+ 'name ' => '$x ' ,
673+ 'content ' => 'protected float|int $x ' ,
674+ 'pass_by_reference ' => false ,
675+ 'variable_length ' => false ,
676+ 'type_hint ' => 'float|int ' ,
677+ 'nullable_type ' => false ,
678+ 'property_visibility ' => 'protected ' ,
679+ ];
680+ $ expected [1 ] = [
681+ 'name ' => '$y ' ,
682+ 'content ' => 'public ?string &$y = \'test \'' ,
683+ 'default ' => "'test' " ,
684+ 'pass_by_reference ' => true ,
685+ 'variable_length ' => false ,
686+ 'type_hint ' => '?string ' ,
687+ 'nullable_type ' => true ,
688+ 'property_visibility ' => 'public ' ,
689+ ];
690+ $ expected [2 ] = [
691+ 'name ' => '$z ' ,
692+ 'content ' => 'private mixed $z ' ,
693+ 'pass_by_reference ' => false ,
694+ 'variable_length ' => false ,
695+ 'type_hint ' => 'mixed ' ,
696+ 'nullable_type ' => false ,
697+ 'property_visibility ' => 'private ' ,
698+ ];
699+
700+ $ this ->getMethodParametersTestHelper ('/* ' .__FUNCTION__ .' */ ' , $ expected );
701+
702+ }//end testPHP8ConstructorPropertyPromotionWithTypes()
703+
704+
705+ /**
706+ * Verify recognition of PHP8 constructor with both property promotion as well as normal parameters.
707+ *
708+ * @return void
709+ */
710+ public function testPHP8ConstructorPropertyPromotionAndNormalParam ()
711+ {
712+ $ expected = [];
713+ $ expected [0 ] = [
714+ 'name ' => '$promotedProp ' ,
715+ 'content ' => 'public int $promotedProp ' ,
716+ 'pass_by_reference ' => false ,
717+ 'variable_length ' => false ,
718+ 'type_hint ' => 'int ' ,
719+ 'nullable_type ' => false ,
720+ 'property_visibility ' => 'public ' ,
721+ ];
722+ $ expected [1 ] = [
723+ 'name ' => '$normalArg ' ,
724+ 'content ' => '?int $normalArg ' ,
725+ 'pass_by_reference ' => false ,
726+ 'variable_length ' => false ,
727+ 'type_hint ' => '?int ' ,
728+ 'nullable_type ' => true ,
729+ ];
730+
731+ $ this ->getMethodParametersTestHelper ('/* ' .__FUNCTION__ .' */ ' , $ expected );
732+
733+ }//end testPHP8ConstructorPropertyPromotionAndNormalParam()
734+
735+
736+ /**
737+ * Verify behaviour when a non-constructor function uses PHP 8 property promotion syntax.
738+ *
739+ * @return void
740+ */
741+ public function testPHP8ConstructorPropertyPromotionGlobalFunction ()
742+ {
743+ $ expected = [];
744+ $ expected [0 ] = [
745+ 'name ' => '$x ' ,
746+ 'content ' => 'private $x ' ,
747+ 'pass_by_reference ' => false ,
748+ 'variable_length ' => false ,
749+ 'type_hint ' => '' ,
750+ 'nullable_type ' => false ,
751+ 'property_visibility ' => 'private ' ,
752+ ];
753+
754+ $ this ->getMethodParametersTestHelper ('/* ' .__FUNCTION__ .' */ ' , $ expected );
755+
756+ }//end testPHP8ConstructorPropertyPromotionGlobalFunction()
757+
758+
759+ /**
760+ * Verify behaviour when an abstract constructor uses PHP 8 property promotion syntax.
761+ *
762+ * @return void
763+ */
764+ public function testPHP8ConstructorPropertyPromotionAbstractMethod ()
765+ {
766+ $ expected = [];
767+ $ expected [0 ] = [
768+ 'name ' => '$y ' ,
769+ 'content ' => 'public callable $y ' ,
770+ 'pass_by_reference ' => false ,
771+ 'variable_length ' => false ,
772+ 'type_hint ' => 'callable ' ,
773+ 'nullable_type ' => false ,
774+ 'property_visibility ' => 'public ' ,
775+ ];
776+ $ expected [1 ] = [
777+ 'name ' => '$x ' ,
778+ 'content ' => 'private ...$x ' ,
779+ 'pass_by_reference ' => false ,
780+ 'variable_length ' => true ,
781+ 'type_hint ' => '' ,
782+ 'nullable_type ' => false ,
783+ 'property_visibility ' => 'private ' ,
784+ ];
785+
786+ $ this ->getMethodParametersTestHelper ('/* ' .__FUNCTION__ .' */ ' , $ expected );
787+
788+ }//end testPHP8ConstructorPropertyPromotionAbstractMethod()
789+
790+
619791 /**
620792 * Test helper.
621793 *
0 commit comments