Skip to content

Commit

Permalink
Add data provider for multiple different arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
adriansuter committed Aug 12, 2019
1 parent 74a0b1a commit 14e070b
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions tests/Controllers/HelloControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,23 @@

class HelloControllerTest extends TestCase
{
public function testInvoke()
/**
* @return array
*/
public function argsDataProvider(): array
{
return [
['Slim'],
['World']
];
}

/**
* @dataProvider argsDataProvider
*
* @param string $argName
*/
public function testInvoke(string $argName)
{
$self = $this;
$twigProphecy = $this->prophesize(Twig::class);
Expand All @@ -23,11 +39,11 @@ public function testInvoke()
$twigProphecy,
'render',
[Argument::type(ResponseInterface::class), Argument::type('string'), Argument::type('array')]
))->will(function ($arguments) use ($self) {
))->will(function ($arguments) use ($self, $argName) {
$self->assertSame('hello.twig', $arguments[1]);
$self->assertSame([
'pageTitle' => 'Hello Slim',
'name' => 'Slim'
'pageTitle' => 'Hello ' . $argName,
'name' => $argName
], $arguments[2]);

return $arguments[0];
Expand All @@ -37,8 +53,8 @@ public function testInvoke()
$loggerProphecy = $this->prophesize(LoggerInterface::class);
$loggerProphecy->addMethodProphecy(
(new MethodProphecy($loggerProphecy, 'debug', [Argument::type('string')]))
->will(function ($arguments) use ($self) {
$self->assertSame('Hello "Slim"', $arguments[0]);
->will(function ($arguments) use ($self, $argName) {
$self->assertSame('Hello "' . $argName . '"', $arguments[0]);
})
);

Expand All @@ -53,6 +69,6 @@ public function testInvoke()
$serverRequest = $this->createMock(ServerRequestInterface::class);
$response = $this->createMock(ResponseInterface::class);

$helloController($serverRequest, $response, ['name' => 'Slim']);
$helloController($serverRequest, $response, ['name' => $argName]);
}
}

0 comments on commit 14e070b

Please sign in to comment.