Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
4 changes: 1 addition & 3 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,8 @@ private function resolveDefinition(Definition $definition, array $parameters = [
// Resolve the definition
try {
$value = $this->definitionResolver->resolve($definition, $parameters);
} catch (Exception $exception) {
} finally {
unset($this->entriesBeingResolved[$entryName]);

throw $exception;
}

unset($this->entriesBeingResolved[$entryName]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this line really necessary anymore?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch I've removed it on master thanks

Expand Down
31 changes: 31 additions & 0 deletions tests/IntegrationTest/ContainerMakeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,35 @@ public function testProvidedPassByReferenceParameter(ContainerBuilder $builder)
]);
$this->assertEquals('bar', $object->foo);
}

/**
* Test that PHP-7 non-exceptions are correctly handled when resolving definitions.
* @dataProvider provideContainer
*/
public function testThrowableDuringResolve(ContainerBuilder $builder)
{
$builder->addDefinitions([
'tomorrow' => \DI\factory(function() {
// Cause a TypeError to be thrown in PHP 7 when this gets resolved
return (new \DateTime())->add('tomorrow');
})
]);
$container = $builder->build();
$exception = null;
try {
// First resolve should throw the TypeError
$container->make('tomorrow');
} catch (\Throwable $e) {
$exception = $e;
}
$this->assertInstanceOf('TypeError', $exception);
$exception = null;
try {
// Second error must ALSO throw the TypeError, not a circular exception
$container->make('tomorrow');
} catch (\Throwable $e) {
$exception = $e;
}
$this->assertInstanceOf('TypeError', $exception);
}
}