Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve PHP-DI/PHP-DI#616 #1

Merged
merged 4 commits into from
Aug 25, 2018

Conversation

mnapoli
Copy link

@mnapoli mnapoli commented Aug 25, 2018

This pull request adds suggested improvements to PHP-DI#616

I'll detail inline.

}

$this->setClassName($className);
}
Copy link
Author

Choose a reason for hiding this comment

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

I've moved the logic of replacing wildcards into this class, that allows for unit tests and a simpler code in DefinitionArray. This is not directly related to your bugfix but it improves the code a bit I think.

$this->replaceWildcards($definition->getClassName(), $matches)
);
$definition = $this->normalizer->normalizeRootDefinition($definition, $name);
}
Copy link
Author

Choose a reason for hiding this comment

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

I've reworked this code so that $this->normalizer->normalizeRootDefinition($definition, $name) isn't called twice. This is now the normalizer that takes care of replacing wildcards.

$this->assertInstanceOf(Implementation1::class, $object);

self::assertEntryIsNotCompiled($container, Interface1::class);
}
Copy link
Author

@mnapoli mnapoli Aug 25, 2018

Choose a reason for hiding this comment

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

I've added this test just to be sure it works ^^ (not related to your bug)

self::assertEntryIsNotCompiled($container, 'DI\Test\IntegrationTest\*\Interface*');
self::assertEntryIsNotCompiled($container, Interface1::class);
self::assertEntryIsNotCompiled($container, Interface2::class);
}
Copy link
Author

Choose a reason for hiding this comment

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

I've added a simpler version of your test: this test passes on the current master. I think this is better to have a simple test (easy to grasp) which covers the base of the feature + your test that is more advanced and covers the bug you were facing.

$definition = new ObjectDefinition('Foo\Bar\Baz');
$definition->replaceWildcards(['1', '2', '3']);
$this->assertEquals('Foo\Bar\Baz', $definition->getClassName());
}
Copy link
Author

Choose a reason for hiding this comment

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

With those unit tests I can sleep better now ;)

@jasonrm jasonrm merged commit 0017265 into ArtFireCom:wildcard-autowire Aug 25, 2018
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