Skip to content
This repository was archived by the owner on Jan 21, 2020. It is now read-only.

Commit 5268853

Browse files
committed
Added test for non existent invokable class
1 parent 33a5150 commit 5268853

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/InvokableTestTrait.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace Zend\ContainerConfigTest;
1111

1212
use ArgumentCountError;
13+
use Error;
1314
use Psr\Container\ContainerExceptionInterface;
1415
use Zend\ContainerConfigTest\Helper\Assert;
1516

@@ -125,4 +126,44 @@ function () use ($container) {
125126
[ArgumentCountError::class, ContainerExceptionInterface::class]
126127
);
127128
}
129+
130+
final public function testFetchingNonExistingInvokableServiceResultsInException() : void
131+
{
132+
$config = [
133+
'invokables' => [
134+
TestAsset\NonExistent::class,
135+
],
136+
];
137+
138+
$container = $this->createContainer($config);
139+
140+
self::assertTrue($container->has(TestAsset\NonExistent::class));
141+
142+
Assert::expectedExceptions(
143+
function () use ($container) {
144+
$container->get(TestAsset\NonExistent::class);
145+
},
146+
[Error::class, ContainerExceptionInterface::class]
147+
);
148+
}
149+
150+
final public function testFetchingNonExistingInvokableByAliasServiceResultsInException() : void
151+
{
152+
$config = [
153+
'invokables' => [
154+
'alias' => TestAsset\NonExistent::class,
155+
],
156+
];
157+
158+
$container = $this->createContainer($config);
159+
160+
self::assertTrue($container->has('alias'));
161+
162+
Assert::expectedExceptions(
163+
function () use ($container) {
164+
$container->get('alias');
165+
},
166+
[Error::class, ContainerExceptionInterface::class]
167+
);
168+
}
128169
}

0 commit comments

Comments
 (0)