Skip to content

Don't emit warnings for circular values#56

Open
martinstuecklschwaiger wants to merge 3 commits into
PHP-DI:masterfrom
martinstuecklschwaiger:circular-references
Open

Don't emit warnings for circular values#56
martinstuecklschwaiger wants to merge 3 commits into
PHP-DI:masterfrom
martinstuecklschwaiger:circular-references

Conversation

@martinstuecklschwaiger
Copy link
Copy Markdown

This fixes warnings for edge cases in NotCallableException::fromInvalidCallable():

  • If $value contains a circular reference, var_export() would emit a warning. This fixes it by using print_r() instead.
  • [SomeObject, null] would not be treated in the "object" if-branch, because null wouldn't be treated as a value by isset().

The problem is documented with tests that previously would emit a warning, but not anymore.

* Tests for circular references
* Tests for `[…, null]` values
If the second value entry is null, we should still print the object
error message. `isset()` doesn't match it though.
print_r() handles circular references nicely, but var_export() emits a
warning.

$exception = NotCallableException::fromInvalidCallable($a);

$this->assertStringContainsString('is not a callable', $exception->getMessage());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not assert on the entire message? (that we we know what the exception message will be, here I'm not sure what it will be)


$exception = NotCallableException::fromInvalidCallable($a, true);

$this->assertStringContainsString('is neither a callable nor a valid container entry', $exception->getMessage());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same thing here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants