Skip to content

Commit

Permalink
Enhancement: Assert that Container throws on second attempt to retrie…
Browse files Browse the repository at this point in the history
…ve service
  • Loading branch information
localheinz committed Sep 4, 2023
1 parent 6c3a043 commit 832be6f
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/Faker/Extension/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,33 @@ public function testGetThrowsRuntimeExceptionWhenServiceResolvedForIdentifierIsN
$container->get($id);
}

/**
* @dataProvider provideDefinitionThatDoesNotResolveToExtension
*/
public function testGetThrowsRuntimeExceptionWhenServiceResolvedForIdentifierIsNotAnExtensionOnSecondTry($definition): void
{
$id = 'file';

$container = new Container([
$id => $definition,
]);

try {
$container->get($id);
} catch (\RuntimeException $e) {
// do nothing
}

$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage(sprintf(
'Service resolved for identifier "%s" does not implement the %s" interface.',
$id,
Extension::class,
));

$container->get($id);
}

/**
* @return \Generator<string, array{0: callable|object|string}>
*/
Expand Down

0 comments on commit 832be6f

Please sign in to comment.