Skip to content

Commit

Permalink
Add test to proof docblock is being used when type hint is array
Browse files Browse the repository at this point in the history
  • Loading branch information
DannyvdSluijs committed Jan 11, 2021
1 parent 06f0b06 commit 22fe5f9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
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
7 changes: 6 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,5 +71,11 @@ 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')]])]);
}

}
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';
}
}

0 comments on commit 22fe5f9

Please sign in to comment.