Skip to content

Commit a8339ff

Browse files
committed
test: Add test to proof docblock is being used when type hint is array
1 parent 06f0b06 commit a8339ff

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

lib/Dispatcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public function dispatch($msg)
152152
}
153153
}
154154
} else if ($type instanceof Types\Array_) {
155-
$class = (string)$type->getValueType()->getFqsen();
155+
$class = (string) $type->getValueType()->getFqsen();
156156
$value = $this->mapper->mapArray($value, [], $class);
157157
} else {
158158
throw new Error('Type is not matching @param tag', ErrorCode::INVALID_PARAMS);

tests/DispatcherTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public function testCallMethodWithUnionTypeParamTag()
6363
$this->assertEquals('Hello World', $result);
6464
$this->assertEquals($this->calls, [new MethodCall('someMethodWithUnionTypeParamTag', [[new Argument('whatever')]])]);
6565
}
66-
6766
public function testCallMethodWithTypeHintWithNamedArgsOnNestedTarget()
6867
{
6968
$result = $this->dispatcher->dispatch((string)new Request(1, 'nestedTarget->someMethodWithTypeHint', ['arg' => new Argument('whatever')]));
@@ -72,5 +71,11 @@ public function testCallMethodWithTypeHintWithNamedArgsOnNestedTarget()
7271
$this->assertEquals($this->callsOfNestedTarget, [new MethodCall('someMethodWithTypeHint', [new Argument('whatever')])]);
7372
}
7473

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

7681
}

tests/Target.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,13 @@ public function someMethodWithDifferentlyTypedArgs(string $arg1 = null, int $arg
4949
$this->calls[] = new MethodCall('someMethodWithDifferentlyTypedArgs', func_get_args());
5050
return 'Hello World';
5151
}
52+
53+
/**
54+
* @param Argument[] $args
55+
*/
56+
public function someMethodWithArrayTypeHint(array $args): string
57+
{
58+
$this->calls[] = new MethodCall('someMethodWithArrayTypeHint', func_get_args());
59+
return 'Hello World';
60+
}
5261
}

0 commit comments

Comments
 (0)