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: Proof @param ?string is supported in current setup #50

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
27 changes: 26 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,31 @@ 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')]));
$this->assertEquals('Hello World', $result);
$this->assertEquals($this->calls, [new MethodCall('someMethodWithoutArgs', [])]);
}

public function testCallMethodWithAdditionalProvidedParamsOnSomeMethodWithTypeHint()
{
$result = $this->dispatcher->dispatch((string) new Request(1, 'someMethodWithTypeHint', ['arg' => new Argument('whatever'), 'arg2' => new Argument('anything')]));
$this->assertEquals('Hello World', $result);
$this->assertEquals($this->calls, [new MethodCall('someMethodWithTypeHint', [new Argument('whatever')])]);
}

public function testSomeMethodWithNullableTypeParamTag(): void
{
$result = $this->dispatcher->dispatch((string)new Request(1, 'someMethodWithNullableTypeParamTag', ['arg' => null]));
$this->assertEquals('Hello World', $result);
$this->assertEquals($this->calls, [new MethodCall('someMethodWithNullableTypeParamTag', [null])]);
}
}
18 changes: 18 additions & 0 deletions tests/Target.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,22 @@ 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';
}

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