@@ -97,13 +97,15 @@ private static function doInvocation(
9797
9898 // execute
9999 if ($ callHandler ->canHandle ($ methodName , $ classMetadata , $ options )) {
100+ $ instance ->assertGivenParametersMatchMethodSignature ($ methodName , $ arguments , $ classMetadata );
101+
100102 if (! $ isStatic ) {
101103 $ return = $ callHandler ->execute ($ objectOrClassName , $ methodName , $ arguments , $ classMetadata );
102104 } else {
103105 $ return = $ callHandler ->executeStatic ($ objectOrClassName , $ methodName , $ arguments , $ classMetadata );
104106 }
105107
106- $ instance ->assertReturnType ($ objectOrClassName , $ methodName , $ return , $ classMetadata );
108+ $ instance ->assertCorrectReturnType ($ objectOrClassName , $ methodName , $ return , $ classMetadata );
107109
108110 return $ return ;
109111 }
@@ -124,10 +126,35 @@ private function classMetadata(string $className) : ClassMetadata
124126 ->classMetadata [$ className ];
125127 }
126128
129+ private function assertGivenParametersMatchMethodSignature (
130+ string $ methodName ,
131+ array $ parameters ,
132+ ClassMetadata $ classMetadata
133+ )
134+ {
135+ $ methodMetadata = $ classMetadata ->features [VirtualMethods::FEATURES_KEY ][$ methodName ];
136+ $ expectedParameterCount = count ($ methodMetadata ->paramters );
137+
138+ $ givenParametersCount = count ($ parameters );
139+
140+ if ($ expectedParameterCount !== $ givenParametersCount ) {
141+ throw new \ArgumentCountError (
142+ sprintf (
143+ 'Too %s arguments to function %s::%s(), %d passed and exactly %d expected ' ,
144+ $ expectedParameterCount > $ givenParametersCount ? 'few ' : 'many ' ,
145+ $ classMetadata ->name ,
146+ $ methodName ,
147+ count ($ parameters ),
148+ $ expectedParameterCount
149+ )
150+ );
151+ }
152+ }
153+
127154 /**
128155 * @param object|string $objectContext
129156 */
130- private function assertReturnType (
157+ private function assertCorrectReturnType (
131158 $ objectContext ,
132159 string $ methodName ,
133160 $ returnValue ,
0 commit comments