Skip to content
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

test: Add test to proof docblock is being used when type hint is array #6

Merged
merged 2 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public function dispatch($msg)
}
}
} else if ($type instanceof Types\Array_) {
$class = (string)$type->getValueType()->getFqsen();
$class = (string) $type->getValueType()->getFqsen();
$value = $this->mapper->mapArray($value, [], $class);
} else {
throw new Error('Type is not matching @param tag', ErrorCode::INVALID_PARAMS);
Expand Down
8 changes: 7 additions & 1 deletion tests/DispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public function testCallMethodWithUnionTypeParamTag()
$this->assertEquals('Hello World', $result);
$this->assertEquals($this->calls, [new MethodCall('someMethodWithUnionTypeParamTag', [[new Argument('whatever')]])]);
}

public function testCallMethodWithTypeHintWithNamedArgsOnNestedTarget()
{
$result = $this->dispatcher->dispatch((string)new Request(1, 'nestedTarget->someMethodWithTypeHint', ['arg' => new Argument('whatever')]));
Expand All @@ -72,6 +71,13 @@ public function testCallMethodWithTypeHintWithNamedArgsOnNestedTarget()
$this->assertEquals($this->callsOfNestedTarget, [new MethodCall('someMethodWithTypeHint', [new Argument('whatever')])]);
}

public function testCallMethodWithArrayTypeHintAndDocblock(): void
{
$result = $this->dispatcher->dispatch((string)new Request(1, 'someMethodWithArrayTypeHint', ['args' => [new Argument('1'), new Argument('2')]]));
$this->assertEquals('Hello World', $result);
$this->assertEquals($this->calls, [new MethodCall('someMethodWithArrayTypeHint', [[new Argument('1'), new Argument('2')]])]);
}

public function testCallMethodWithAdditionalProvidedParamsOnSomeMethodWithoutArgs()
{
$result = $this->dispatcher->dispatch((string) new Request(1, 'someMethodWithoutArgs', ['arg' => new Argument('whatever')]));
Expand Down
9 changes: 9 additions & 0 deletions tests/Target.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,13 @@ public function someMethodWithDifferentlyTypedArgs(string $arg1 = null, int $arg
$this->calls[] = new MethodCall('someMethodWithDifferentlyTypedArgs', func_get_args());
return 'Hello World';
}

/**
* @param Argument[] $args
*/
public function someMethodWithArrayTypeHint(array $args): string
{
$this->calls[] = new MethodCall('someMethodWithArrayTypeHint', func_get_args());
return 'Hello World';
}
}