-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#145: Fix bug with empty arguments #170
Changes from 3 commits
3b159c5
7c4f4a3
069c0ef
f08e3d6
fc57d8b
604756e
106ee3f
7e66c4a
4b2fcae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -134,21 +134,43 @@ protected function assertArguments( | |||||
$expectedCount = count($expected); | ||||||
$actualCount = count($actual); | ||||||
|
||||||
if ($expectedCount !== $actualCount) { | ||||||
if ($isClass) { | ||||||
$reflectionMethod = new \ReflectionMethod($class, $function); | ||||||
$parameters = $reflectionMethod->getParameters(); | ||||||
$requiredParametersCount = count(array_filter($parameters, fn($param) => !$param->isOptional())); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} else { | ||||||
$parameters = $actual; | ||||||
$requiredParametersCount = count(array_filter($actual, fn ($item) => $item !== self::OPTIONAL_ARGUMENT_NAME)); | ||||||
} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's move it to the separate method which will return [$parameters, $requiredParametersCount] |
||||||
|
||||||
if ($expectedCount > $actualCount || $expectedCount < $requiredParametersCount) { | ||||||
throw new Exception("Failed assert that function {$function} was called with {$expectedCount} arguments, actually it calls with {$actualCount} arguments."); | ||||||
} | ||||||
if ($expectedCount !== $actualCount) { | ||||||
$this->assertFalse( | ||||||
$expectedCount > $actualCount || $expectedCount < $requiredParametersCount, | ||||||
"Failed assert that function {$function} was called with {$expectedCount} arguments, actually it calls with {$actualCount} arguments." | ||||||
); | ||||||
} | ||||||
|
||||||
$expected = array_pad($expected, $actualCount, self::OPTIONAL_ARGUMENT_NAME); | ||||||
if ($isClass) { | ||||||
foreach ($parameters as $index => $parameter) { | ||||||
if (!isset($expected[$index]) && $parameter->isOptional()) { | ||||||
$expected[$index] = $parameter->getDefaultValue(); | ||||||
} | ||||||
} | ||||||
} else { | ||||||
$expected = array_pad($expected, $actualCount, self::OPTIONAL_ARGUMENT_NAME); | ||||||
} | ||||||
|
||||||
$message = ($isClass) | ||||||
? "Class '{$class}'\nMethod: '{$function}'\nMethod call index: {$callIndex}" | ||||||
: "Namespace '{$class}'\nFunction: '{$function}'\nCall index: {$callIndex}"; | ||||||
|
||||||
foreach ($actual as $index => $argument) { | ||||||
$expectedArgument = $expected[$index] ?? null; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as discussed, please check that this is realy need |
||||||
|
||||||
if ($isClass && $parameters[$index]->isOptional() && $argument !== $expectedArgument) { | ||||||
$argument = $expected[$index]; | ||||||
} | ||||||
|
||||||
$this->assertEquals( | ||||||
$expected[$index], | ||||||
$argument, | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.